diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 4f6e9a0..7b23bb4 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -108,7 +108,7 @@ class ExpressTemplateController extends Controller $provinces = Province::find()->cache(0)->all(); foreach ($provinces as $k => $v) { $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) + $cities = City::find() ->where(['province_id' => $v->province_id]) ->all(); foreach ($cities as $city) { @@ -153,7 +153,7 @@ class ExpressTemplateController extends Controller $provinces = Province::find()->cache(0)->all(); foreach ($provinces as $k => $v) { $data[$k]['province'] = $v->name; - $cities = City::find()->cache(0) + $cities = City::find() ->where(['province_id' => $v->province_id]) ->all(); foreach ($cities as $city) { @@ -233,4 +233,79 @@ class ExpressTemplateController extends Controller 'expressTemplate' => $expressTemplate ]); } + + /** + * @return array|mixed|string|Response + * 运费区域模板区域创建方法 + */ + public function actionExpressAreaCreate() + { + $expressTemplateId = Yii::$app->request->get('expressTemplateId'); + $expressTemplateModel = ExpressTemplate::findOne($expressTemplateId); + $model = new ExpressArea(); + $model->basic_count = 1; + $model->basic_price = '0.00'; + $model->express_template = $expressTemplateModel->id; + + if (Yii::$app->request->isPost) { + $data = Yii::$app->request->post('ExpressArea'); + if (Yii::$app->request->isAjax) { + $model->load($data, ''); + Yii::$app->response->format = Response::FORMAT_JSON; + $data = ActiveForm::validate($model); + $data['status'] = 2; + return $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->basic_price *= 100; + $model->extra_price *= 100; + if ($expressTemplateModel->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { + $model->basic_count *= 10; + $model->extra_count *= 10; + } else { + $model->basic_count *= 1; + $model->extra_count *= 1; + } + $model->save(); + return $this->redirect('express-area-list?id='.$model->express_template); + } + $data = []; + $expressAreas = ExpressArea::find()->select(['city'])->where(['express_template' => $expressTemplateModel->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++; + } + } + if (empty($data)) { + Yii::$app->session->setFlash('error', '已无地区选择'); + return $this->redirect('express-area-list?id='.$expressTemplateModel->id); + } + return $this->render('express_area_create', [ + 'model' => $model, + 'data' => $data, + 'expressTemplateModel' => $expressTemplateModel + ]); + } } diff --git a/backend/modules/shop/views/express-template/express_area_create.php b/backend/modules/shop/views/express-template/express_area_create.php new file mode 100755 index 0000000..fb35a2e --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_create.php @@ -0,0 +1,50 @@ +title = '创建运费模板'; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->params['breadcrumbs'][] = $this->title; +Yii::$app->params['bsVersion'] = '4.x'; +?> +
必须至少选择一个城市为配送区域
+