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';