1], [['limit'], 'default', 'value' => 20], [['cx_mch_id'], 'required'], [['page_id'], 'required', 'on' => 'detail'], ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $query = Page::find()->alias('p') ->leftJoin(['rt' => RichText::tableName()],'rt.id=p.rich_text_id') ->where([ 'p.cx_mch_id' => $this->cx_mch_id, 'p.is_delete' => 0, ]) ->andFilterWhere([ 'OR', ['LIKE', 'rt.title', $this->keywords], ['LIKE', 'rt.author', $this->keywords], ['LIKE', 'rt.summary', $this->keywords], ]) ->andFilterWhere([ 'p.is_top' => $this->is_top, 'p.status' => $this->status, 'p.id' => $this->page_id, 'p.url_alias' => $this->url_alias, ]) ->select('rt.author,rt.title,rt.summary,rt.content,rt.cover_url,p.id,p.rich_text_id,p.sort,p.is_top,p.status,p.created_at,p.published_at,p.viewed_num,p.allow_read'); $count_query = clone $query; $count = $count_query->count(); $pagination = new Pagination(['pageSize' => $this->limit, 'totalCount' => $count, 'page' => $this->page - 1]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['p.sort' => SORT_ASC, 'p.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['created_at_cn'] = date('Y-m-d H:i:s',$item['created_at']); $item['published_at_cn'] = date('Y-m-d H:i:s',$item['published_at']); $item['status_cn'] = Page::getStatus($item['status']); $item['allow_read_cn'] = $item['allow_read'] == 1 ? '开放阅读' : '密码访问'; if($this->scenario == 'detail') $item['content'] = SiteHelper::repairContent($item['content']); $list[$index] = $item; } //是否已经全部加载 $end_flag = $this->page > $pagination->pageCount ? true : false; return [ 'code' => 0, 'msg' => 'ok', 'data' => $list, 'count' => $count, 'page_size' => $this->limit, 'page_count' => $pagination->pageCount, 'page_no' => $this->page, 'end_flag' => $end_flag ]; } }