From b59b490fd0a2c304921e4c282cdae763b8d9411f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Mon, 2 Dec 2019 16:19:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=A4=84=E7=90=86=E5=95=86?= =?UTF-8?q?=E5=93=81=E8=A1=A8=E9=87=8D=E9=87=8F=EF=BC=8C=E9=95=BF=E5=BA=A6?= =?UTF-8?q?=EF=BC=8C=E5=AE=BD=E5=BA=A6=EF=BC=8C=E9=AB=98=E5=BA=A6=EF=BC=8C?= =?UTF-8?q?=E7=9B=B4=E5=BE=84=EF=BC=8C=E5=B7=B2=E5=94=AE=E6=95=B0=E9=87=8F?= =?UTF-8?q?=EF=BC=8C=E5=B8=82=E5=9C=BA=E4=BB=B7=EF=BC=8C=E9=94=80=E5=94=AE?= =?UTF-8?q?=E4=BB=B7=E5=AD=97=E6=AE=B5=E9=9D=9E=E8=B4=9F=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../antgoods/goods/src/migrations/sql/goods.sql | 16 ++++++++-------- vendor/antgoods/goods/src/models/ars/Goods.php | 13 +++++++++++++ 2 files changed, 21 insertions(+), 8 deletions(-) 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