Browse Source

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

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
ffe8739e77
  1. 2
      vendor/antgoods/goods/src/controllers/AttributeController.php
  2. 4
      vendor/antgoods/goods/src/controllers/CategoryController.php
  3. 43
      vendor/antgoods/goods/src/migrations/m191202_032835_update_column_sort_order_in_antgoods_category.php
  4. 16
      vendor/antgoods/goods/src/models/ars/Category.php

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

@ -69,7 +69,7 @@ class AttributeController extends Controller
$model->sort_order = 0; $model->sort_order = 0;
$model->cat_id = 0; $model->cat_id = 0;
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))) {

4
vendor/antgoods/goods/src/controllers/CategoryController.php

@ -82,7 +82,7 @@ class CategoryController extends Controller
$model->is_show = Category::IS_SHOW_DISPLAY; $model->is_show = Category::IS_SHOW_DISPLAY;
$model->sort_order = 0; $model->sort_order = 0;
if ($model->load(Yii::$app->request->post())) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//类目图片上传保存处理 //类目图片上传保存处理
$icon_image_id_str = $model->iconImageId; $icon_image_id_str = $model->iconImageId;
@ -115,7 +115,7 @@ class CategoryController extends Controller
//记录已保存的类目图片id,用于修改 //记录已保存的类目图片id,用于修改
$icon_image_old_id_arr = $model->icon; $icon_image_old_id_arr = $model->icon;
if ($model->load(Yii::$app->request->post())) {
if ($model->load(Yii::$app->request->post()) && $model->validate()) {
//类目图片上传保存处理 //类目图片上传保存处理
$icon_image_id_str = $model->iconImageId; $icon_image_id_str = $model->iconImageId;

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

@ -0,0 +1,43 @@
<?php
use yii\db\Migration;
/**
* Class m191202_032835_update_column_sort_order_in_antgoods_category
*/
class m191202_032835_update_column_sort_order_in_antgoods_category extends Migration
{
/**
* {@inheritdoc}
*/
public function safeUp()
{
$this->dropColumn('antgoods_category', 'sort_order');
$this->addColumn('antgoods_category', 'sort_order', $this->smallInteger(3)->defaultValue(0)->comment('排序'));
}
/**
* {@inheritdoc}
*/
public function safeDown()
{
$this->dropColumn('antgoods_category', 'sort_order');
$this->addColumn('antgoods_category', 'sort_order', $this->smallInteger(3)->unsigned()->defaultValue(0)->comment('排序'));
return true;
}
/*
// Use up()/down() to run migration code without a transaction.
public function up()
{
}
public function down()
{
echo "m191202_032835_update_column_sort_order_in_antgoods_category cannot be reverted.\n";
return false;
}
*/
}

16
vendor/antgoods/goods/src/models/ars/Category.php

@ -54,9 +54,25 @@ class Category extends \yii\db\ActiveRecord
[['pid', 'goods_count', 'sort_order', 'is_show', 'is_delete', 'icon'], 'integer'], [['pid', 'goods_count', 'sort_order', 'is_show', 'is_delete', 'icon'], 'integer'],
[['name'], 'string', 'max' => 60], [['name'], 'string', 'max' => 60],
[['iconImageId'], 'string'], [['iconImageId'], 'string'],
[['sort_order'], 'checkNegative'],
]; ];
} }
/**
* @param $attribute
* @param $params
* 验证是否为负数
*/
public function checkNegative($attribute, $params)
{
if ($this->$attribute < 0) {
$this->addError($attribute, "不得为负数");
}
if ($this->$attribute > 65535) {
$this->addError($attribute, "不得大于65535");
}
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */

Loading…
Cancel
Save