From ba138ebf1f76d6aa79d1f6ebddb2d3156de741a4 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Tue, 3 Dec 2019 20:19:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E5=8F=91=E8=BF=90=E8=B4=B9=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E6=A8=A1=E5=9D=97=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=9C=81?= =?UTF-8?q?=E5=B8=82=E5=8C=BA=E5=9F=9F=E9=80=89=E6=8B=A9js=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD=E9=97=AE=E9=A2=98=EF=BC=8C=E5=AE=89=E8=A3=85vue?= =?UTF-8?q?=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 61 +++++++++++++++++-- backend/views/express-template/create.php | 7 ++- backend/views/express-template/update.php | 42 +++++++++++-- backend/views/layouts/main.php | 7 +++ common/models/ars/ExpressTemplate.php | 4 +- composer.json | 4 +- 6 files changed, 110 insertions(+), 15 deletions(-) diff --git a/backend/controllers/ExpressTemplateController.php b/backend/controllers/ExpressTemplateController.php index 602385f..a03621e 100644 --- a/backend/controllers/ExpressTemplateController.php +++ b/backend/controllers/ExpressTemplateController.php @@ -2,12 +2,17 @@ namespace backend\controllers; +use common\models\ars\City; +use common\models\ars\Province; use Yii; use common\models\ars\ExpressTemplate; use common\models\searchs\ExpressTemplateSearch; +use yii\caching\Cache; use yii\web\Controller; use yii\web\NotFoundHttpException; use yii\filters\VerbFilter; +use yii\web\Response; +use yii\widgets\ActiveForm; /** * ExpressTemplateController implements the CRUD actions for ExpressTemplate model. @@ -67,12 +72,39 @@ class ExpressTemplateController extends Controller { $model = new ExpressTemplate(); - if ($model->load(Yii::$app->request->post()) && $model->save()) { + if (Yii::$app->request->isPost) { + $data = Yii::$app->request->post('ExpressTemplate'); + 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->save(); return $this->redirect('index'); } + $data = []; + $provinces = Province::find()->cache(0)->all(); + foreach ($provinces as $k => $v) { + $data[$k]['province'] = $v->name; + $cities = City::find()->cache(0) + ->where(['province_id' => $v->province_id]) + ->all(); + foreach ($cities as $city) { + $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } + } return $this->render('create', [ 'model' => $model, + 'data' => $data ]); } @@ -86,13 +118,30 @@ class ExpressTemplateController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - - if ($model->load(Yii::$app->request->post()) && $model->save()) { - return $this->redirect('index'); + $data = Yii::$app->request->post('ExpressTemplate'); + 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->render('view', ['model' => ExpressTemplate::findOne($model->id)]); + } + $data = []; + $provinces = Province::find()->cache(0)->all(); + foreach ($provinces as $k => $v) { + $data[$k]['province'] = $v->name; + $cities = City::find()->cache(0) + ->where(['province_id' => $v->province_id]) + ->all(); + foreach ($cities as $city) { + $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; + } } - return $this->render('update', [ - 'model' => $model, + 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city) ]); } diff --git a/backend/views/express-template/create.php b/backend/views/express-template/create.php index f939012..df1198e 100644 --- a/backend/views/express-template/create.php +++ b/backend/views/express-template/create.php @@ -7,7 +7,7 @@ use kartik\tabs\TabsX; /* @var $this yii\web\View */ /* @var $model common\models\ars\ExpressTemplate */ -$this->title = '创建 Express Template'; +$this->title = '创建运费模板'; $this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; Yii::$app->params['bsVersion'] = '4.x'; @@ -28,6 +28,11 @@ Yii::$app->params['bsVersion'] = '4.x'; 'form' => $form, ]), ], + [ + 'label' => ' 选择配送区域', + 'content' => $this->render('area', ['data' => $data, 'form' => $form, 'cities' => [] + ]), + ], ], 'position' => TabsX::POS_ABOVE, 'encodeLabels' => false diff --git a/backend/views/express-template/update.php b/backend/views/express-template/update.php index 20c70fd..3e5d1c8 100644 --- a/backend/views/express-template/update.php +++ b/backend/views/express-template/update.php @@ -1,19 +1,51 @@ title = '编辑 Express Template: ' . $model->name; +$this->title = '编辑运费模板: ' . $model->name; $this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; $this->params['breadcrumbs'][] = ['label' => $model->name, 'url' => ['view', 'id' => $model->id]]; $this->params['breadcrumbs'][] = 'Update '; +Yii::$app->params['bsVersion'] = '4.x'; ?>