From f6dc5c426e3efdfb1d1e6104cf72ff3b0abea28f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Sat, 7 Dec 2019 10:03:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E8=B4=B9=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=88=9B=E5=BB=BA=E5=92=8C=E6=9B=B4=E6=96=B0=E6=96=B9?= =?UTF-8?q?=E6=B3=95=E5=9B=A0=E5=88=A0=E9=99=A4=E5=AD=97=E6=AE=B5=E5=AF=BC?= =?UTF-8?q?=E8=87=B4=E7=9A=84=E9=80=BB=E8=BE=91=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 74 ++----------------- 1 file changed, 6 insertions(+), 68 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 6f29c2b..2e56221 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -73,52 +73,13 @@ class ExpressTemplateController extends Controller public function actionCreate() { $model = new ExpressTemplate(); - $model->calculation_type = ExpressTemplate::CALCULATION_TYPE_NUMBER; - $model->basic_count = 1; - $model->basic_price = '0.00'; - 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->basic_price *= 100; - $model->extra_price *= 100; - if ($model->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(); + if ($model->load(Yii::$app->request->post()) && $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() - ->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 ]); } @@ -132,36 +93,13 @@ class ExpressTemplateController extends Controller public function actionUpdate($id) { $model = $this->findModel($id); - $model->basic_price /= 100; - $model->extra_price /= 100; - if ($model->calculation_type == ExpressTemplate::CALCULATION_TYPE_WEIGHT) { - $model->basic_count /= 10; - $model->extra_count /= 10; - } - $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() - ->where(['province_id' => $v->province_id]) - ->all(); - foreach ($cities as $city) { - $data[$k]['city'][] = ['id' => $city->city_id, 'name' => $city->name]; - } + + if ($model->load(Yii::$app->request->post()) && $model->save()) { + return $this->redirect('index'); } + return $this->render('update', [ - 'model' => $model, 'data' => $data, 'cities' => explode(',', $model->city) + 'model' => $model, ]); }