From 2ac1efa1de90d5535dc55be6238fb4762a5a3da9 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 26 Sep 2019 16:28:22 +0800 Subject: [PATCH] =?UTF-8?q?mtwm.getUploadImgPoiCode=E9=9A=8F=E6=9C=BA?= =?UTF-8?q?=E5=BE=97=E5=88=B0=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E7=9A=84?= =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E5=BA=97=EF=BC=88=E7=9C=8B=E7=9C=8B=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E6=98=AF=E4=BC=A0=E5=9B=BE=E7=89=87API=E9=99=90?= =?UTF-8?q?=E9=A2=91=E6=98=AF=E6=8C=89=E9=97=A8=E5=BA=97=E7=BB=B4=E5=BA=A6?= =?UTF-8?q?=E7=9A=84=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/partner/purchase/mtwm/mtwm.go | 28 ++++++++++++++++---------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/business/partner/purchase/mtwm/mtwm.go b/business/partner/purchase/mtwm/mtwm.go index 1854d5c57..1f6c280ff 100644 --- a/business/partner/purchase/mtwm/mtwm.go +++ b/business/partner/purchase/mtwm/mtwm.go @@ -2,6 +2,7 @@ package mtwm import ( "fmt" + "math/rand" "strings" "sync" @@ -24,8 +25,8 @@ type PurchaseHandler struct { partner.BasePurchasePlatform putils.DefSingleStorePlatform - poiCode4UploadImg string - locker sync.RWMutex + storeIDs []string + locker sync.RWMutex } func init() { @@ -185,25 +186,30 @@ func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgDa } func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) { + var storeIDs []string p.locker.RLock() - poiCode = p.poiCode4UploadImg + storeIDs = p.storeIDs p.locker.RUnlock() - if poiCode != "" { - return poiCode + if len(storeIDs) > 0 { + return storeIDs[rand.Intn(len(storeIDs))] } p.locker.Lock() - poiCode = p.poiCode4UploadImg - if poiCode != "" { + storeIDs = p.storeIDs + if len(storeIDs) > 0 { p.locker.Unlock() - return poiCode + return storeIDs[rand.Intn(len(storeIDs))] } defer p.locker.Unlock() storeIDs, err := api.MtwmAPI.PoiGetIDs() - if err == nil && len(storeIDs) > 0 { - poiCode = storeIDs[0] + if err == nil { + if len(storeIDs) > 0 { + p.storeIDs = storeIDs + poiCode = storeIDs[rand.Intn(len(storeIDs))] + } else { + // p.storeIDs = []string{""} + } } - p.poiCode4UploadImg = poiCode return poiCode }