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 }