diff --git a/vendor/antgoods/goods/src/models/ars/Brand.php b/vendor/antgoods/goods/src/models/ars/Brand.php index f3e49b5..e577b1d 100644 --- a/vendor/antgoods/goods/src/models/ars/Brand.php +++ b/vendor/antgoods/goods/src/models/ars/Brand.php @@ -77,6 +77,6 @@ class Brand extends \yii\db\ActiveRecord public static function modelColumn() { - return $column = Brand::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); } } diff --git a/vendor/antgoods/goods/src/models/ars/Category.php b/vendor/antgoods/goods/src/models/ars/Category.php index 7d4fa46..a64511a 100644 --- a/vendor/antgoods/goods/src/models/ars/Category.php +++ b/vendor/antgoods/goods/src/models/ars/Category.php @@ -97,8 +97,12 @@ class Category extends \yii\db\ActiveRecord ]; } + /** + * @return array + * 数据键值对 + */ public static function modelColumn() { - return $column = Category::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); } } diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index 2434e83..0a102b9 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -47,6 +47,13 @@ class Goods extends \yii\db\ActiveRecord //是否删除is_delete const IS_DELETE_NO = 0;//未删除 const IS_DELETE_YES = 1;//已删除 + //该商品是否开放销售is_sale + const IS_SALE_NO = 0;//否 + const IS_SALE_YES = 1;//是 + public static $isSale = [ + self::IS_SALE_NO => '否', + self::IS_SALE_YES => '是' + ]; /** * {@inheritdoc} */ @@ -63,6 +70,7 @@ class Goods extends \yii\db\ActiveRecord return [ [['pid', 'cat_id', 'brand_id', 'shop_cat_id', 'supplier_id', 'weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'limit_count', 'stock', 'stock_warn', 'market_price', 'price', 'image', 'model_id', 'is_sale', 'sort_order', 'bouns_points', 'experience_points', 'is_delete', 'express_template'], 'integer'], [['cat_id', 'brand_id', 'shop_cat_id', 'name', 'sn'], 'required'], + [['sn'], 'checkExist'], [['description'], 'string'], [['name'], 'string', 'max' => 120], [['sn'], 'string', 'max' => 60], @@ -72,6 +80,25 @@ class Goods extends \yii\db\ActiveRecord ]; } + /** + * @param $attribute + * @param $params + * 验证商品编号唯一 + */ + public function checkExist($attribute, $params) + { + $goods = self::find()->where([$attribute => $this->$attribute, 'is_delete' => 0])->one(); + if ($this->isNewRecord) { + if ($goods) { + $this->addError($attribute, "该商品编号已经存在"); + } + } else { + if ($goods && $goods->id != $this->id) { + $this->addError($attribute, "该商品编号已经存在"); + } + } + } + /** * {@inheritdoc} */ @@ -103,7 +130,7 @@ class Goods extends \yii\db\ActiveRecord 'description' => '详细介绍', 'image' => '图片id', 'model_id' => '模型id', - 'is_sale' => '该商品是否开放销售,1为是,0为否', + 'is_sale' => '该商品是否开放销售', 'sort_order' => '排序', 'bouns_points' => '奖励积分', 'experience_points' => '经验值', @@ -135,4 +162,17 @@ class Goods extends \yii\db\ActiveRecord ], ]; } + + /** + * @param bool $insert + * @return bool + * 自动填入参数 + */ + public function beforeSave($insert) + { + if (!$this->sn) { + $this->sn = time() . rand(1111, 9999); + } + return parent::beforeSave($insert); // TODO: Change the autogenerated stub + } } diff --git a/vendor/antgoods/goods/src/models/ars/ShopCategory.php b/vendor/antgoods/goods/src/models/ars/ShopCategory.php index a848f51..92fa87e 100644 --- a/vendor/antgoods/goods/src/models/ars/ShopCategory.php +++ b/vendor/antgoods/goods/src/models/ars/ShopCategory.php @@ -105,4 +105,13 @@ class ShopCategory extends \yii\db\ActiveRecord ], ]; } + + /** + * @return array + * 数据键值对 + */ + public static function modelColumn() + { + return $column = self::find()->select(['name'])->where(['is_delete' => self::IS_DELETE_NO])->indexBy('id')->column(); + } } diff --git a/vendor/antgoods/goods/src/views/goods/_form.php b/vendor/antgoods/goods/src/views/goods/_form.php index a944d3e..4dba452 100644 --- a/vendor/antgoods/goods/src/views/goods/_form.php +++ b/vendor/antgoods/goods/src/views/goods/_form.php @@ -4,6 +4,7 @@ use yii\helpers\Html; use yii\widgets\ActiveForm; use antgoods\goods\models\ars\Category; use antgoods\goods\models\ars\Brand; +use antgoods\goods\models\ars\ShopCategory; /* @var $this yii\web\View */ /* @var $model antgoods\goods\models\ars\Goods */ @@ -18,7 +19,7 @@ use antgoods\goods\models\ars\Brand; field($model, 'brand_id')->dropDownList(Brand::modelColumn(), ['prompt' => '请选择']) ?> - field($model, 'shop_cat_id')->textInput() ?> + field($model, 'shop_cat_id')->dropDownList(ShopCategory::modelColumn(), ['prompt' => '请选择']) ?> field($model, 'name')->textInput(['maxlength' => true]) ?> @@ -60,7 +61,7 @@ use antgoods\goods\models\ars\Brand; field($model, 'model_id')->textInput() ?> - field($model, 'is_sale')->textInput() ?> + field($model, 'is_sale')->radioList($model::$isSale) ?> field($model, 'sort_order')->textInput() ?>