mtwm.getStoreIDFromList
This commit is contained in:
@@ -2,7 +2,6 @@ package mtwm
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
@@ -185,20 +184,27 @@ func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, imgURL string, imgDa
|
|||||||
return imgHint, err
|
return imgHint, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getStoreIDFromList(storeIDs []string) (poiCode string) {
|
||||||
|
if len(storeIDs) > 0 {
|
||||||
|
poiCode = storeIDs[0]
|
||||||
|
}
|
||||||
|
return poiCode
|
||||||
|
}
|
||||||
|
|
||||||
func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
|
func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
|
||||||
var storeIDs []string
|
var storeIDs []string
|
||||||
p.locker.RLock()
|
p.locker.RLock()
|
||||||
storeIDs = p.storeIDs
|
storeIDs = p.storeIDs
|
||||||
p.locker.RUnlock()
|
p.locker.RUnlock()
|
||||||
if len(storeIDs) > 0 {
|
if len(storeIDs) > 0 {
|
||||||
return storeIDs[rand.Intn(len(storeIDs))]
|
return getStoreIDFromList(storeIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
p.locker.Lock()
|
p.locker.Lock()
|
||||||
storeIDs = p.storeIDs
|
storeIDs = p.storeIDs
|
||||||
if len(storeIDs) > 0 {
|
if len(storeIDs) > 0 {
|
||||||
p.locker.Unlock()
|
p.locker.Unlock()
|
||||||
return storeIDs[rand.Intn(len(storeIDs))]
|
return getStoreIDFromList(storeIDs)
|
||||||
}
|
}
|
||||||
|
|
||||||
defer p.locker.Unlock()
|
defer p.locker.Unlock()
|
||||||
@@ -206,7 +212,7 @@ func (p *PurchaseHandler) getUploadImgPoiCode() (poiCode string) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
if len(storeIDs) > 0 {
|
if len(storeIDs) > 0 {
|
||||||
p.storeIDs = storeIDs
|
p.storeIDs = storeIDs
|
||||||
poiCode = storeIDs[rand.Intn(len(storeIDs))]
|
poiCode = getStoreIDFromList(storeIDs)
|
||||||
} else {
|
} else {
|
||||||
// p.storeIDs = []string{""}
|
// p.storeIDs = []string{""}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user