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'; ?>
+
- render('_form', [ - 'model' => $model, - ]) ?> + ['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']) ?> +
+ + + +
diff --git a/backend/views/layouts/main.php b/backend/views/layouts/main.php index b6b8add..b938779 100755 --- a/backend/views/layouts/main.php +++ b/backend/views/layouts/main.php @@ -19,6 +19,13 @@ AppAsset::register($this); registerCsrfMetaTags() ?> <?= Html::encode($this->title) ?> + + + + + + + head() ?> diff --git a/common/models/ars/ExpressTemplate.php b/common/models/ars/ExpressTemplate.php index d21f833..4436401 100644 --- a/common/models/ars/ExpressTemplate.php +++ b/common/models/ars/ExpressTemplate.php @@ -17,7 +17,7 @@ use yii\behaviors\TimestampBehavior; * @property int $basic_price 基本运费 * @property int $basic_amount 基本数量 * @property int $extra_price 续重运费 - * @property int $extra_amount 续重运费 + * @property int $extra_amount 续重数量 * @property int $updated_at 更新时间 * @property int $created_at 创建时间 */ @@ -67,7 +67,7 @@ class ExpressTemplate extends \yii\db\ActiveRecord 'basic_price' => '基本运费', 'basic_amount' => '基本数量', 'extra_price' => '续重运费', - 'extra_amount' => '续重运费', + 'extra_amount' => '续重数量', 'updated_at' => '更新时间', 'created_at' => '创建时间', ]; diff --git a/composer.json b/composer.json index c6ddee8..c79317a 100755 --- a/composer.json +++ b/composer.json @@ -18,7 +18,9 @@ "moonlandsoft/yii2-phpexcel": "*", "kartik-v/yii2-tabs-x": "^1.2@dev", "kartik-v/yii2-editable": "^1.7@dev", - "kartik-v/yii2-widget-depdrop": "dev-master" + "kartik-v/yii2-widget-depdrop": "dev-master", + "antkaz/yii2-vue": "dev-master", + "xj/yii2-babel": "dev-master" }, "repositories": { "asset_packagist": {