['cid'] ]; } /** * @notes 自定查询条件 * @return array * @author 段誉 * @date 2022/10/25 16:53 */ public function queryWhere() { $where[] = ['is_show', '=', 1]; return $where; } /** * @notes 获取文章列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 段誉 * @date 2022/9/16 18:55 */ public function lists(): array { $lang = $this->params['lang']; $field = 'id,title,image,langs'; $result = Article::field($field) ->where($this->queryWhere()) ->where($this->searchWhere) ->order(['sort' => 'desc', 'id' => 'desc']) ->limit($this->limitOffset, $this->limitLength) ->select()->toArray(); foreach ($result as &$article) { //多语言替换 $data = UtilsService::get_langs_data($article['langs'],$lang); $data_title = ''; if(count($data) > 0){ $data_title = $data['title']; } $article['title'] = $data_title; unset($article['langs']); } return $result; } /** * @notes 获取文章数量 * @return int * @author 段誉 * @date 2022/9/16 18:55 */ public function count(): int { return Article::where($this->searchWhere) ->where($this->queryWhere()) ->count(); } }