From fae4b2ea04aedb89e5848f7eb4f6386714da7c1f Mon Sep 17 00:00:00 2001 From: linyaostalker <602604991@qq.com> Date: Fri, 29 Nov 2019 10:38:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E5=B1=9E=E6=80=A7=E8=A1=A8?= =?UTF-8?q?=E4=BF=AE=E6=94=B9goods=5Fid=E5=92=8Cattr=5Fid=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=EF=BC=8C=E5=AE=8C=E6=88=90sku=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84bug=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../goods/src/controllers/GoodsController.php | 1 + .../goods/src/logic/goods/GoodsManager.php | 6 +++-- ...d_attr_id_in_table_antgoods_goods_attr.php | 26 +++++++++++++++++++ .../goods/src/models/ars/GoodsAttr.php | 2 +- 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php diff --git a/vendor/antgoods/goods/src/controllers/GoodsController.php b/vendor/antgoods/goods/src/controllers/GoodsController.php index dc67b12..6ce0aa2 100644 --- a/vendor/antgoods/goods/src/controllers/GoodsController.php +++ b/vendor/antgoods/goods/src/controllers/GoodsController.php @@ -2,6 +2,7 @@ namespace antgoods\goods\controllers; +use antgoods\goods\models\ars\GoodsAttr; use antgoods\goods\models\ars\GoodsSku; use common\models\ars\TemFile; use MongoDB\Driver\Manager; diff --git a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php index ff7cd3b..dc04a89 100644 --- a/vendor/antgoods/goods/src/logic/goods/GoodsManager.php +++ b/vendor/antgoods/goods/src/logic/goods/GoodsManager.php @@ -285,7 +285,7 @@ class GoodsManager $data['id'] = $sku->id; $data['price'] = $sku->price; $data['stock'] = $sku->stock; - $data['weight'] = $sku->goods_weight; + $data['weight'] = $sku->weight; return $data; } @@ -350,6 +350,7 @@ class GoodsManager */ public static function AddOrUpdateData($sku, $type, $goodsId) { + $goodsModel = Goods::findOne($goodsId); if ($sku['id'] > 0) { $goodsSku = GoodsSku::findOne($sku['id']); $attrId = array_filter(explode(',', $goodsSku->goods_attr)); @@ -358,7 +359,7 @@ class GoodsManager $goodsSku = new GoodsSku(); $attr = new GoodsAttr(); } - if (!$attr || !$goodsSku) { + if (!$attr || !$goodsSku || !$goodsModel) { throw new \yii\db\Exception('系统异常'); } if ($type == Goods::SKU_MODE_MANUAL) { @@ -375,6 +376,7 @@ class GoodsManager $goodsSku->price = $sku['price']; $goodsSku->stock = $sku['stock']; $goodsSku->weight = $sku['weight']; + $goodsSku->goods_sn = $goodsModel->sn; if (!$goodsSku->save()) { throw new \yii\db\Exception('保存失败,请检查是否有重复规格'); } diff --git a/vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php b/vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php new file mode 100644 index 0000000..3ee066e --- /dev/null +++ b/vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php @@ -0,0 +1,26 @@ +dropColumn('antgoods_goods_attr', 'goods_id'); + $this->dropColumn('antgoods_goods_attr', 'attr_id'); + $this->addColumn('antgoods_goods_attr', 'goods_id', $this->integer(11)->notNull()->defaultValue(0)->comment('商品id')); + $this->addColumn('antgoods_goods_attr', 'attr_id', $this->integer(11)->notNull()->defaultValue(0)->comment('属性id')); + } + + public function down() + { + $this->dropColumn('antgoods_goods_attr', 'goods_id'); + $this->dropColumn('antgoods_goods_attr', 'attr_id'); + $this->addColumn('antgoods_goods_attr', 'goods_id', $this->integer(11)->notNull()->comment('商品id')); + $this->addColumn('antgoods_goods_attr', 'attr_id', $this->integer(11)->notNull()->comment('属性id')); + return true; + } +} diff --git a/vendor/antgoods/goods/src/models/ars/GoodsAttr.php b/vendor/antgoods/goods/src/models/ars/GoodsAttr.php index 3573764..7d350d6 100644 --- a/vendor/antgoods/goods/src/models/ars/GoodsAttr.php +++ b/vendor/antgoods/goods/src/models/ars/GoodsAttr.php @@ -35,7 +35,7 @@ class GoodsAttr extends \yii\db\ActiveRecord public function rules() { return [ - [['goods_id', 'attr_id', 'attr_value'], 'required'], + [['attr_value'], 'required'], [['goods_id', 'attr_id', 'is_delete'], 'integer'], [['attr_value'], 'string', 'max' => 50], ];