1], [['limit'], 'default', 'value' => 20], ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $query = Coupon::find() ->where([ 'is_delete' => 0 ]) ->andFilterWhere([ 'OR', ['like','title',$this->keywords], ])->andFilterWhere([ 'type' => $this->type ]); $count = $query->count(); $pagination = new Pagination(['totalCount' => $count, 'pageSize' => $this->limit]); $list = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['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['business'] = date('Y-m-d',$item['start_time']).' - '.date('Y-m-d',$item['end_time']); $item['get_business'] = date('Y-m-d',$item['get_start_time']).' - '.date('Y-m-d',$item['get_end_time']); if($item['num'] < 0){ $item['num'] = '不限量'; } $item['store_name_list'] = ''; if(!empty($item['store_ids'])){ $store_ids = explode(',',$item['store_ids']); $store_ids = array_filter($store_ids); $store = Store::find()->where(['id' => $store_ids,'is_delete' => 0])->select('name')->column(); if(!empty($store)){ $item['store_name_list'] = implode(',',$store); } }else{ $item['store_name_list'] = '全部'; } $list[$index] = $item; } $data = []; $data['code'] = 0; $data['msg'] = 'ok'; $data['data'] = $list; $data['count'] = $count; return $data; } }