ArticleModel.class.php 1.37 KB
<?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']);
    }
}