diff --git a/vendor/antgoods/goods/src/migrations/sql/goods.sql b/vendor/antgoods/goods/src/migrations/sql/goods.sql index fe9d9e2..3944770 100755 --- a/vendor/antgoods/goods/src/migrations/sql/goods.sql +++ b/vendor/antgoods/goods/src/migrations/sql/goods.sql @@ -9,18 +9,18 @@ CREATE TABLE `antgoods_goods` ( `sn` varchar(60) DEFAULT NULL COMMENT '商品唯一货号', `code` varchar(50) DEFAULT NULL COMMENT '商品货码', `supplier_id` int(11) DEFAULT NULL COMMENT '供应商id', - `weight` mediumint(8) DEFAULT NULL COMMENT '重量', - `length` mediumint(8) DEFAULT NULL COMMENT '长度', - `width` mediumint(8) DEFAULT NULL COMMENT '宽度', - `height` mediumint(8) DEFAULT NULL COMMENT '高度', - `diameter` mediumint(8) DEFAULT NULL COMMENT '直径', + `weight` mediumint(8) DEFAULT NULL unique COMMENT '重量', + `length` mediumint(8) DEFAULT NULL unique COMMENT '长度', + `width` mediumint(8) DEFAULT NULL unique COMMENT '宽度', + `height` mediumint(8) DEFAULT NULL unique COMMENT '高度', + `diameter` mediumint(8) DEFAULT NULL unique COMMENT '直径', `unit` varchar(16) DEFAULT NULL COMMENT '单位', - `sold_count` int(10) DEFAULT NULL COMMENT '已售数量', + `sold_count` int(10) DEFAULT NULL unique COMMENT '已售数量', `limit_count` int(10) DEFAULT NULL COMMENT '限购数量', `stock` int(10) DEFAULT NULL COMMENT '库存', `stock_warn` int(10) DEFAULT NULL COMMENT '库存警告', - `market_price` int(20) DEFAULT NULL COMMENT '市场价', - `price` int(20) DEFAULT NULL COMMENT '销售价', + `market_price` int(20) DEFAULT NULL unique COMMENT '市场价', + `price` int(20) DEFAULT NULL unique COMMENT '销售价', `brief` varchar(255) DEFAULT NULL COMMENT '简介', `description` text COMMENT '详细介绍', `image` int(11) DEFAULT NULL COMMENT '图片id', diff --git a/vendor/antgoods/goods/src/models/ars/Goods.php b/vendor/antgoods/goods/src/models/ars/Goods.php index e94430c..71d074f 100644 --- a/vendor/antgoods/goods/src/models/ars/Goods.php +++ b/vendor/antgoods/goods/src/models/ars/Goods.php @@ -93,9 +93,22 @@ class Goods extends \yii\db\ActiveRecord [['code'], 'string', 'max' => 50], [['unit'], 'string', 'max' => 16], [['brief'], 'string', 'max' => 255], + [['weight', 'length', 'width', 'height', 'diameter', 'sold_count', 'market_price', 'price'], 'checkNegative'], ]; } + /** + * @param $attribute + * @param $params + * 验证是否为负数 + */ + public function checkNegative($attribute, $params) + { + if ($this->$attribute < 0) { + $this->addError($attribute, "不得为负数"); + } + } + /** * @param $attribute * @param $params