From 1619d876c5185d92b473edc192fb5f1088044033 Mon Sep 17 00:00:00 2001 From: kanade Date: Thu, 1 Dec 2022 11:00:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0skuId?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/v2/logic/third/supply.go | 46 +++++++++++++------ .../v2/model/third/recookThirdPartySupply.go | 3 ++ 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/internal/v2/logic/third/supply.go b/internal/v2/logic/third/supply.go index 9635da0..b13f003 100644 --- a/internal/v2/logic/third/supply.go +++ b/internal/v2/logic/third/supply.go @@ -43,6 +43,13 @@ type skuItem struct { BrandName string `json:"brandName"` Price decimal.Decimal `json:"price"` GuidePrice decimal.Decimal `json:"guidePrice"` + SkuId uint `json:"skuId"` + GoodsId uint `json:"goodsId"` + PurchasePrice decimal.Decimal `json:"purchasePrice"` + OriginalPrice decimal.Decimal `json:"originalPrice"` + DiscountPrice decimal.Decimal `json:"discountPrice"` + Coupon decimal.Decimal `json:"coupon"` + ControlPrice decimal.Decimal `json:"controlPrice"` } type SupplySearch struct { Status uint @@ -75,7 +82,7 @@ func (s *supplyLogic) Lists(search SupplySearch, page bean.Page) (lists []skuIte } else { mysql.Db.Model(thirdPartySupplies).Where(where).Count(&total) if page.HasPage(total) { - mysql.Db.Where(where).Offset(page.GetStart()).Limit(page.GetLimit()).Order("id desc").Find(&thirdPartySupplies) + mysql.Db.Preload("Sku").Where(where).Offset(page.GetStart()).Limit(page.GetLimit()).Order("id desc").Find(&thirdPartySupplies) } } for _, thirdPartySupply := range thirdPartySupplies { @@ -91,6 +98,13 @@ func (s *supplyLogic) Lists(search SupplySearch, page bean.Page) (lists []skuIte BrandName: thirdPartySupply.BrandName, Price: thirdPartySupply.Price, GuidePrice: thirdPartySupply.GuidePrice, + SkuId: thirdPartySupply.SkuId, + GoodsId: thirdPartySupply.GoodsId, + PurchasePrice: thirdPartySupply.Sku.PurchasePrice, + OriginalPrice: thirdPartySupply.Sku.OriginalPrice, + DiscountPrice: thirdPartySupply.Sku.DiscountPrice, + Coupon: thirdPartySupply.Sku.Coupon, + ControlPrice: thirdPartySupply.Sku.ControlPrice, }) } return @@ -191,13 +205,6 @@ func (s *supplyLogic) Adopt(data AdoptSkuInfo) error { if len(recookGoodsSkuModels) > 0 { // 已添加过商品 return mysql.Db.Transaction(func(tx *gorm.DB) error { - // 原数据处理 - if tx.Model(&manage.RecookThirdPartySupply{}).Where("id = ?", thirdPartySupply.Id).Updates(map[string]interface{}{ - "status": manage.RecookThirdPartySupplyStatusAdopt, - "goods_id": recookGoodsSkuModels[0].GoodsId, - }).RowsAffected != 1 { - return errors.New("入库失败") - } // 详情 if thirdPartySupply.Content != "" { if tx.Model(&goods.RecookGoodsContentModel{}).Where("goods_id = ?", recookGoodsSkuModels[0].GoodsId).Update("content", thirdPartySupply.Content).Error != nil { @@ -344,6 +351,14 @@ func (s *supplyLogic) Adopt(data AdoptSkuInfo) error { if tx.Create(&sku).Error != nil { return errors.New("入库失败") } + // 原数据处理 + if tx.Model(&manage.RecookThirdPartySupply{}).Where("id = ? and goods_id = 0", thirdPartySupply.Id).Updates(map[string]interface{}{ + "status": manage.RecookThirdPartySupplyStatusAdopt, + "goods_id": recookGoodsSkuModels[0].GoodsId, + "sku_id": sku.Id, + }).RowsAffected != 1 { + return errors.New("入库失败") + } return nil }) } else { @@ -372,13 +387,6 @@ func (s *supplyLogic) Adopt(data AdoptSkuInfo) error { if tx.Create(&recookGoodsInfoModel).Error != nil { return errors.New("入库失败") } - // 原数据处理 - if tx.Model(&manage.RecookThirdPartySupply{}).Where("id = ?", thirdPartySupply.Id).Updates(map[string]interface{}{ - "status": manage.RecookThirdPartySupplyStatusAdopt, - "goods_id": recookGoodsInfoModel.Id, - }).RowsAffected != 1 { - return errors.New("入库失败") - } // 商品详情 recookGoodsContentModel := goods.RecookGoodsContentModel{ @@ -495,6 +503,14 @@ func (s *supplyLogic) Adopt(data AdoptSkuInfo) error { if tx.Create(&sku).Error != nil { return errors.New("入库失败") } + // 原数据处理 + if tx.Model(&manage.RecookThirdPartySupply{}).Where("id = ? and goods_id = 0", thirdPartySupply.Id).Updates(map[string]interface{}{ + "status": manage.RecookThirdPartySupplyStatusAdopt, + "goods_id": recookGoodsInfoModel.Id, + "sku_id": sku.Id, + }).RowsAffected != 1 { + return errors.New("入库失败") + } return nil }) } diff --git a/internal/v2/model/third/recookThirdPartySupply.go b/internal/v2/model/third/recookThirdPartySupply.go index cf77523..a284f50 100644 --- a/internal/v2/model/third/recookThirdPartySupply.go +++ b/internal/v2/model/third/recookThirdPartySupply.go @@ -2,6 +2,7 @@ package manage import ( "github.com/shopspring/decimal" + "recook/internal/v2/model/recook/goods" "time" ) @@ -44,6 +45,8 @@ type RecookThirdPartySupply struct { Status uint // 状态 1=未入库 2=已入库 SupplyStatus uint // 供应链状态 1=上架 2=下架 GoodsId uint // 瑞库客商品id + SkuId uint // 瑞库客skuId + Sku goods.RecookGoodsSkuModel `gorm:"foreignKey:SkuId"` Imgs []RecookThirdPartySupplyImg `gorm:"foreignKey:SupplySkuId;references:SupplySkuId"` Specifications []RecookThirdPartySupplySpecification `gorm:"foreignKey:SupplySkuId;references:SupplySkuId"` CreatedAt time.Time