From fd2c5c512d8b06db064a9d994cae624250ee3da6 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 15:04:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90=E8=BF=90=E8=B4=B9=E6=A8=A1?= =?UTF-8?q?=E6=9D=BF=E5=A2=9E=E5=88=A0=E6=94=B9=E6=9F=A5=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ExpressTemplateController.php | 15 ++++++++++ .../shop/models/ars/ExpressTemplate.php | 3 +- .../shop/views/express-template/_form.php | 28 ++++++++++++++++--- .../shop/views/express-template/create.php | 2 +- .../shop/views/express-template/update.php | 2 +- 5 files changed, 43 insertions(+), 7 deletions(-) diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 8984993..460be98 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/backend/modules/shop/controllers/ExpressTemplateController.php @@ -90,6 +90,15 @@ class ExpressTemplateController extends Controller $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(); return $this->redirect('index'); } @@ -121,6 +130,12 @@ 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) { diff --git a/backend/modules/shop/models/ars/ExpressTemplate.php b/backend/modules/shop/models/ars/ExpressTemplate.php index ba1f02a..ce4fd07 100644 --- a/backend/modules/shop/models/ars/ExpressTemplate.php +++ b/backend/modules/shop/models/ars/ExpressTemplate.php @@ -47,8 +47,9 @@ class ExpressTemplate extends \yii\db\ActiveRecord return [ [['name'], 'required'], [['province', 'city', 'area'], 'string'], - [['extra_price', 'basic_price', 'basic_count', 'extra_count', 'calculation_type'], 'integer'], + [['calculation_type'], 'integer'], [['name'], 'string', 'max' => 255], + [['extra_price', 'basic_price', 'basic_count', 'extra_count'], 'safe'] ]; } diff --git a/backend/modules/shop/views/express-template/_form.php b/backend/modules/shop/views/express-template/_form.php index 8f21860..940b46f 100755 --- a/backend/modules/shop/views/express-template/_form.php +++ b/backend/modules/shop/views/express-template/_form.php @@ -56,7 +56,7 @@ const udfVal = [//初始值 ] var calType = 1;//初始的计算方式0:计重 1:计件 -function changeCalType(type){//当切换计算方式 +function updateTypeChangeCalType(type){//当切换计算方式 $.each(formList[type],function(index,value){ //更改文字标题 $("." + index).children("label").html(value) @@ -64,8 +64,28 @@ function changeCalType(type){//当切换计算方式 $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 $("#expresstemplate-basic_price").val(udfVal[type][1]) - $("#expresstemplate-extra_count").val('') - $("#expresstemplate-extra_price").val('') + $("#expresstemplate-extra_count").val(0) + $("#expresstemplate-extra_price").val(udfVal[type][1]) + calType = type; +} +function changeCalType(type){//当切换计算方式 + + $.each(formList[type],function(index,value){ //更改文字标题 + $("." + index).children("label").html(value) + }); + + if(!$("#expresstemplate-basic_count").val()){ + $("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值 + } + if(!$("#expresstemplate-basic_price").val()){ + $("#expresstemplate-basic_price").val(udfVal[type][1]) + } + if(!$("#expresstemplate-extra_count").val()){ + $("#expresstemplate-extra_count").val(0) + } + if(!$("#expresstemplate-extra_price").val()){ + $("#expresstemplate-extra_price").val(udfVal[type][1]) + } calType = type; } $(document).ready(function(){ @@ -115,7 +135,7 @@ $(document).ready(function(){ }) $("input:radio[name='ExpressTemplate[calculation_type]']").on('ifChecked', function(event){ - changeCalType($(this).val()-1) + updateTypeChangeCalType($(this).val()-1) }) changeCalType(calType) }) diff --git a/backend/modules/shop/views/express-template/create.php b/backend/modules/shop/views/express-template/create.php index ad05035..fb35a2e 100755 --- a/backend/modules/shop/views/express-template/create.php +++ b/backend/modules/shop/views/express-template/create.php @@ -8,7 +8,7 @@ use kartik\tabs\TabsX; /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ $this->title = '创建运费模板'; -$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; +$this->params['breadcrumbs'][] = ['label' => '运费模板', 'url' => ['index']]; $this->params['breadcrumbs'][] = $this->title; Yii::$app->params['bsVersion'] = '4.x'; ?> diff --git a/backend/modules/shop/views/express-template/update.php b/backend/modules/shop/views/express-template/update.php index 22b28bc..13c0193 100755 --- a/backend/modules/shop/views/express-template/update.php +++ b/backend/modules/shop/views/express-template/update.php @@ -8,7 +8,7 @@ use kartik\tabs\TabsX; /* @var $model backend\modules\shop\models\ars\ExpressTemplate */ $this->title = '编辑运费模板: ' . $model->name; -$this->params['breadcrumbs'][] = ['label' => 'Express Templates', 'url' => ['index']]; +$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';