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