/** * 阅读动态,根据班级、任务类型、阅读状态等筛选出需要的数据 * * @param array $whereArr * @param array $whereMap * @param int $limit * * @return \ST\Common\Models\User * @author Hunter.<*****@*****.**> */ public function getClassesReadBook($whereArr = [], $whereMap = [], $limit = 10) { //todo 使用统计表统计 $builder = $this->di->get('modelsManager')->createBuilder()->columns(['task.id as id', 'book.name as bookName', 'count(DISTINCT page.id) AS readCount', 'count(DISTINCT note.id) AS noteCount', 'avg(log.point) as pointAvg', 'task.start_time', 'task.end_time'])->from(['task' => 'ST\\Common\\Models\\Task'])->leftJoin('ST\\Common\\Models\\Page', 'page.read_task_id=task.id', 'page')->leftJoin('ST\\Common\\Models\\Note', 'note.read_task_id=task.id', 'note')->leftJoin('ST\\Common\\Models\\Book', 'book.id=task.book_id', 'book')->leftJoin('ST\\Common\\Models\\EvaTaskLog', 'log.read_task_id=task.id', 'log')->groupBy('task.id')->orderBy('task.start_time asc'); if ($whereArr) { $i = 0; foreach ($whereArr as $field => $where) { if ($i == 0) { $builder->where($where, $whereMap); } else { $builder->andWhere($where, $whereMap); } $i++; } } $result = BaseModel::getList($builder, $limit, '', '', 'my'); return $result; }
/** * 学生获取阅读任务 * * @param array $whereArr * @param array $whereMap * @param int $limit * * @return \ST\Common\Models\Task * @author Hunter.<*****@*****.**> */ public function getUserTaskList($whereArr = [], $whereMap = [], $limit = 16) { $builder = $this->di->get('modelsManager')->createBuilder()->columns(['task.*', 'page.last_page', 'page.last_page/book.count_page as _avg', 'book.count_page as book_count_page', 'page.is_finished', 'book.has_question', 'book.image as book_image', 'book.name as book_name', 'book.auth as book_auth', 'book.id as book_id', 'if(note.id,1,0) as note_id'])->from(['task' => 'ST\\Common\\Models\\Task'])->leftJoin('ST\\Common\\Models\\Page', 'page.read_task_id=task.id and page.uid="' . $this->thisController->user->id . '"', 'page')->leftJoin('ST\\Common\\Models\\Book', 'task.book_id=book.id', 'book')->leftJoin('ST\\Common\\Models\\Note', 'note.read_task_id=task.id', 'note')->orderBy('task.start_time asc'); if ($whereArr) { $i = 0; foreach ($whereArr as $field => $where) { if ($i == 0) { $builder->where($where, $whereMap); } else { $builder->andWhere($where, $whereMap); } $i++; } } if ($limit == 1) { return $builder->getQuery()->execute(); } return BaseModel::getList($builder, $limit); }
public function getIntegralShopList($whereArr = [], $whereMap = [], $limit = 16) { $page = $this->di->get('dispatcher')->getParam('page', 'int', 1); //组建查询缓存的key $keyStr = __NAMESPACE__ . __METHOD__; if ($whereMap) { $keyStr .= implode(',', $whereArr) . implode(',', $whereMap); } $keyStr .= $page . $limit; $key = md5($keyStr); $result = self::$cache->getCache($key); if ($result === null) { $builder = $this->di->get('modelsManager')->createBuilder()->from(['good' => 'ST\\Common\\Models\\Good'])->orderBy('good.sale desc,good.create_at desc'); if ($whereArr) { $i = 0; foreach ($whereArr as $field => $where) { if ($i == 0) { $builder->where($where, $whereMap); } else { $builder->andWhere($where, $whereMap); } $i++; } } $result = BaseModel::getList($builder, $limit); self::$cache->setCache($key, $result); } return $result; }
/** * 根据学校、年级等查询条件获取所有学生 * * @param array $whereArr * @param array $whereMap * @param int $limit * * @return bool|\ST\Common\Models\User * @author Hunter.<*****@*****.**> */ public function getStudentList($whereArr = [], $whereMap = [], $limit = 12) { $page = $this->di->get('dispatcher')->getParam('page', 'int', 1); //组建查询缓存的key $keyStr = __NAMESPACE__ . __METHOD__; if ($whereMap) { $keyStr .= implode(',', $whereArr) . implode(',', $whereMap); } $keyStr .= $page . $limit; $key = md5($keyStr); $result = self::$cache->getCache($key); if ($result === null) { $builder = $this->di->get('modelsManager')->createBuilder()->columns(['u.*', 'classes.name as class_name', 'classes.grade_id as class_grade_id', 'statistics.*', 's40.val as s_read_val', 's50.val as s_note_val', 's60.val as s_avgpoint_val'])->from(['u' => 'ST\\Common\\Models\\User'])->leftJoin('ST\\Common\\Models\\Classes', 'u.classes_id=classes.id', 'classes')->leftJoin('ST\\Common\\Models\\Statistics', 'u.id=statistics.uid and u.classes_id=statistics.classes_id and u.school_id=statistics.school_id', 'statistics')->leftJoin('ST\\Common\\Models\\Statistics', 's40.uid=statistics.uid and s40.ab_id=40', 's40')->leftJoin('ST\\Common\\Models\\Statistics', 's50.uid=statistics.uid and s50.ab_id=50', 's50')->leftJoin('ST\\Common\\Models\\Statistics', 's60.uid=statistics.uid and s60.ab_id=60', 's60')->groupBy('u.id')->orderBy('s60.val+0 desc'); if ($whereArr) { $i = 0; foreach ($whereArr as $field => $where) { if ($i == 0) { $builder->where($where, $whereMap); } else { $builder->andWhere($where, $whereMap); } $i++; } } $result = BaseModel::getList($builder, $limit, '', '', 'my'); self::$cache->setCache($key, $result); } return $result; }