Browse Source

修改商品属性表排序字段修改委非负数,模型中增加相应判断

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
d837ac5797
  1. 2
      vendor/antgoods/goods/src/controllers/AttributeController.php
  2. 43
      vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php
  3. 13
      vendor/antgoods/goods/src/models/ars/Attribute.php

2
vendor/antgoods/goods/src/controllers/AttributeController.php

@ -97,7 +97,7 @@ class AttributeController extends Controller
{ {
$model = $this->findModel($id); $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); $model->value = str_replace(',', ',', $model->value);
$array = explode(',', $model->value); $array = explode(',', $model->value);
if (count($array) != count(array_unique($array))) { if (count($array) != count(array_unique($array))) {

43
vendor/antgoods/goods/src/migrations/m191202_025843_update_column_sort_order_in_antgoods_attribute.php

@ -0,0 +1,43 @@
<?php
use yii\db\Migration;
/**
* Class m191202_025843_update_column_sort_order_in_antgoods_attribute
*/
class m191202_025843_update_column_sort_order_in_antgoods_attribute extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->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;
}
*/
}

13
vendor/antgoods/goods/src/models/ars/Attribute.php

@ -44,9 +44,22 @@ class Attribute extends \yii\db\ActiveRecord
[['value'], 'string'], [['value'], 'string'],
[['type', 'sort_order', 'is_delete', 'cat_id'], 'integer'], [['type', 'sort_order', 'is_delete', 'cat_id'], 'integer'],
[['name'], 'string', 'max' => 50], [['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} * {@inheritdoc}
*/ */

Loading…
Cancel
Save