From bfc3b5f94519c003c173453f892767984d6e140c Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 17 Apr 2019 15:27:43 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E9=97=A8=E5=BA=97=E4=BB=B7=E9=99=90?= =?UTF-8?q?=E5=88=B6=E4=B8=8D=E8=83=BD=E4=B8=BA=E8=B4=9F=E6=95=B0=20-=20?= =?UTF-8?q?=E4=BA=AC=E4=B8=9C=E9=97=A8=E5=BA=97=E4=BB=B7=E9=99=90=E5=88=B6?= =?UTF-8?q?=E4=B8=BA=E6=9C=80=E5=B0=91=E4=B8=80=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxutils/jxutils_cms.go | 6 +++++- business/partner/purchase/jd/store_sku.go | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) 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 +}