1], [['limit'], 'default', 'value' => 20], [['cx_mch_id'], 'required'], [['notice_id'], 'required', 'on' => 'detail'], ]; } public function search($is_admin = 0) { if(!$this->validate()){ return $this->getModelError(); } if(empty($this->store_id) && !$is_admin){ $store = Store::findOne(['is_delete' => 0]); $this->store_id = $store == null ? 0 : $store->id; } $query = Notice::find()->alias('n') ->leftJoin(['rt' => RichText::tableName()],'rt.id=n.rich_text_id') ->where([ 'n.cx_mch_id' => $this->cx_mch_id, 'n.is_delete' => 0, ]) ->andFilterWhere([ 'OR', ['LIKE', 'rt.title', $this->keywords], ['LIKE', 'rt.author', $this->keywords], ['LIKE', 'rt.summary', $this->keywords], ]) ->andFilterWhere([ 'n.is_top' => $this->is_top, 'n.is_index' => $this->is_index, 'n.status' => $this->status, 'n.id' => $this->notice_id, 'n.store_id' => $this->store_id ]) ->select('rt.author,rt.title,rt.summary,rt.content,rt.cover_url,n.id,n.rich_text_id,n.sort,n.is_top,n.is_index,n.status,n.created_at,n.published_at,n.viewed_num,n.cover'); $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(['n.is_top' => SORT_DESC,'n.sort' => SORT_ASC, 'n.created_at' => SORT_DESC])->asArray()->all(); foreach ($list as $index => $item){ $item['created_at_cn'] = date('Y年m月d日 下午H:i',$item['created_at']); $item['published_at_cn'] = date('Y年m月d日 下午H:i',$item['published_at']); $item['status_cn'] = Notice::getStatus($item['status']); $item['cover'] = SiteHelper::getFullUrl($item['cover']); if($this->scenario == 'detail') $item['content'] = SiteHelper::repairContent($item['content']); $list[$index] = $item; } //是否已经全部加载 $end_flag = $this->page > $pagination->pageCount ? true : false; try { $storeMakeCover = SiteHelper::getCustomiseOptionByKey("storeMakeCover","hump"); $storeMakeCover = empty($storeMakeCover) ? '' : SiteHelper::getFullUrl($storeMakeCover); }catch (\Exception $e){ $storeMakeCover = ''; } 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, 'storeMakeCover' => $storeMakeCover, ]; } }