<?php /** * Created by PhpStorm. * User: zhonglei * Date: 17/10/11 * Time: 16:58 */ namespace Common\Model; class ClickModel extends AbstractModel { // 构造方法 public function __construct() { parent::__construct(); } /** * 获取应用数据点击量排行 * @author zhonglei * @param array $conds 条件 * @param int $limit 数据总数,0为取所有数据 * @return array */ public function listClickRank($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 `app_data_id` ORDER BY `total` DESC, `created` DESC"; if ($limit > 0) { $sql .= " LIMIT {$limit}"; } return $this->_m->fetch_array($sql, $params); } /** * 批量获取点击数 * @author liyifei * @param string $uid 人员UID * @param string $app 应用 * @param array $app_data_ids 评论对象ID * @return array */ public function listCourseStudyTotal($uid, $app, $app_data_ids) { $conds = [ 'uid' => $uid, 'app' => $app, 'app_data_id' => $app_data_ids, ]; $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 app_data_id, count(*) total FROM __TABLE__ WHERE {$wheres_sql} GROUP BY `app_data_id` ORDER BY `total` DESC"; return $this->_m->fetch_array($sql, $params); } }