Merge pull request '添加skuId' (#97) from test into master

Reviewed-on: https://git.oa00.com/recook/backend_v2/pulls/97
master
杨赟 3 years ago
commit 598c89f8cd

@ -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
})
}

@ -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

Loading…
Cancel
Save