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], ];