From cd778c7b404830e016017e98021d0f2b5b2fe08b Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 14:44:53 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=BF=90=E8=B4=B9=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E6=A3=80=E7=B4=A2=E9=A1=B5=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/models/searchs/ExpressAreaSearch.php | 160 ++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 backend/modules/shop/models/searchs/ExpressAreaSearch.php diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php new file mode 100644 index 0000000..7604eef --- /dev/null +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -0,0 +1,160 @@ + 'blobt\grid\CheckboxColumn', + 'width' => '2%', + 'align' => 'center' + ], + 'id', + ['attribute' => 'city', + 'value' => function ($model) { + $array = explode(',', $model->city); + $cities = []; + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { + $cities[] = $city->name; + } + return implode(' // ', $cities); + }, + ], + 'express_template', + //'extra_price', + //'basic_price', + //'basic_count', + //'extra_count', + //'updated_at', + //'created_at', + [ + 'class' => 'iron\grid\ActionColumn', + 'align' => 'center', + ], + ]; + } + /** + * @param $params + * @return ActiveDataProvider + * 不分页的所有数据 + */ + public function allData($params) + { + $query = ExpressArea::find(); + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => false, + 'sort' => false + ]); + $this->load($params); + return $this->filter($query, $dataProvider); + } + + /** + * Creates data provider instance with search query applied + * + * @param array $params + * + * @return ActiveDataProvider + */ + public function search($params, $expressTemplateId) + { + $query = ExpressArea::find()->where(['express_template' => $expressTemplateId]); + + // add conditions that should always apply here + + $dataProvider = new ActiveDataProvider([ + 'query' => $query, + 'pagination' => [ + 'pageSizeLimit' => [1, 200] + ], + 'sort' => [ + 'defaultOrder' => [ + 'id' => SORT_DESC, + ] + ], + ]); + + $this->load($params); + return $this->filter($query, $dataProvider); + } + /** + * @param $query + * @param $dataProvider + * @return ActiveDataProvider + * 条件筛选 + */ + private function filter($query, $dataProvider){ + if (!$this->validate()) { + // uncomment the following line if you do not want to return any records when validation fails + // $query->where('0=1'); + return $dataProvider; + } + + // grid filtering conditions + $query->andFilterWhere([ + 'id' => $this->id, + 'express_template' => $this->express_template, + 'extra_price' => $this->extra_price, + 'basic_price' => $this->basic_price, + 'basic_count' => $this->basic_count, + 'extra_count' => $this->extra_count, + 'updated_at' => $this->updated_at, + 'created_at' => $this->created_at, + ]); + + $query->andFilterWhere(['like', 'province', $this->province]) + ->andFilterWhere(['like', 'city', $this->city]) + ->andFilterWhere(['like', 'area', $this->area]); + if ($this->created_at_range) { + $arr = explode(' ~ ', $this->created_at_range); + $start = strtotime($arr[0]); + $end = strtotime($arr[1]) + 3600 * 24; + $query->andFilterWhere(['between', 'created_at', $start, $end]); + } + return $dataProvider; + } +}