From 1547d81c67d023418023b13f8c00f3072643fdb2 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 6 Dec 2019 15:43:05 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9=E5=8C=BA?= =?UTF-8?q?=E5=9F=9F=E6=9B=B4=E6=96=B0=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 7b23bb4..61e7773 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -308,4 +308,59 @@ class ExpressTemplateController extends Controller 'expressTemplateModel' => $expressTemplateModel ]); } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域更新方法 + */ + public function actionExpressAreaUpdate($id) + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $model = ExpressArea::findOne($id); + $model->basic_price /= 100; + $model->extra_price /= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count /= 10; + $model->extra_count /= 10; + } + $data = Yii::$app->request->post('ExpressArea'); + if ($data) { + if (Yii::$app->request->post('area') == null) { + return $this->redirect(Yii::$app->request->referrer . '&status=1'); + } + $cityIds = array_keys(Yii::$app->request->post('area')); + $data['city'] = implode(',', $cityIds); + $model->load($data, ''); + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->id])->andWhere(['!=', 'id', $id])->all(); + $expressAresCityIdArr = []; + if ($expressAreas) { + foreach ($expressAreas as $expressAreaCity) { + $cityIdArr = explode(',', $expressAreaCity->city); + $expressAresCityIdArr = array_unique(array_merge($cityIdArr, $expressAresCityIdArr)); + } + } + $provinces = Province::find()->cache(0)->all(); + $j = 0; + foreach ($provinces as $k => $v) { + $cities = City::find() + ->where(['province_id' => $v->province_id]) + ->andWhere(['not in', 'city_id', $expressAresCityIdArr]) + ->all(); + if ($cities) { + $data[$j]['province'] = $v->name; + foreach ($cities as $city) { + $data[$j]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + $j++; + } + } + return $this->render('express_area_update', [ + 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city), 'expressTemplateModel' => $expressTemplateModel + ]); + } }