Browse Source

商品属性表修改goods_id和attr_id字段,完成sku添加方法的bug修复

wechat_public_accounts
linyaostalker 5 years ago
parent
commit
fae4b2ea04
  1. 1
      vendor/antgoods/goods/src/controllers/GoodsController.php
  2. 6
      vendor/antgoods/goods/src/logic/goods/GoodsManager.php
  3. 26
      vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php
  4. 2
      vendor/antgoods/goods/src/models/ars/GoodsAttr.php

1
vendor/antgoods/goods/src/controllers/GoodsController.php

@ -2,6 +2,7 @@
namespace antgoods\goods\controllers; namespace antgoods\goods\controllers;
use antgoods\goods\models\ars\GoodsAttr;
use antgoods\goods\models\ars\GoodsSku; use antgoods\goods\models\ars\GoodsSku;
use common\models\ars\TemFile; use common\models\ars\TemFile;
use MongoDB\Driver\Manager; use MongoDB\Driver\Manager;

6
vendor/antgoods/goods/src/logic/goods/GoodsManager.php

@ -285,7 +285,7 @@ class GoodsManager
$data['id'] = $sku->id; $data['id'] = $sku->id;
$data['price'] = $sku->price; $data['price'] = $sku->price;
$data['stock'] = $sku->stock; $data['stock'] = $sku->stock;
$data['weight'] = $sku->goods_weight;
$data['weight'] = $sku->weight;
return $data; return $data;
} }
@ -350,6 +350,7 @@ class GoodsManager
*/ */
public static function AddOrUpdateData($sku, $type, $goodsId) public static function AddOrUpdateData($sku, $type, $goodsId)
{ {
$goodsModel = Goods::findOne($goodsId);
if ($sku['id'] > 0) { if ($sku['id'] > 0) {
$goodsSku = GoodsSku::findOne($sku['id']); $goodsSku = GoodsSku::findOne($sku['id']);
$attrId = array_filter(explode(',', $goodsSku->goods_attr)); $attrId = array_filter(explode(',', $goodsSku->goods_attr));
@ -358,7 +359,7 @@ class GoodsManager
$goodsSku = new GoodsSku(); $goodsSku = new GoodsSku();
$attr = new GoodsAttr(); $attr = new GoodsAttr();
} }
if (!$attr || !$goodsSku) {
if (!$attr || !$goodsSku || !$goodsModel) {
throw new \yii\db\Exception('系统异常'); throw new \yii\db\Exception('系统异常');
} }
if ($type == Goods::SKU_MODE_MANUAL) { if ($type == Goods::SKU_MODE_MANUAL) {
@ -375,6 +376,7 @@ class GoodsManager
$goodsSku->price = $sku['price']; $goodsSku->price = $sku['price'];
$goodsSku->stock = $sku['stock']; $goodsSku->stock = $sku['stock'];
$goodsSku->weight = $sku['weight']; $goodsSku->weight = $sku['weight'];
$goodsSku->goods_sn = $goodsModel->sn;
if (!$goodsSku->save()) { if (!$goodsSku->save()) {
throw new \yii\db\Exception('保存失败,请检查是否有重复规格'); throw new \yii\db\Exception('保存失败,请检查是否有重复规格');
} }

26
vendor/antgoods/goods/src/migrations/m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr.php

@ -0,0 +1,26 @@
<?php
use yii\db\Migration;
/**
* Class m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr
*/
class m191129_020131_add_columns_goods_id_and_attr_id_in_table_antgoods_goods_attr extends Migration
{
public function up()
{
$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()->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;
}
}

2
vendor/antgoods/goods/src/models/ars/GoodsAttr.php

@ -35,7 +35,7 @@ class GoodsAttr extends \yii\db\ActiveRecord
public function rules() public function rules()
{ {
return [ return [
[['goods_id', 'attr_id', 'attr_value'], 'required'],
[['attr_value'], 'required'],
[['goods_id', 'attr_id', 'is_delete'], 'integer'], [['goods_id', 'attr_id', 'is_delete'], 'integer'],
[['attr_value'], 'string', 'max' => 50], [['attr_value'], 'string', 'max' => 50],
]; ];

Loading…
Cancel
Save