From d837ac5797b3df643a0c22ae0b7f79d449befb0c Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Mon, 2 Dec 2019 11:24:31 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=95=86=E5=93=81=E5=B1=9E?= =?UTF-8?q?=E6=80=A7=E8=A1=A8=E6=8E=92=E5=BA=8F=E5=AD=97=E6=AE=B5=E4=BF=AE?= =?UTF-8?q?=E6=94=B9=E5=A7=94=E9=9D=9E=E8=B4=9F=E6=95=B0=EF=BC=8C=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=B8=AD=E5=A2=9E=E5=8A=A0=E7=9B=B8=E5=BA=94=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/controllers/AttributeController.php | 2 +- ...olumn_sort_order_in_antgoods_attribute.php | 43 +++++++++++++++++++ .../goods/src/models/ars/Attribute.php | 13 ++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php diff --git a/vendor/antgoods/goods/src/controllers/AttributeController.php b/vendor/antgoods/goods/src/controllers/AttributeController.php index 719fea2..ffa0873 100644 --- a/vendor/antgoods/goods/src/controllers/AttributeController.php +++ b/vendor/antgoods/goods/src/controllers/AttributeController.php @@ -97,7 +97,7 @@ class AttributeController extends Controller { $model = $this->findModel($id); - if ($model->load(Yii::$app->request->post())) { + if ($model->load(Yii::$app->request->post()) && $model->validate()) { $model->value = str_replace(',', ',', $model->value); $array = explode(',', $model->value); if (count($array) != count(array_unique($array))) { diff --git a/vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php b/vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php new file mode 100644 index 0000000..6757320 --- /dev/null +++ b/vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php @@ -0,0 +1,43 @@ +dropColumn('antgoods_attribute', 'sort_order'); + $this->addColumn('antgoods_attribute', 'sort_order', $this->smallInteger(3)->defaultValue(null)->unsigned()->comment('排序')); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropColumn('antgoods_attribute', 'sort_order'); + $this->addColumn('antgoods_attribute', 'sort_order', $this->smallInteger(3)->defaultValue(null)->comment('排序')); + return true; + } + + /* + // Use up()/down() to run migration code without a transaction. + public function up() + { + + } + + public function down() + { + echo "m191202_025843_update_column_sort_order_in_antgoods_attribute cannot be reverted.\n"; + + return false; + } + */ +} diff --git a/vendor/antgoods/goods/src/models/ars/Attribute.php b/vendor/antgoods/goods/src/models/ars/Attribute.php index 0d7bee3..496dbc7 100644 --- a/vendor/antgoods/goods/src/models/ars/Attribute.php +++ b/vendor/antgoods/goods/src/models/ars/Attribute.php @@ -44,9 +44,22 @@ class Attribute extends \yii\db\ActiveRecord [['value'], 'string'], [['type', 'sort_order', 'is_delete', 'cat_id'], 'integer'], [['name'], 'string', 'max' => 50], + [['sort_order'], 'checkNegative'], ]; } + /** + * @param $attribute + * @param $params + * 验证是否为负数 + */ + public function checkNegative($attribute, $params) + { + if ((integer)$this->$attribute < 0) { + $this->addError($attribute, "不得为负数"); + } + } + /** * {@inheritdoc} */