Browse Source

完成运费模板增删改查逻辑

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
fd2c5c512d
  1. 15
      backend/modules/shop/controllers/ExpressTemplateController.php
  2. 3
      backend/modules/shop/models/ars/ExpressTemplate.php
  3. 26
      backend/modules/shop/views/express-template/_form.php
  4. 2
      backend/modules/shop/views/express-template/create.php
  5. 2
      backend/modules/shop/views/express-template/update.php

15
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) {

3
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']
];
}

26
backend/modules/shop/views/express-template/_form.php

@ -56,16 +56,36 @@ const udfVal = [//初始值
]
var calType = 1;//初始的计算方式0:计重 1:计件
function updateTypeChangeCalType(type){//当切换计算方式
$.each(formList[type],function(index,value){ //更改文字标题
$("." + index).children("label").html(value)
});
$("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值
$("#expresstemplate-basic_price").val(udfVal[type][1])
$("#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])
$("#expresstemplate-extra_count").val('')
$("#expresstemplate-extra_price").val('')
}
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)
})

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

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

Loading…
Cancel
Save