StudyTimeModel.class.php 2.92 KB
<?php
/**
 * Created by PhpStorm.
 * User: liyifei2012it
 * Date: 17/10/9
 * Time: 16:43
 */

namespace Common\Model;

class StudyTimeModel extends AbstractModel
{

    // 构造方法
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 获取已参与学习的用户ID数组(去重)
     * @author zhonglei
     * @param array $conds 条件
     * @return array
     */
    public function listDistinctUidByConds($conds)
    {
        $wheres = [];
        $params = [];

        if (is_array($conds) && !empty($conds)) {

            $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 DISTINCT(`uid`) FROM __TABLE__ WHERE {$wheres_sql}";

        $list = $this->_m->fetch_array($sql, $params);
        return array_column($list, 'uid');
    }

    /**
     * 获取累计学习时长(单位:秒)
     *
     * @param array $conditions 条件
     *
     * @return array
     */
    public function getTotalStudyTime($conditions)
    {

        $wheres = [];
        $params = [];

        if (is_array($conditions) && !empty($conditions)) {

            $this->_parse_where($wheres, $params, $conditions);
        }

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

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

        $wheres_sql = implode(' AND ', $wheres);
        $sql = "SELECT SUM(`study_time`) `total` FROM __TABLE__ WHERE {$wheres_sql}";

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

    /**
     * 获取学员课程学习时长数据
     * @param int $article_id 课程id
     * @param int $customtask_id 任务id
     * @param int $plan_id 培训计划id
     * @param int $ed_id 培训id
     * @param int $map_id 学习地图id
     * @param int $path_id 学习路径id
     *
     * @return array
     */
    public function users_study_time($article_id = 0, $customtask_id = 0, $plan_id = 0, $ed_id = 0, $map_id = 0, $path_id = 0)
    {
        // 查询sql语句
        $sql = "SELECT `uid`,SUM(`study_time`) AS `study_time` FROM `oa_course_study_time` WHERE `article_id`=? AND `customtask_id`=? AND `plan_id`=? AND `ed_id`=? AND `map_id`=? AND `path_id`=? AND `domain`=? AND `status`<? AND `source_id`!=? GROUP BY `uid`";

        $status = $this->get_st_delete();

        // 参数
        $params = [
            $article_id,
            $customtask_id,
            $plan_id,
            $ed_id,
            $map_id,
            $path_id,
            QY_DOMAIN,
            $status,
            0
        ];

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