<?php /** * Created by PhpStorm. * User: zhonglei * Date: 17/10/11 * Time: 15:05 */ namespace Common\Model; class CourseCompleteModel extends \Com\Model { // 构造方法 public function __construct() { parent::__construct('Complete', 'oa_course_'); } /** * 获取课程完成人数排行 * @author zhonglei * * @param array $conds 条件 * @param int $limit 数据总数,0为取所有数据 * * @return array */ public function listArticleRank($conds, $limit = 0) { $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 `article_id`, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `article_id` ORDER BY `total` DESC"; if ($limit > 0) { $sql .= " LIMIT {$limit}"; } return $this->_m->fetch_array($sql, $params); } /** * 根据UID获取人员已完成课程数 * @author liyifei * * @param array $uids 人员UID * @param array $articles 常规课程ID集合 * * @return array */ public function completeTotalByUids($uids, $articles = []) { $conds = [ 'uid' => $uids, 'article_id' => $articles ]; $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 `uid`, count(DISTINCT `article_id`) total FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid`"; return $this->_m->fetch_array($sql, $params); } /** * 获取用户已完成课程门数排行 * @author zhonglei * * @param array $conds 条件 * @param int $limit 数据总数,0为取所有数据 * * @return array */ public function listUserRank($conds, $limit = 0) { $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 *, COUNT(*) `total` FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `uid` ORDER BY `total` DESC"; if ($limit > 0) { $sql .= " LIMIT {$limit}"; } return $this->_m->fetch_array($sql, $params); } /** * 根据人员ID、课程ID数组,获取该人员课程完成情况 * * @param array $datas 人员ID、课程ID数组 * + string $datas[]['uid'] * + string $datas[]['article_id'] * * @return array */ public function listUserComplete($datas) { $domain = QY_DOMAIN; $status = $this->get_st_delete(); $where = "`{$this->prefield}domain`='{$domain}' AND `{$this->prefield}status`<{$status} AND"; foreach ($datas as $data) { $where .= " (`article_id` = {$data['article_id']} AND `uid` = '{$data['uid']}') OR"; } $where = substr($where, 0, -3); $sql = "SELECT `article_id`, `uid`, `created` AS `complete_time` FROM __TABLE__ WHERE {$where}"; return $this->_m->fetch_array($sql); } }