CourseStudyRecordModel.class.php 1.16 KB
<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 17/10/12
 * Time: 18:43
 */

namespace Common\Model;

class CourseStudyRecordModel extends \Com\Model
{

    // 构造方法
    public function __construct()
    {
        parent::__construct('StudyRecord', 'oa_course_');
    }

    /**
     * 获取用户每个课程中第一次学习的时间
     * @author liyifei
     * @param string $uid
     * @param array $articleIds
     * @return array
     */
    public function listFirstStudy($uid, $articleIds)
    {
        $conds = [
            'uid' => $uid,
            'article_id' => $articleIds,
        ];

        $wheres = [];
        $params = [];
        $this->_parse_where($wheres, $params, $conds);

        // 企业标记
        $wheres[] = "`{$this->prefield}domain`=?";
        $params[] = QY_DOMAIN;

        // 状态条件
        $wheres[] = "`{$this->prefield}status`<?";
        $params[] = $this->get_st_delete();

        $wheres_sql = implode(' AND ', $wheres);
        $sql = "SELECT `article_id`, MIN(`created`) `created` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `article_id`";

        return $this->_m->fetch_array($sql, $params);
    }
}