From 00a1df84855f1fc5cec4fbf28b7f1c86186ac033 Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Thu, 5 Dec 2019 14:40:42 +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=9F=BA=E7=A1=80=E6=95=B0=E9=87=8F=EF=BC=8C=E7=BB=AD?= =?UTF-8?q?=E9=87=8D=E6=95=B0=E9=87=8F=E5=92=8C=E8=AE=A1=E7=AE=97=E6=96=B9?= =?UTF-8?q?=E5=BC=8F=E5=AD=97=E6=AE=B5=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/modules/shop/Module.php | 0 .../controllers/ExpressTemplateController.php | 4 +- ...culation_in_table_ats_express_template.php | 30 ++++++++++++ .../shop/models/ars/ExpressTemplate.php | 49 +++++++------------ .../models/searchs/ExpressTemplateSearch.php | 8 +-- .../shop/views/express-template/_form.php | 40 +++++++-------- .../shop/views/express-template/view.php | 8 +-- 7 files changed, 78 insertions(+), 61 deletions(-) mode change 100644 => 100755 backend/modules/shop/Module.php create mode 100755 backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php mode change 100755 => 100644 backend/modules/shop/models/ars/ExpressTemplate.php diff --git a/backend/modules/shop/Module.php b/backend/modules/shop/Module.php old mode 100644 new mode 100755 diff --git a/backend/modules/shop/controllers/ExpressTemplateController.php b/backend/modules/shop/controllers/ExpressTemplateController.php index 2ff09b1..8984993 100755 --- a/backend/modules/shop/controllers/ExpressTemplateController.php +++ b/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) { diff --git a/backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php b/backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php new file mode 100755 index 0000000..6d8a75e --- /dev/null +++ b/backend/modules/shop/migrations/m191205_062533_update_columns_basic_amount_extra_amount_calculation_in_table_ats_express_template.php @@ -0,0 +1,30 @@ +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; + } +} diff --git a/backend/modules/shop/models/ars/ExpressTemplate.php b/backend/modules/shop/models/ars/ExpressTemplate.php old mode 100755 new mode 100644 index 4774c6e..ba1f02a --- a/backend/modules/shop/models/ars/ExpressTemplate.php +++ b/backend/modules/shop/models/ars/ExpressTemplate.php @@ -1,6 +1,6 @@ '按重量', - 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' => '计算方式', ]; } diff --git a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php b/backend/modules/shop/models/searchs/ExpressTemplateSearch.php index 4cb0bff..8cee01c 100755 --- a/backend/modules/shop/models/searchs/ExpressTemplateSearch.php +++ b/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, ]); diff --git a/backend/modules/shop/views/express-template/_form.php b/backend/modules/shop/views/express-template/_form.php index 1dfe48e..8f21860 100755 --- a/backend/modules/shop/views/express-template/_form.php +++ b/backend/modules/shop/views/express-template/_form.php @@ -21,13 +21,13 @@ if ($status == 1) { field($model, 'name')->textInput(['maxlength' => true]) ?> -field($model, 'calculation')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculation, 'type' => "radio"]) ?> +field($model, 'calculation_type')->widget(Icheck::className(), ["items" => ExpressTemplate::$calculationType, 'type' => "radio"]) ?> -field($model, 'basic_amount')->textInput() ?> +field($model, 'basic_count')->textInput() ?> field($model, 'basic_price')->textInput() ?> -field($model, 'extra_amount')->textInput() ?> +field($model, 'extra_count')->textInput() ?> field($model, 'extra_price')->textInput() ?> @@ -35,17 +35,17 @@ if ($status == 1) { $js=<<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',