Browse Source

修改运费模板基础数量,续重数量和计算方式字段,并修改相关文件

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
00a1df8485
  1. 0
      backend/modules/shop/Module.php
  2. 4
      backend/modules/shop/controllers/ExpressTemplateController.php
  3. 30
      backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php
  4. 49
      backend/modules/shop/models/ars/ExpressTemplate.php
  5. 8
      backend/modules/shop/models/searchs/ExpressTemplateSearch.php
  6. 40
      backend/modules/shop/views/express-template/_form.php
  7. 8
      backend/modules/shop/views/express-template/view.php

0
backend/modules/shop/Module.php

4
backend/modules/shop/controllers/ExpressTemplateController.php

@ -71,8 +71,8 @@ class ExpressTemplateController extends Controller
public function actionCreate()
{
$model = new ExpressTemplate();
$model->calculation = ExpressTemplate::CALCULATION_NUMBER;
$model->basic_amount = 1;
$model->calculation_type = ExpressTemplate::CALCULATION_TYPE_NUMBER;
$model->basic_count = 1;
$model->basic_price = '0.00';
if (Yii::$app->request->isPost) {

30
backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php

@ -0,0 +1,30 @@
<?php
use yii\db\Migration;
/**
* Class m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template
*/
class m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template extends Migration
{
public function up()
{
$this->dropColumn('ats_express_template', 'basic_amount');
$this->dropColumn('ats_express_template', 'extra_amount');
$this->dropColumn('ats_express_template', 'calculation');
$this->addColumn('ats_express_template', 'basic_count', $this->integer(20)->defaultValue(null)->comment('基本数量'));
$this->addColumn('ats_express_template', 'extra_count', $this->integer(20)->defaultValue(null)->comment('续重数量'));
$this->addColumn('ats_express_template', 'calculation_type', $this->tinyInteger(2)->defaultValue(0)->comment('计算方式'));
}
public function down()
{
$this->dropColumn('ats_express_template', 'basic_amount');
$this->dropColumn('ats_express_template', 'extra_amount');
$this->dropColumn('ats_express_template', 'calculation');
$this->addColumn('ats_express_template', 'basic_amount', $this->integer(20)->defaultValue(null)->comment('基本数量'));
$this->addColumn('ats_express_template', 'extra_amount', $this->integer(20)->defaultValue(null)->comment('续重数量'));
$this->addColumn('ats_express_template', 'calculation', $this->tinyInteger(2)->defaultValue(0)->comment('计算方式'));
return true;
}
}

49
backend/modules/shop/models/ars/ExpressTemplate.php

@ -1,6 +1,6 @@
<?php
namespace backend\modules\shop\models\ars;
namespace backend\modules\shop\models\ars;
use Yii;
use yii\behaviors\TimestampBehavior;
@ -13,23 +13,23 @@ use yii\behaviors\TimestampBehavior;
* @property string $province 省份
* @property string $city 城市
* @property string $area 区域
* @property int $calculation 计算方式
* @property int $basic_price 基本运费
* @property int $basic_amount 基本数量
* @property int $extra_price 续重运费
* @property int $extra_amount 续重数量
* @property int $updated_at 更新时间
* @property int $created_at 创建时间
* @property int $basic_price 基本运费
* @property int $basic_count 基本数量
* @property int $extra_count 续重数量
* @property int $calculation_type 计算方式
*/
class ExpressTemplate extends \yii\db\ActiveRecord
{
//计算方式calculation
const CALCULATION_WEIGHT = 1; //按重量
const CALCULATION_NUMBER = 2; //按件数
//计算方式calculation_type
const CALCULATION_TYPE_WEIGHT = 1; //按重量
const CALCULATION_TYPE_NUMBER = 2; //按件数
public static $calculation = [
self::CALCULATION_WEIGHT => '按重量',
self::CALCULATION_NUMBER => '按件数'
public static $calculationType = [
self::CALCULATION_TYPE_WEIGHT => '按重量',
self::CALCULATION_TYPE_NUMBER => '按件数'
];
/**
* {@inheritdoc}
@ -45,26 +45,13 @@ class ExpressTemplate extends \yii\db\ActiveRecord
public function rules()
{
return [
[['name', 'calculation', 'basic_price', 'basic_amount'], 'required'],
[['province', 'city', 'area', 'basic_price', 'extra_price', 'basic_amount', 'extra_amount'], 'string'],
[['calculation'], 'integer'],
[['name'], 'required'],
[['province', 'city', 'area'], 'string'],
[['extra_price', 'basic_price', 'basic_count', 'extra_count', 'calculation_type'], 'integer'],
[['name'], 'string', 'max' => 255],
[['basic_amount', 'basic_price', 'extra_price', 'extra_amount'], 'checkNegative'],
];
}
/**
* @param $attribute
* @param $params
* 验证是否为负数
*/
public function checkNegative($attribute, $params)
{
if ($this->$attribute < 0) {
$this->addError($attribute, "不得为负数");
}
}
/**
* {@inheritdoc}
*/
@ -76,13 +63,13 @@ class ExpressTemplate extends \yii\db\ActiveRecord
'province' => '省份',
'city' => '城市',
'area' => '区域',
'calculation' => '计算方式',
'basic_price' => '基本运费',
'basic_amount' => '基本数量',
'extra_price' => '续重运费',
'extra_amount' => '续重数量',
'updated_at' => '更新时间',
'created_at' => '创建时间',
'basic_price' => '基本运费',
'basic_count' => '基本数量',
'extra_count' => '续重数量',
'calculation_type' => '计算方式',
];
}

8
backend/modules/shop/models/searchs/ExpressTemplateSearch.php

@ -26,7 +26,7 @@ class ExpressTemplateSearch extends ExpressTemplate
public function rules()
{
return [
[['id', 'calculation', 'basic_price', 'basic_amount', 'extra_price', 'extra_amount', 'updated_at', 'created_at'], 'integer'],
[['id', 'calculation_type', 'basic_price', 'basic_count', 'extra_price', 'extra_count', 'updated_at', 'created_at'], 'integer'],
[['name', 'province', 'city', 'area'], 'safe'],
['created_at_range','safe'],
];
@ -121,11 +121,11 @@ class ExpressTemplateSearch extends ExpressTemplate
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'calculation' => $this->calculation,
'calculation_type' => $this->calculation_type,
'basic_price' => $this->basic_price,
'basic_amount' => $this->basic_amount,
'basic_count' => $this->basic_count,
'extra_price' => $this->extra_price,
'extra_amount' => $this->extra_amount,
'extra_count' => $this->extra_count,
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
]);

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

@ -21,13 +21,13 @@ if ($status == 1) {
<?= $form->field($model, 'name')->textInput(['maxlength' => true]) ?>
<?= $form->field($model, 'calculation')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculation, 'type' => "radio"]) ?>
<?= $form->field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?>
<?= $form->field($model, 'basic_amount')->textInput() ?>
<?= $form->field($model, 'basic_count')->textInput() ?>
<?= $form->field($model, 'basic_price')->textInput() ?>
<?= $form->field($model, 'extra_amount')->textInput() ?>
<?= $form->field($model, 'extra_count')->textInput() ?>
<?= $form->field($model, 'extra_price')->textInput() ?>
@ -35,17 +35,17 @@ if ($status == 1) {
$js=<<<JS
const formList = [//切换时,class对应的标题
{
"field-expresstemplate-basic_amount":"基本重量(KG)",
"field-expresstemplate-basic_count":"基本重量(KG)",
"field-expresstemplate-basic_price":"基本运费(元)",
"field-expresstemplate-extra_amount":"续重重量(KG)",
"field-expresstemplate-extra_count":"续重重量(KG)",
"field-expresstemplate-extra_price":"续重运费(元)"
},
{
"field-expresstemplate-basic_amount":"基本数量(件)",
"field-expresstemplate-basic_count":"基本数量(件)",
"field-expresstemplate-basic_price":"基本运费(元)",
"field-expresstemplate-extra_amount":"续重数量(件)",
"field-expresstemplate-extra_count":"续重数量(件)",
"field-expresstemplate-extra_price":"续重运费(元)"
}
@ -62,26 +62,26 @@ function changeCalType(type){//当切换计算方式
$("." + index).children("label").html(value)
});
$("#expresstemplate-basic_amount").val(udfVal[type][0])//重置初始值
$("#expresstemplate-basic_count").val(udfVal[type][0])//重置初始值
$("#expresstemplate-basic_price").val(udfVal[type][1])
$("#expresstemplate-extra_amount").val('')
$("#expresstemplate-extra_count").val('')
$("#expresstemplate-extra_price").val('')
calType = type;
}
$(document).ready(function(){
$("#expresstemplate-basic_amount").blur(function(){
$("#expresstemplate-basic_count").blur(function(){
if (calType == 0) {
if($(this).val() < 0.1){
$(this).val(0.1)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 10) / 10);
var basiccount = $(this).val();
$(this).val(Math.floor(basiccount * 10) / 10);
} else{
if($(this).val() < 1){
$(this).val(1)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 1) / 1);
var basiccount = $(this).val();
$(this).val(Math.floor(basiccount * 1) / 1);
}
})
$("#expresstemplate-basic_price").blur(function(){
@ -91,19 +91,19 @@ $(document).ready(function(){
var basicPrice = $(this).val();
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
})
$("#expresstemplate-extra_amount").blur(function(){
$("#expresstemplate-extra_count").blur(function(){
if (calType == 0) {
if($(this).val() < 0){
$(this).val(0)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 10) / 10);
var basiccount = $(this).val();
$(this).val(Math.floor(basiccount * 10) / 10);
} else{
if($(this).val() < 0){
$(this).val(0)
}
var basicAmount = $(this).val();
$(this).val(Math.floor(basicAmount * 1) / 1);
var basiccount = $(this).val();
$(this).val(Math.floor(basiccount * 1) / 1);
}
})
$("#expresstemplate-extra_price").blur(function(){
@ -114,7 +114,7 @@ $(document).ready(function(){
$(this).val(basicPrice.toString().match(/^\d+(?:\.\d{0,2})?/));
})
$("input:radio[name='ExpressTemplate[calculation]']").on('ifChecked', function(event){
$("input:radio[name='ExpressTemplate[calculation_type]']").on('ifChecked', function(event){
changeCalType($(this).val()-1)
})
changeCalType(calType)

8
backend/modules/shop/views/express-template/view.php

@ -24,15 +24,15 @@ $this->params['breadcrumbs'][] = $this->title;
'id',
'name',
[
'attribute' => 'calculation',
'attribute' => 'calculation_type',
'value' => function ($model) {
return ExpressTemplate::$calculation[$model->calculation];
return ExpressTemplate::$calculationType[$model->calculation_type];
}
],
'basic_price',
'basic_amount',
'basic_count',
'extra_price',
'extra_amount',
'extra_count',
'updated_at:datetime',
'created_at:datetime',
['attribute' => 'city',

Loading…
Cancel
Save