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'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('_form', [ + 'model' => $model, + 'form' => $form, + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
+
diff --git a/backend/modules/shop/views/express-template/express_area_form.php b/backend/modules/shop/views/express-template/express_area_form.php new file mode 100755 index 0000000..940b46f --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_form.php @@ -0,0 +1,145 @@ + + +request->get('status'); +if ($status == 1) { + ?> + + + +field($model, 'name')->textInput(['maxlength' => true]) ?> + +field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> + +field($model, 'basic_count')->textInput() ?> + +field($model, 'basic_price')->textInput() ?> + +field($model, 'extra_count')->textInput() ?> + +field($model, 'extra_price')->textInput() ?> + +registerJs($js) + +?> \ No newline at end of file diff --git a/backend/modules/shop/views/express-template/express_area_update.php b/backend/modules/shop/views/express-template/express_area_update.php new file mode 100755 index 0000000..13c0193 --- /dev/null +++ b/backend/modules/shop/views/express-template/express_area_update.php @@ -0,0 +1,51 @@ +title = '编辑运费模板: ' . $model->name; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; +$this->params['breadcrumbs'][] = 'Update '; +Yii::$app->params['bsVersion'] = '4.x'; +?> +
+
+ + ['class' => 'container-fluid']]); + + echo TabsX::widget([ + 'bordered' => true, + 'items' => [ + [ + 'label' => ' 基本信息', + 'content' => $this->render('_form', [ + 'model' => $model, + 'form' => $form, + ]), + ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => $cities + ]), + ], + ], + 'position' => TabsX::POS_ABOVE, + 'encodeLabels' => false + ]); + ?> + +
+ 'btn btn-success']) ?> + 'btn btn-info']) ?> +
+ + + +
+