ArticleModel.class.php
1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
/**
* Created by PhpStorm.
* User: tangxingguo
* Date: 2017/4/12
* Time: 10:33
*/
namespace Common\Model;
class ArticleModel extends AbstractModel
{
// 构造方法
public function __construct()
{
parent::__construct();
}
/**
* 处理条件语句及其值
* @author liyifei
* @param array $conds 条件
* @return array
*/
public function buildSql($conds)
{
// 条件
$where = '`domain` = ? AND `status` < ?';
// 条件的值
$params = [
QY_DOMAIN,
$this->get_st_delete(),
];
// 组合搜索条件及值
if (isset($conds['teacher_id'])) {
$teacher_ids = implode("','", $conds['teacher_id']);
$where .= " AND `teacher_id` in ('{$teacher_ids}')";
}
return [
'where' => $where,
'params' => $params,
];
}
/**
* 根据讲师ID获取关联的课程数
* @ahthor liyifei
* @param array $teacher_ids 讲师ID
* @return array
*/
public function getTotalByTeacherIds($teacher_ids)
{
$data = $this->buildSql(['teacher_id' => $teacher_ids]);
$sql = "SELECT COUNT(*) AS total, `teacher_id` FROM __TABLE__ WHERE {$data['where']} GROUP BY `teacher_id`";
return $this->_m->fetch_array($sql, $data['params']);
}
}