修正自动更新门店数量和营业时间的问题
This commit is contained in:
@@ -1,17 +1,13 @@
|
||||
package misc
|
||||
|
||||
import (
|
||||
//"fmt"
|
||||
"time"
|
||||
"encoding/json"
|
||||
"strconv"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxstore/cms"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils"
|
||||
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
|
||||
"git.rosy.net.cn/jx-callback/business/model"
|
||||
"git.rosy.net.cn/jx-callback/business/partner"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"git.rosy.net.cn/jx-callback/business/partner/putils"
|
||||
"git.rosy.net.cn/baseapi"
|
||||
)
|
||||
@@ -39,25 +35,15 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func SetStoreOptime(startTime, endTime int16) {
|
||||
if startTime == 0 || endTime == 0 {
|
||||
startOpStoreTime = startOpStoreTimeDefault
|
||||
endOpStoreTime = endOpStoreTimeDefault
|
||||
baseapi.SugarLogger.Debugf("The store time can't be 0")
|
||||
} else {
|
||||
startOpStoreTime = startTime
|
||||
endOpStoreTime = endTime
|
||||
baseapi.SugarLogger.Debugf("SetStoreOptime:%d do:%d", startTime, endTime)
|
||||
}
|
||||
}
|
||||
|
||||
func AddOrDelExtraStoreOptime(vendorID, storeID int, vendorStoreID string, storeInfo *model.Store, needAddTime bool) {
|
||||
ctx := jxcontext.AdminCtx
|
||||
opTimeList := storeInfo.GetOpTimeList()
|
||||
if needAddTime {
|
||||
if len(opTimeList) == 2 {
|
||||
if len(opTimeList) == 0 {
|
||||
opTimeList = append(opTimeList, startOpStoreTime, endOpStoreTime)
|
||||
} else if len(opTimeList) >= 2 {
|
||||
opTimeList[0] = startOpStoreTime
|
||||
opTimeList[1] = endOpStoreTime
|
||||
opTimeList[1] = endOpStoreTime
|
||||
}
|
||||
}
|
||||
handler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IStoreHandler)
|
||||
@@ -72,20 +58,16 @@ func GetStockValue(startOrEnd bool) int {
|
||||
}
|
||||
}
|
||||
|
||||
func GetSkuNameMap(vendorID, storeID int, vendorStoreID string) map[int]*partner.SkuNameInfo {
|
||||
skuNameMap := make(map[int]*partner.SkuNameInfo)
|
||||
ctx := jxcontext.AdminCtx
|
||||
singleStoreHandler, _ := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
skuNameList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, storeID, vendorStoreID, nil)
|
||||
if err == nil {
|
||||
for _, value := range skuNameList {
|
||||
skuNameMap[value.NameID] = value
|
||||
}
|
||||
func StartOrEndOpStore(startOrEnd bool, startTime, endTime int16) {
|
||||
if startTime == 0 || endTime == 0 {
|
||||
startOpStoreTime = startOpStoreTimeDefault
|
||||
endOpStoreTime = endOpStoreTimeDefault
|
||||
baseapi.SugarLogger.Debugf("The store time can't be 0")
|
||||
} else {
|
||||
startOpStoreTime = startTime
|
||||
endOpStoreTime = endTime
|
||||
baseapi.SugarLogger.Debugf("SetStoreOptime:%d do:%d", startTime, endTime)
|
||||
}
|
||||
return skuNameMap
|
||||
}
|
||||
|
||||
func StartOrEndOpStore(startOrEnd bool) {
|
||||
ctx := jxcontext.AdminCtx
|
||||
storeInfo, err := cms.GetStores(ctx, "", map[string]interface{}{}, 0, -1, utils.DefaultTimeValue, utils.DefaultTimeValue, 0, 0)
|
||||
|
||||
@@ -97,19 +79,26 @@ func StartOrEndOpStore(startOrEnd bool) {
|
||||
if storeListValue.StoreMaps != nil {
|
||||
for _, vendorListValue := range storeListValue.StoreMaps {
|
||||
vendorID, _ := strconv.Atoi(vendorListValue["vendorID"].(json.Number).String())
|
||||
vendorStoreID := vendorListValue["vendorStoreID"].(string)
|
||||
baseapi.SugarLogger.Debugf("storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue)
|
||||
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
storeSkuList, err := storeSkuHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, nil)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("storeSkuList error:%v", err)
|
||||
} else {
|
||||
if _, ok := vendorList[vendorID]; ok {
|
||||
if _, ok := vendorList[vendorID]; ok {
|
||||
vendorStoreID := vendorListValue["vendorStoreID"].(string)
|
||||
baseapi.SugarLogger.Debugf("storeID:%d vendorID:%d vendorStoreID:%s vendorListValue:%v", storeID, vendorID, vendorStoreID, vendorListValue)
|
||||
storeSkuHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.IPurchasePlatformStoreSkuHandler)
|
||||
// storeSkuList, err := storeSkuHandler.GetStoreSkusBareInfo(ctx, nil, storeID, vendorStoreID, nil)
|
||||
singleStoreHandler := partner.GetPurchasePlatformFromVendorID(vendorID).(partner.ISingleStoreStoreSkuHandler)
|
||||
storeSkuNameList, err := singleStoreHandler.GetStoreSkusFullInfo(ctx, nil, storeID, vendorStoreID, nil)
|
||||
storeSkuList := putils.StoreSkuFullList2Bare(storeSkuNameList)
|
||||
if err != nil {
|
||||
baseapi.SugarLogger.Errorf("storeSkuList error:%v", err)
|
||||
} else {
|
||||
if len(storeSkuList) > 0 {
|
||||
if !startOrEnd {
|
||||
AddOrDelExtraStoreOptime(vendorID, storeID, vendorStoreID, &storeListValue.Store, false)
|
||||
}
|
||||
skuNameMap := GetSkuNameMap(vendorID, storeID, vendorStoreID)
|
||||
skuNameMap := make(map[int]*partner.SkuNameInfo)
|
||||
for _, value := range storeSkuNameList {
|
||||
skuNameMap[value.NameID] = value
|
||||
}
|
||||
|
||||
isContinueWhenError := true
|
||||
_, err = putils.FreeBatchStoreSkuInfo(func(batchedStoreSkuList []*partner.StoreSkuInfo) (result interface{}, err error) {
|
||||
var filterBatchedStoreSkuList []*partner.StoreSkuInfo
|
||||
@@ -147,17 +136,10 @@ func StartOrEndOpStore(startOrEnd bool) {
|
||||
}
|
||||
|
||||
func InitEx() {
|
||||
ScheduleTimerFuncEx(StartOrEndOpStore, true, startOpStoreTimeList)
|
||||
ScheduleTimerFuncEx(StartOrEndOpStore, false, endOpStoreTimeList)
|
||||
}
|
||||
|
||||
func ScheduleTimerFuncEx(handler func(bool), startOrEnd bool, timeList []string) {
|
||||
now := time.Now()
|
||||
nextTime := jxutils.GetNextTimeFromList(now, timeList)
|
||||
duration := nextTime.Sub(now) + 1 * time.Second
|
||||
globals.SugarLogger.Debugf("ScheduleTimerFunc, duration:%v", duration)
|
||||
utils.AfterFuncWithRecover(duration, func() {
|
||||
handler(startOrEnd)
|
||||
ScheduleTimerFuncEx(handler, startOrEnd, timeList)
|
||||
})
|
||||
ScheduleTimerFunc(func() {
|
||||
StartOrEndOpStore(true, 0, 0)
|
||||
}, startOpStoreTimeList)
|
||||
ScheduleTimerFunc(func() {
|
||||
StartOrEndOpStore(false, 0, 0)
|
||||
}, endOpStoreTimeList)
|
||||
}
|
||||
@@ -5,5 +5,5 @@ import (
|
||||
)
|
||||
|
||||
func TestStartOrEndOpStore(t *testing.T) {
|
||||
StartOrEndOpStore(true)
|
||||
StartOrEndOpStore(true, 0, 0)
|
||||
}
|
||||
|
||||
@@ -284,8 +284,7 @@ func (c *TempOpController) TestIt() {
|
||||
// @router /TestStartOrEndOpStore [get]
|
||||
func (c *TempOpController) TestStartOrEndOpStore() {
|
||||
c.callTestStartOrEndOpStore(func(params *tTempopTestStartOrEndOpStoreParams) (retVal interface{}, errCode string, err error) {
|
||||
misc.SetStoreOptime(int16(params.StartTime), int16(params.EndTime))
|
||||
misc.StartOrEndOpStore(params.StartOrEndStore)
|
||||
misc.StartOrEndOpStore(params.StartOrEndStore, int16(params.StartTime), int16(params.EndTime))
|
||||
return retVal, "", err
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user