1], [['limit'], 'default', 'value' => 20], [['type', 'cx_mch_id'], 'required'] ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $query = Cat2::find() ->where([ 'cx_mch_id' => $this->cx_mch_id, 'type' => $this->type, 'is_delete' => 0, ]) ->andWhere([ 'OR', ['LIKE', 'name', $this->keywords], ['LIKE', 'desc', $this->keywords], ]) ->select('id,name,desc,img_url,parent_id,sort,created_at,status,is_hide,big_img_url,advert_url,advert_pic,advert_url_type,advert_open_params'); $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(['sort' => SORT_ASC, '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['status_cn'] = $item['status'] == 1 ? "已开启": "已关闭"; $item['is_hide_cn'] = $item['is_hide'] == 1 ? "已隐藏": "已显示"; $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 ]; } }