mtwm.getUploadImgPoiCode随机得到上传图片的美团店(看看是否是传图片API限频是按门店维度的)
This commit is contained in:
@@ -2,6 +2,7 @@ package mtwm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ type PurchaseHandler struct {
|
|||||||
partner.BasePurchasePlatform
|
partner.BasePurchasePlatform
|
||||||
putils.DefSingleStorePlatform
|
putils.DefSingleStorePlatform
|
||||||
|
|
||||||
poiCode4UploadImg string
|
storeIDs []string
|
||||||
locker sync.RWMutex
|
locker sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -185,25 +186,30 @@ func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgDa
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
|
func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
|
||||||
|
var storeIDs []string
|
||||||
p.locker.RLock()
|
p.locker.RLock()
|
||||||
poiCode = p.poiCode4UploadImg
|
storeIDs = p.storeIDs
|
||||||
p.locker.RUnlock()
|
p.locker.RUnlock()
|
||||||
if poiCode != "" {
|
if len(storeIDs) > 0 {
|
||||||
return poiCode
|
return storeIDs[rand.Intn(len(storeIDs))]
|
||||||
}
|
}
|
||||||
|
|
||||||
p.locker.Lock()
|
p.locker.Lock()
|
||||||
poiCode = p.poiCode4UploadImg
|
storeIDs = p.storeIDs
|
||||||
if poiCode != "" {
|
if len(storeIDs) > 0 {
|
||||||
p.locker.Unlock()
|
p.locker.Unlock()
|
||||||
return poiCode
|
return storeIDs[rand.Intn(len(storeIDs))]
|
||||||
}
|
}
|
||||||
|
|
||||||
defer p.locker.Unlock()
|
defer p.locker.Unlock()
|
||||||
storeIDs, err := api.MtwmAPI.PoiGetIDs()
|
storeIDs, err := api.MtwmAPI.PoiGetIDs()
|
||||||
if err == nil && len(storeIDs) > 0 {
|
if err == nil {
|
||||||
poiCode = storeIDs[0]
|
if len(storeIDs) > 0 {
|
||||||
|
p.storeIDs = storeIDs
|
||||||
|
poiCode = storeIDs[rand.Intn(len(storeIDs))]
|
||||||
|
} else {
|
||||||
|
// p.storeIDs = []string{""}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
p.poiCode4UploadImg = poiCode
|
|
||||||
return poiCode
|
return poiCode
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user