diff --git a/business/jxutils/jxutils_cms.go b/business/jxutils/jxutils_cms.go index 0279a86bc..ef086b531 100644 --- a/business/jxutils/jxutils_cms.go +++ b/business/jxutils/jxutils_cms.go @@ -178,7 +178,11 @@ func GetSliceLen(list interface{}) int { } func CaculateSkuVendorPrice(price int, percentage int) int { - return int(math.Round(float64(price*percentage) / 100)) + storePrice := int(math.Round(float64(price*percentage) / 100)) + if storePrice < 0 { + storePrice = 0 + } + return storePrice } // 生成一个不重复的临时ID diff --git a/business/partner/purchase/jd/store_sku.go b/business/partner/purchase/jd/store_sku.go index 8332a072f..b7418b660 100644 --- a/business/partner/purchase/jd/store_sku.go +++ b/business/partner/purchase/jd/store_sku.go @@ -83,7 +83,7 @@ func (p *PurchaseHandler) SyncStoreSkus(ctx *jxcontext.Context, parentTask tasks if storeSku.JdSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ OutSkuId: utils.Int2Str(storeSku.SkuID), - Price: jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage), + Price: constrainPrice(jxutils.CaculateSkuVendorPrice(storeSku.Price, storeSku.PricePercentage)), }) } if storeSku.JdSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { @@ -215,7 +215,7 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks if storeSku.SkuSyncStatus&(model.SyncFlagPriceMask|model.SyncFlagNewMask) != 0 { skuPriceInfoList = append(skuPriceInfoList, &jdapi.SkuPriceInfo{ OutSkuId: utils.Int2Str(storeSku.ID), - Price: jxutils.CaculateSkuVendorPrice(int(storeSku.Price), int(storeDetail.PricePercentage)), + Price: constrainPrice(jxutils.CaculateSkuVendorPrice(int(storeSku.Price), int(storeDetail.PricePercentage))), }) } if storeSku.SkuSyncStatus&(model.SyncFlagSaleMask|model.SyncFlagNewMask) != 0 { @@ -271,3 +271,10 @@ func (p *PurchaseHandler) syncStoreSkus(ctx *jxcontext.Context, parentTask tasks func (p *PurchaseHandler) DeleteRemoteStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, storeID int, isAsync, isContinueWhenError bool) (hint string, err error) { return hint, err } + +func constrainPrice(price int) int { + if price <= 0 { + price = 1 + } + return price +}