From 7560af34f11efa2036d62bec29f9628ab9849067 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 17:03:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=84=E7=90=86=E5=9F=8E=E5=B8=82=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E6=98=BE=E7=A4=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 1 + .../shop/models/searchs/ExpressAreaSearch.php | 22 +++++++++++++++---- .../express-template/express_area_update.php | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 61e7773..488385f 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -359,6 +359,7 @@ class ExpressTemplateController extends Controller $j++; } } + return $this->render('express_area_update', [ 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel ]); diff --git a/backend/modules/shop/models/searchs/ExpressAreaSearch.php b/backend/modules/shop/models/searchs/ExpressAreaSearch.php index dea69ac..c9cb7a3 100644 --- a/backend/modules/shop/models/searchs/ExpressAreaSearch.php +++ b/backend/modules/shop/models/searchs/ExpressAreaSearch.php @@ -2,6 +2,8 @@ namespace backend\modules\shop\models\searchs; +use backend\modules\shop\models\ars\City; +use backend\modules\shop\models\ars\Province; use yii\base\Model; use yii\data\ActiveDataProvider; use yii\helpers\ArrayHelper; @@ -57,12 +59,24 @@ class ExpressAreaSearch extends ExpressArea 'id', ['attribute' => 'city', 'value' => function ($model) { - $array = explode(',', $model->city); + $expressAreas = ExpressArea::findOne($model->id); + $expressAresCityIdArr = explode(',', $expressAreas->city); $cities = []; - foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', $array])->all() as $city) { - $cities[] = $city->name; + $provinces = Province::find()->cache(0)->all(); + foreach ($provinces as $k => $v) { + $cityId = City::find() + ->select(['city_id']) + ->where(['province_id' => $v->province_id]) + ->column(); + if (empty(array_diff($cityId, $expressAresCityIdArr))) { + $cities[] = $v->name; + }else{ + foreach (\backend\modules\shop\models\ars\City::find()->andWhere(['in', 'city_id', array_diff($cityId, array_diff($cityId, $expressAresCityIdArr))])->all() as $city) { + $cities[] = $city->name; + } + } } - return implode(' // ', $cities); + return implode(' , ', $cities); }, ], [ diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php index 0019efb..60c0704 100755 --- a/backend/modules/shop/views/express-template/express_area_update.php +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -43,7 +43,7 @@ Yii::$app->params['bsVersion'] = '4.x';