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