mtwm.getUploadImgPoiCode随机得到上传图片的美团店(看看是否是传图片API限频是按门店维度的)

This commit is contained in:
gazebo
2019-09-26 16:28:22 +08:00
parent 0b2321e7a6
commit 2ac1efa1de

View File

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