1], [['limit'], 'default', 'value' => 20], [['user_id', 'cx_mch_id'], 'required'] ]; } public function search() { if(!$this->validate()){ return $this->getModelError(); } $query = Address::find() ->where([ 'user_id' => $this->user_id, 'cx_mch_id' => $this->cx_mch_id, 'is_delete' => 0 ]) ->andFilterWhere([ 'OR', ['LIKE', 'name', $this->keywords], ['LIKE', 'mobile', $this->keywords], ['LIKE', 'detail', $this->keywords], ]) ->select('id,user_id,name,mobile,province_id,province,city_id,city,district_id,district,town_id,town,detail,lat,lng,is_default,tag,gender,formatted_addr,created_at'); $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(['is_default' => SORT_DESC, '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['tag_cn'] = Address::getTag($item['tag']); $item['gender_cn'] = Address::getGender($item['gender']); $item['selected'] = $item['is_default'] == 1 ? true : false; $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 ]; } }