1086 lines
34 KiB
Go
1086 lines
34 KiB
Go
package misc
|
||
|
||
import (
|
||
"fmt"
|
||
"sync"
|
||
"time"
|
||
|
||
"git.rosy.net.cn/baseapi/platformapi/dingdingapi"
|
||
"git.rosy.net.cn/jx-callback/business/bidding"
|
||
"git.rosy.net.cn/jx-callback/business/jxcallback/auto_delivery"
|
||
"git.rosy.net.cn/jx-callback/business/jxutils/ddmsg"
|
||
"git.rosy.net.cn/jx-callback/business/partner/delivery"
|
||
|
||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jdshop"
|
||
|
||
"git.rosy.net.cn/baseapi/platformapi/jdapi"
|
||
|
||
"git.rosy.net.cn/jx-callback/business/partner/purchase/jx/localjx"
|
||
"git.rosy.net.cn/jx-callback/globals/api"
|
||
|
||
"git.rosy.net.cn/jx-callback/business/jxstore/report"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
"git.rosy.net.cn/baseapi/utils/errlist"
|
||
"git.rosy.net.cn/jx-callback/business/jxcallback/orderman"
|
||
"git.rosy.net.cn/jx-callback/business/jxcallback/scheduler/defsch"
|
||
"git.rosy.net.cn/jx-callback/business/jxstore/act"
|
||
"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/netprinter"
|
||
"git.rosy.net.cn/jx-callback/business/jxutils/tasksch"
|
||
"git.rosy.net.cn/jx-callback/business/model"
|
||
"git.rosy.net.cn/jx-callback/business/model/dao"
|
||
"git.rosy.net.cn/jx-callback/business/netspider"
|
||
"git.rosy.net.cn/jx-callback/business/partner"
|
||
"git.rosy.net.cn/jx-callback/globals"
|
||
beego "github.com/astaxie/beego/server/web"
|
||
)
|
||
|
||
const (
|
||
SpecialTaskID = "Running"
|
||
TaskNameSyncStoreSku = "SyncStoreSku"
|
||
)
|
||
|
||
var (
|
||
dailyHeartbeat = []string{
|
||
"09:00:00",
|
||
}
|
||
dailyWorkTimeList = []string{
|
||
"21:30:00",
|
||
}
|
||
dailyWorkTimeList2 = []string{
|
||
"02:30:00",
|
||
}
|
||
priceReferTimeList = []string{
|
||
"03:00:00",
|
||
}
|
||
checkCookieList = []string{
|
||
"08:00:00",
|
||
"12:00:00",
|
||
"18:00:00",
|
||
}
|
||
createStorePriceTimeList = []string{
|
||
"04:00:00",
|
||
}
|
||
refreshPageActTimeList = []string{
|
||
"7:00:00",
|
||
"8:00:00",
|
||
"9:00:00",
|
||
"10:00:00",
|
||
"11:00:00",
|
||
"12:00:00",
|
||
"13:00:00",
|
||
"14:00:00",
|
||
"15:00:00",
|
||
"16:00:00",
|
||
"17:00:00",
|
||
"18:00:00",
|
||
"19:00:00",
|
||
"22:00:00",
|
||
}
|
||
ChangeStoreSkuSaleStatusList = []string{
|
||
"7:00:00",
|
||
"8:00:00",
|
||
"9:00:00",
|
||
//"10:00:00",
|
||
//"11:00:00",
|
||
//"12:00:00",
|
||
//"13:00:00",
|
||
//"14:00:00",
|
||
//"15:00:00",
|
||
//"16:00:00",
|
||
//"17:00:00",
|
||
//"18:00:00",
|
||
//"19:00:00",
|
||
//"20:00:00",
|
||
}
|
||
openRemoteStoreTimeList = []string{
|
||
"04:30:00",
|
||
"23:30:00",
|
||
}
|
||
updateActStatusTimeList = []string{
|
||
"00:01:00",
|
||
}
|
||
sendSecKillWarnList = []string{
|
||
"9:00:00",
|
||
}
|
||
autoPayForPopluarManList = []string{
|
||
"10:30:00",
|
||
}
|
||
|
||
autoSaleStoreSkuTimeList = []string{
|
||
cms.AutoSaleAtStr,
|
||
}
|
||
|
||
backUpStoreSkuBindList = []string{
|
||
"23:30:00",
|
||
}
|
||
|
||
exSyncList = []string{
|
||
"11:30:00",
|
||
}
|
||
|
||
importantTaskMap = &sync.Map{}
|
||
|
||
cancelPayTimeOutOrderList = localjx.GetHalfHoursList()
|
||
discountActJxList = localjx.GetDiscountActHoursList()
|
||
|
||
//ebaiStorePageCookieExdTOKEN string
|
||
//ebaiStorePageCookieWMUSS2 string
|
||
//ebaiStorePageCookieWMSTOKEN2 string
|
||
ebaiStorePageCookie string
|
||
//ebaiStorePageCookieWMSTOKEN string
|
||
mtwmCookieStr string
|
||
mtpsStoreToken string
|
||
jd2StorePageCookie string
|
||
JdStorePageCookie string
|
||
yinbaoCookie string
|
||
feiePageCookie string
|
||
jdStorePageEarning string
|
||
//jdsCookie string
|
||
// jdsCookie2 string
|
||
)
|
||
|
||
func GetImportantTaskID(taskName string) string {
|
||
if value, ok := importantTaskMap.Load(taskName); ok {
|
||
return value.(string)
|
||
}
|
||
return ""
|
||
}
|
||
|
||
func SaveImportantTaskID(taskName, taskID string) {
|
||
importantTaskMap.Store(taskName, taskID)
|
||
}
|
||
|
||
func IsImportantTaskRunning(taskName string) bool {
|
||
taskID := GetImportantTaskID(taskName)
|
||
if taskID == "" {
|
||
return false
|
||
} else if taskID == SpecialTaskID {
|
||
return true
|
||
}
|
||
return tasksch.IsTaskRunning(taskID)
|
||
}
|
||
|
||
func Init() {
|
||
if globals.IsProductEnv() {
|
||
//ScheduleTimerFunc("doDailyWork2", doDailyWork2, dailyWorkTimeList2)
|
||
|
||
//京东的订单信息解密密钥获取
|
||
ScheduleTimerFuncByInterval(func() {
|
||
jdshop.InitKey()
|
||
}, 5*time.Second, 8*time.Hour)
|
||
|
||
ScheduleTimerFuncByInterval(func() {
|
||
RefreshRealMobile(jxcontext.AdminCtx, model.VendorIDEBAI, time.Now().Add(-24*time.Hour), utils.DefaultTimeValue, false, true)
|
||
report.RefreshStoreManageState(jxcontext.AdminCtx, nil, []int{model.VendorIDJD})
|
||
}, 5*time.Second, 1*time.Hour)
|
||
|
||
// 每五分钟轮询一次推送骑手信息坐标给美团
|
||
ScheduleTimerFuncByInterval(func() {
|
||
delivery.GetOrderRiderInfoToPlatform("", 0)
|
||
}, 10*time.Second, 4*time.Minute)
|
||
|
||
//每天晚上23:00更新抖店 审核状态
|
||
ScheduleTimerFunc("UpdateStorePoiStatus", func() {
|
||
cms.UpdateStorePoiStatus(jxcontext.AdminCtx)
|
||
}, []string{
|
||
"22:00:00",
|
||
})
|
||
//每天晚上23:00获取门店 电子围栏、仓库、限售模板、运费模板ID同步进数据库
|
||
ScheduleTimerFunc("UpdateStoreRelInformation", func() {
|
||
cms.UpdateStoreRelInformation(jxcontext.AdminCtx)
|
||
}, []string{
|
||
"22:00:00",
|
||
})
|
||
// 更新抖店订单的结算信息
|
||
ScheduleTimerFunc("UpdateTiktokShopTotalMoney", func() {
|
||
orderman.UpdateTiktokShopTotalMoney()
|
||
}, []string{
|
||
"03:35:00",
|
||
"09:35:00",
|
||
})
|
||
/// 更新淘鲜达结算信息
|
||
ScheduleTimerFunc("UpdateTaoTotalMoney", func() {
|
||
orderman.UpdateTaoSettleInfo()
|
||
}, []string{
|
||
"18:10:00",
|
||
})
|
||
|
||
// 每分钟轮询一次,推送骑手信息
|
||
ScheduleTimerFuncByInterval(func() {
|
||
delivery.UpdateFakeWayBillToTiktok()
|
||
}, 10*time.Second, 5*time.Second)
|
||
|
||
// (自动发单拣货,设置骑手)
|
||
ScheduleTimerFuncByInterval(func() {
|
||
auto_delivery.Init() // 初始化骑手列表
|
||
auto_delivery.AutoSettingFakeDelivery()
|
||
}, 10*time.Second, 3*time.Minute)
|
||
|
||
// 定时任务更新负责人信息
|
||
ScheduleTimerFunc("RefreshStoreOperator", func() {
|
||
cms.UpdateStoreOperatorConfig()
|
||
}, []string{
|
||
"04:00:00",
|
||
})
|
||
|
||
// 每天更新美团-门店结算方式[结算给企业/结算给个人]
|
||
ScheduleTimerFunc("LoadingStoreOrderSettleAmount", func() {
|
||
delivery.LoadingStoreOrderSettleAmount(0, 0, nil)
|
||
}, []string{
|
||
"19:50:00",
|
||
})
|
||
|
||
ScheduleTimerFunc("UpdateStoreName ", func() {
|
||
cms.UpdateStoreName()
|
||
}, []string{
|
||
"13:35:00",
|
||
})
|
||
|
||
// 定时任务更新昨天的都要商品和本地商品id的映射关系
|
||
//ScheduleTimerFunc("RefreshStoreOperator", func() {
|
||
// t := time.Now()
|
||
// cms.SyncTiktokMainIdToLocal(jxcontext.AdminCtx, &tiktok_store.MainSku{
|
||
// AppOrgCode: "",
|
||
// CheckStatus: 3,
|
||
// StartTime: time.Date(t.Year(), t.Month(), t.Day()-1, 0, 0, 1, 0, time.Local).Unix(),
|
||
// EndTime: time.Date(t.Year(), t.Month(), t.Day()-1, 23, 59, 59, 0, time.Local).Unix(),
|
||
// Page: 1,
|
||
// PageSize: 100,
|
||
// })
|
||
//}, []string{
|
||
// "04:30:00",
|
||
//})
|
||
|
||
ScheduleTimerFuncByInterval(func() {
|
||
defsch.FixedScheduler.ConfirmSelfTakeOrders(jxcontext.AdminCtx, []int{model.VendorIDJD}, time.Now().Add(-48*time.Hour), time.Now().Add(-30*time.Minute), true, true)
|
||
}, 5*time.Second, 10*time.Minute)
|
||
|
||
ScheduleTimerFuncByInterval(func() {
|
||
report.RefreshStoreManageState(jxcontext.AdminCtx, nil, []int{model.VendorIDMTWM, model.VendorIDEBAI})
|
||
}, 5*time.Second, 40*time.Minute)
|
||
|
||
ScheduleTimerFuncByInterval(func() {
|
||
orderman.SaveJdsOrders(jxcontext.AdminCtx, time.Now().Add(-30*time.Minute), time.Now())
|
||
orderman.UpdateJdsOrdersStatus(jxcontext.AdminCtx, time.Now().AddDate(0, 0, -1), time.Now())
|
||
}, 5*time.Second, 5*time.Minute)
|
||
|
||
ScheduleTimerFuncByInterval(func() {
|
||
curDate := utils.Time2Date(time.Now())
|
||
orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI, model.VendorIDDD}, 0, curDate, curDate, true, true)
|
||
}, 5*time.Second, 10*time.Minute)
|
||
|
||
// 抖音更新门店商品 ,接口收费暂不使用
|
||
//if beego.BConfig.RunMode != "jxgy" {
|
||
// ScheduleTimerFunc("RefreshSyncSkuList", func() {
|
||
// syncStoreSkuTiktok()
|
||
// }, []string{"13:00:00"})
|
||
//}
|
||
|
||
// 淘鲜达更新门店商品 ,接口收费暂不使用
|
||
ScheduleTimerFunc("RefreshSyncSkuListTao", func() {
|
||
var hangzhou = []int{
|
||
669113,
|
||
669111,
|
||
669110,
|
||
669109,
|
||
669108,
|
||
669107,
|
||
669106,
|
||
669103,
|
||
669100,
|
||
669099,
|
||
669098,
|
||
669097,
|
||
669096,
|
||
669095,
|
||
669094,
|
||
669093,
|
||
669092,
|
||
669091,
|
||
669087,
|
||
669086,
|
||
669085,
|
||
669084,
|
||
669083,
|
||
669082,
|
||
669079,
|
||
669078,
|
||
669077,
|
||
669075,
|
||
669074,
|
||
669072,
|
||
669070,
|
||
669067,
|
||
669064,
|
||
669063,
|
||
669062,
|
||
669060,
|
||
669059,
|
||
669056,
|
||
669055,
|
||
669054,
|
||
669050,
|
||
669049,
|
||
669047,
|
||
669046,
|
||
669045,
|
||
669042,
|
||
669041,
|
||
669038,
|
||
669036,
|
||
669035,
|
||
669033,
|
||
669032,
|
||
669031,
|
||
669027,
|
||
669025,
|
||
669024,
|
||
669022,
|
||
669021,
|
||
669020,
|
||
669017,
|
||
669015,
|
||
669014,
|
||
669012,
|
||
669009,
|
||
669007,
|
||
669002,
|
||
669000,
|
||
668999,
|
||
668997,
|
||
668996,
|
||
668993,
|
||
668988,
|
||
668986,
|
||
668984,
|
||
668966,
|
||
668963,
|
||
668961,
|
||
668958,
|
||
668954,
|
||
668950,
|
||
668948,
|
||
668946,
|
||
668943,
|
||
668938,
|
||
668928,
|
||
668910,
|
||
668907,
|
||
668900,
|
||
668897,
|
||
668896,
|
||
668891,
|
||
668889,
|
||
668883,
|
||
668882,
|
||
668868,
|
||
668860,
|
||
668855,
|
||
668853,
|
||
668850,
|
||
668849,
|
||
668843,
|
||
668838,
|
||
668807,
|
||
668802,
|
||
668784,
|
||
668773,
|
||
668771,
|
||
668767,
|
||
668766,
|
||
668755,
|
||
668749,
|
||
668728,
|
||
668724,
|
||
668722,
|
||
668721,
|
||
668716,
|
||
668706,
|
||
668704,
|
||
668699,
|
||
668697,
|
||
668695,
|
||
668693,
|
||
668692,
|
||
668688,
|
||
668686,
|
||
668682,
|
||
668680,
|
||
668679,
|
||
668678,
|
||
668672,
|
||
668666,
|
||
668662,
|
||
668660,
|
||
668659,
|
||
668656,
|
||
668655,
|
||
668654,
|
||
668649,
|
||
668648,
|
||
668643,
|
||
668642,
|
||
668640,
|
||
668636,
|
||
668632,
|
||
668631,
|
||
668629,
|
||
668624,
|
||
668616,
|
||
668613,
|
||
668608,
|
||
668594,
|
||
668548,
|
||
668543,
|
||
668540,
|
||
668537,
|
||
668530,
|
||
668512,
|
||
668258,
|
||
668257,
|
||
668256,
|
||
668254,
|
||
668203,
|
||
668190,
|
||
668186,
|
||
668185,
|
||
668182,
|
||
668170,
|
||
668169,
|
||
668168,
|
||
668166,
|
||
668165,
|
||
668164,
|
||
668157,
|
||
668156,
|
||
668125,
|
||
668121,
|
||
668095,
|
||
668094,
|
||
668071,
|
||
667959,
|
||
667745,
|
||
667744,
|
||
667743,
|
||
667563,
|
||
667562,
|
||
667561,
|
||
667560,
|
||
667559,
|
||
667558,
|
||
667556,
|
||
667420,
|
||
667332,
|
||
667308,
|
||
667305,
|
||
667304,
|
||
667299,
|
||
667292,
|
||
667285,
|
||
667281,
|
||
667278,
|
||
667263,
|
||
667001,
|
||
666975,
|
||
666677,
|
||
666667,
|
||
666666,
|
||
103408,
|
||
103184,
|
||
103174,
|
||
103127,
|
||
103113,
|
||
102925,
|
||
102740,
|
||
102736,
|
||
102630,
|
||
102383,
|
||
102180,
|
||
101942,
|
||
101897,
|
||
101875,
|
||
101036,
|
||
100840,
|
||
100743,
|
||
100654,
|
||
100471,
|
||
100144,
|
||
100135,
|
||
100129,
|
||
100126,
|
||
100123,
|
||
100115,
|
||
}
|
||
syncStoreSkuTao(hangzhou)
|
||
}, []string{
|
||
"18:50:00",
|
||
"20:50:00",
|
||
"22:28:00",
|
||
"00:50:00",
|
||
"02:50:00",
|
||
"04:50:00",
|
||
"06:50:00",
|
||
"08:50:00",
|
||
"10:50:00",
|
||
"12:50:00",
|
||
"14:50:00",
|
||
"16:50:00",
|
||
})
|
||
|
||
// 刷新抖音门店token
|
||
if beego.BConfig.RunMode != "jxgy" {
|
||
ScheduleTimerFuncByInterval(func() {
|
||
cms.RefreshTiktokShopToken(jxcontext.AdminCtx)
|
||
}, 60*time.Second, 30*time.Minute)
|
||
}
|
||
|
||
// 定时任务刷新当前订单的物流信息
|
||
ScheduleTimerFunc("RefreshMaterialLogistics", func() {
|
||
bidding.LoadingLogistics(nil)
|
||
}, []string{
|
||
"02:45:00",
|
||
})
|
||
|
||
//刷新京东物竞天择订单结算价
|
||
ScheduleTimerFunc("RefreshJdShopOrdersEarningPrice", func() {
|
||
orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, utils.Time2Str(time.Now().AddDate(0, 0, -2)), utils.Time2Str(time.Now().AddDate(0, 0, -2)))
|
||
orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, utils.Time2Str(time.Now().AddDate(0, 0, -1)), utils.Time2Str(time.Now().AddDate(0, 0, -1)))
|
||
}, []string{
|
||
"05:00:00",
|
||
})
|
||
//刷新京东售后单结算价
|
||
ScheduleTimerFunc("RefreshJdAfsOrderTotalShopMoney", func() {
|
||
orderman.RefreshJdAfsOrderTotalShopMoney()
|
||
}, []string{
|
||
"05:30:00",
|
||
})
|
||
|
||
ScheduleTimerFunc("auto enable remote store", func() {
|
||
cms.EnableHaveRestStores(jxcontext.AdminCtx, false, true)
|
||
// cms.OpenRemoteStoreByJxStatus(jxcontext.AdminCtx, nil, nil, false, false, true)
|
||
}, openRemoteStoreTimeList)
|
||
|
||
// ScheduleTimerFunc("SaveAndSendAlarmVendorSnapshot", func() {
|
||
// cms.SaveAndSendAlarmVendorSnapshot(jxcontext.AdminCtx, nil, nil, false)
|
||
// }, cms.WatchVendorStoreTimeList)
|
||
|
||
ScheduleTimerFunc("RefreshPageActs", func() {
|
||
act.RefreshPageActs(jxcontext.AdminCtx, []int{model.VendorIDEBAI}, time.Now().Add(-30*24*time.Hour), false)
|
||
}, refreshPageActTimeList)
|
||
ScheduleTimerFunc("UpdateActStatusByTime", func() {
|
||
dao.UpdateActStatusByTime(dao.GetDB(), time.Now())
|
||
}, updateActStatusTimeList)
|
||
ScheduleScoreStore()
|
||
// ScheduleCheckStoreAlert()
|
||
ScheduleTimerFunc("ChangeStoreSkuSaleStatus", func() {
|
||
cms.CurVendorSync.ChangeStoreSkuSaleStatus(jxcontext.AdminCtx, 0, true, true)
|
||
}, ChangeStoreSkuSaleStatusList)
|
||
ScheduleTimerFunc("BeginSavePriceRefer", func() {
|
||
report.BeginSavePriceRefer(jxcontext.AdminCtx, nil, nil, true, true)
|
||
}, priceReferTimeList)
|
||
ScheduleTimerFunc("CreateStorePriceScore", func() {
|
||
cms.CreateStorePriceScore(jxcontext.AdminCtx)
|
||
}, createStorePriceTimeList)
|
||
//ScheduleTimerFunc("AutoFocusStoreSkusForTopSkus", func() {
|
||
// cms.AutoFocusStoreSkusForTopSkus(jxcontext.AdminCtx, true, true)
|
||
//}, createStorePriceTimeList)
|
||
//ScheduleTimerFunc("GetCheckVendorCookie", func() {
|
||
// event.GetCheckVendorCookie(jxcontext.AdminCtx, []int{model.VendorIDEBAI, model.VendorIDJD, model.VendorIDMTWM, model.VendorIDMTPS, model.VendorIDJDShop}, true)
|
||
//}, checkCookieList)
|
||
//ScheduleTimerFunc("SendSeckillSkusCountMsg", func() {
|
||
// cms.SendSeckillSkusCountMsg(jxcontext.AdminCtx, []int{model.VendorIDEBAI, model.VendorIDJD, model.VendorIDMTWM}, false, true)
|
||
//}, sendSecKillWarnList)
|
||
// ScheduleTimerFunc("每日报警心跳", func() {
|
||
// globals.SugarLogger.Warnf("每日报警心跳,这不是报警。启动时间:%s", cms.GetServiceInfo(jxcontext.AdminCtx)["startupTime"])
|
||
// }, dailyHeartbeat)
|
||
ScheduleTimerFunc("AutoPayForPopluarMan", func() {
|
||
localjx.AutoPayForPopluarMan(jxcontext.AdminCtx)
|
||
}, autoPayForPopluarManList)
|
||
ScheduleTimerFunc("CancelPayTimeOutOrder", func() {
|
||
localjx.CancelPayTimeOutOrder(jxcontext.AdminCtx)
|
||
}, cancelPayTimeOutOrderList)
|
||
ScheduleTimerFunc("BackUpStoreSkuBind", func() {
|
||
cms.BackUpStoreSkuBind(jxcontext.AdminCtx, true, true)
|
||
}, backUpStoreSkuBindList)
|
||
// ScheduleTimerFunc("SendNoCatSkusToOperater", func() {
|
||
// cms.SendNoCatSkusToOperater(jxcontext.AdminCtx)
|
||
// }, autoPayForPopluarManList)
|
||
ScheduleTimerFunc("CleanStoreIsBoughtMatter", func() {
|
||
cms.CleanStoreIsBoughtMatter(jxcontext.AdminCtx)
|
||
}, priceReferTimeList)
|
||
ScheduleTimerFunc("CleanUserOrderSMSMark", func() {
|
||
cms.CleanUserOrderSMSMark(jxcontext.AdminCtx)
|
||
}, priceReferTimeList)
|
||
ScheduleTimerFunc("CreateOrderByPriceDefend", func() {
|
||
localjx.CreateOrderByPriceDefend(jxcontext.AdminCtx)
|
||
}, []string{
|
||
"22:00:00",
|
||
})
|
||
//ScheduleTimerFunc("ChangeJxPriceByDiscountAct", func() {
|
||
// act.ChangeJxPriceByDiscountAct(jxcontext.AdminCtx)
|
||
//}, discountActJxList)
|
||
ScheduleTimerFunc("RefreshUserMemberStatus", func() {
|
||
cms.RefreshUserMemberStatus(jxcontext.AdminCtx)
|
||
}, updateActStatusTimeList)
|
||
//刷优惠券状态
|
||
ScheduleTimerFunc("RefreshCouponsStatus", func() {
|
||
localjx.RefreshCouponsStatus(jxcontext.AdminCtx)
|
||
}, updateActStatusTimeList)
|
||
//刷新美团商超门店Token
|
||
ScheduleTimerFunc("RefreshMTWMToken", func() {
|
||
cms.RefreshMTWMToken(jxcontext.AdminCtx)
|
||
}, updateActStatusTimeList)
|
||
|
||
//获取最新平台流量活动
|
||
ScheduleTimerFunc("GetNewVendorPopActs", func() {
|
||
act.GetNewVendorPopActs(jxcontext.AdminCtx)
|
||
}, dailyHeartbeat)
|
||
//企业微信群人数通告(暂时取消)
|
||
//ScheduleTimerFunc("SendQywxPeopleCount", func() {
|
||
// cms.SendQywxPeopleCount(jxcontext.AdminCtx)
|
||
//}, dailyHeartbeat)
|
||
ScheduleTimerFunc("doDailyWork1", func() {
|
||
//同步商品额外前缀和水印图(打标记)
|
||
cms.SyncSkuExperfixAndWatermark(jxcontext.AdminCtx)
|
||
}, dailyWorkTimeList)
|
||
/*ScheduleTimerFunc("BuildFakeMatterOrder", func() {
|
||
orderman.BuildFakeMatterOrder()
|
||
}, []string{
|
||
"09:00:00",
|
||
"15:00:00",
|
||
"23:00:00",
|
||
})*/
|
||
ScheduleTimerFunc("doDailyWork2", func() {
|
||
//刷新京东会员
|
||
//report.RefreshJDMembers(jxcontext.AdminCtx)
|
||
cms.SetSingleStoreSkuSyncModifyStatus(dao.GetDB(), []int{1, 3})
|
||
cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, dao.GetDB(), []int{1, 3}, nil, false, nil, nil, model.SyncFlagSaleMask, true, true)
|
||
}, dailyWorkTimeList)
|
||
ScheduleTimerFunc("doDailyWork3", func() {
|
||
dao.SetStoresMapSyncStatus(dao.GetDB(), nil, nil, model.SyncFlagStoreStatus)
|
||
cms.CurVendorSync.SyncStore2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDMTWM, model.VendorIDJD, model.VendorIDEBAI, model.VendorIDDD}, nil, true, true)
|
||
|
||
syncStoreSku()
|
||
InitEx()
|
||
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||
}, dailyWorkTimeList)
|
||
ScheduleTimerFunc("doDailyWork4", func() {
|
||
curDate := utils.Time2Date(time.Now())
|
||
orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, []int{model.VendorIDJD, model.VendorIDMTWM, model.VendorIDEBAI, model.VendorIDDD}, 0, curDate.Add(-72*time.Hour), curDate, true, true)
|
||
//只传toDate默认刷新toDate到5天以前的订单
|
||
orderman.RefreshOrdersWithoutJxStoreID(jxcontext.AdminCtx, "", "", true, true)
|
||
//禁用没有绑定的门店
|
||
cms.DisabledStoreWithoutVendor(jxcontext.AdminCtx, true, true)
|
||
}, dailyWorkTimeList)
|
||
ScheduleTimerFunc("doDailyWork5", func() {
|
||
//刷新物料订单状态
|
||
localjx.RefreshAllMatterOrderStatus(jxcontext.AdminCtx)
|
||
//同步美团配送与否状态及美团门店是否存在
|
||
//cms.SetMTPSStatus(jxcontext.AdminCtx, 0, 0)
|
||
cms.SetMTPSStatus2(0)
|
||
//售后单如果超过12小时没有审核,就自动通过
|
||
//RefreshAfsOrderStatusAccess(jxcontext.AdminCtx)
|
||
//刷新门店分组管理
|
||
cms.RefreshStoreBind(jxcontext.AdminCtx)
|
||
//更新所有门店的上下线状态
|
||
cms.RefreshStoreIsOnline(jxcontext.AdminCtx)
|
||
}, dailyWorkTimeList)
|
||
ScheduleTimerFunc("RrefreshMtwmVendorAct", func() {
|
||
//刷新美团平台活动
|
||
act.RrefreshMtwmVendorAct(jxcontext.AdminCtx)
|
||
//刷新饿百平台活动
|
||
act.RrefreshEbaiVendorAct(jxcontext.AdminCtx)
|
||
}, dailyWorkTimeList2)
|
||
// 轮询每天更新当前时间一个月
|
||
ScheduleTimerFunc("UpdateOrder2Complete", func() {
|
||
delivery.UpdateOrder2Complete()
|
||
}, []string{
|
||
"04:00:00",
|
||
})
|
||
}
|
||
//update xuhang 2022/04/06用于同步京东数据以取代爬取订单 但由于京东的v2API已不支持手机号 因此以下代码暂时注释 后续接入虚拟号可再次open
|
||
/* ScheduleTimerFuncByInterval(func() {
|
||
jdshop.InitKey()
|
||
}, 10*time.Second, 8*time.Hour)*/
|
||
//此处需要新增一个message 存储操作 服务器启动的30s后开始执行 每10s刷新一次
|
||
//进行一个JCQ队列定时任务执行
|
||
/* ScheduleTimerFuncByInterval(func() {
|
||
jcq.JCQSchedule()
|
||
}, 10*time.Second, 10*time.Second)*/
|
||
//ScheduleTimerFuncByInterval(func() {
|
||
// jdslogin.RefreshQRCode()
|
||
//}, 10*time.Second, 10*time.Minute)
|
||
ScheduleTimerFunc("AutoSaleStoreSku", func() {
|
||
cms.AutoSaleStoreSku(jxcontext.AdminCtx, nil, false)
|
||
}, autoSaleStoreSkuTimeList)
|
||
|
||
if beego.BConfig.RunMode == "jxgy" {
|
||
ScheduleTimerFunc("SyncMatterC4ToGy", func() {
|
||
cms.SyncMatterC4ToGy(jxcontext.AdminCtx, true, true)
|
||
}, dailyWorkTimeList)
|
||
}
|
||
if beego.BConfig.RunMode == "beta" {
|
||
//ScheduleTimerFunc("CancelPayTimeOutOrder", func() {
|
||
// localjx.CancelPayTimeOutOrder(jxcontext.AdminCtx)
|
||
//}, cancelPayTimeOutOrderList)
|
||
ScheduleTimerFunc("GetAndStoreCitiesShops", func() {
|
||
netspider.GetAndStoreCitiesShops(jxcontext.AdminCtx, nil, nil, 0, 0, false, false)
|
||
}, []string{
|
||
"04:05:06",
|
||
})
|
||
//京东的订单信息解密密钥获取
|
||
//ScheduleTimerFuncByInterval(func() {
|
||
// jdshop.InitKey()
|
||
//}, 10*time.Second, 8*time.Hour)
|
||
ScheduleTimerFunc("ChangeJxPriceByDiscountAct", func() {
|
||
act.ChangeJxPriceByDiscountAct(jxcontext.AdminCtx)
|
||
}, discountActJxList)
|
||
//ScheduleTimerFunc("CreateOrderByPriceDefend", func() {
|
||
// localjx.CreateOrderByPriceDefend(jxcontext.AdminCtx)
|
||
//}, []string{
|
||
// "22:00:00",
|
||
//})
|
||
//刷新门店数据坐标等
|
||
ScheduleTimerFunc("RefreshPageStore", func() {
|
||
cms.RefreshPageStore()
|
||
}, []string{
|
||
"20:00:00",
|
||
})
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "ebaiStorePageCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
ebaiStorePageCookie = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtwmCookieStr", model.ConfigTypeCookie, ""); err == nil {
|
||
mtwmCookieStr = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "mtpsStoreToken", model.ConfigTypeCookie, ""); err == nil {
|
||
mtpsStoreToken = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdStorePageCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
JdStorePageCookie = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "jdStorePageEarning", model.ConfigTypeCookie, ""); err == nil {
|
||
jdStorePageEarning = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "jd2StorePageCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
jd2StorePageCookie = configs[0].Value
|
||
}
|
||
if configs, err := dao.QueryConfigs(dao.GetDB(), "feiePageCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
feiePageCookie = configs[0].Value
|
||
}
|
||
//if configs, err := dao.QueryConfigs(dao.GetDB(), "jdsCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
// jdsCookie = configs[0].Value
|
||
// api.JdShopAPI.SetCookieWithStr(jdsCookie)
|
||
//}
|
||
//if configs, err := dao.QueryConfigs(dao.GetDB(), "yinbaoCookie", model.ConfigTypeCookie, ""); err == nil {
|
||
// yinbaoCookie := configs[0].Value
|
||
// api.YinBaoAPI.SetCookie(".POSPALAUTH30220", yinbaoCookie)
|
||
//}
|
||
if globals.Jd2OrgCode != "" {
|
||
api.Jd2API.SetJdCookie(jd2StorePageCookie)
|
||
}
|
||
//api.EbaiAPI.SetCookie("PASSPORT_DELIMONT_TOKEN", ebaiStorePageCookieExdTOKEN)
|
||
//api.EbaiAPI.SetCookie("WMUSS", ebaiStorePageCookieWMUSS)
|
||
//api.EbaiAPI.SetCookie("WMSTOKEN", ebaiStorePageCookieWMSTOKEN)
|
||
//api.Ebai2API.SetCookie("PASSPORT_DELIMONT_TOKEN", ebaiStorePageCookieExdTOKEN)
|
||
//api.Ebai2API.SetCookie("WMUSS", ebaiStorePageCookieWMUSS2)
|
||
//api.Ebai2API.SetCookie("WMSTOKEN", ebaiStorePageCookieWMSTOKEN2)
|
||
api.EbaiAPI.SetCookieWithStr(ebaiStorePageCookie)
|
||
api.MtwmAPI.SetCookieWithStr(mtwmCookieStr)
|
||
api.MtpsAPI.SetCookie("token", mtpsStoreToken)
|
||
//api.JdAPI.SetJdCookie(JdStorePageCookie)
|
||
api.JdAPI.SetCookieWithStr(JdStorePageCookie)
|
||
api.JdAPI.SetCookie("user", jdStorePageEarning)
|
||
api.JdPageAPI.SetCookie(jdapi.AccessStorePageCookieName, JdStorePageCookie)
|
||
api.JdPageAPI.SetCookie(jdapi.AccessStorePageCookieName2, JdStorePageCookie)
|
||
api.FeieAPI.SetCookieWithStr(feiePageCookie)
|
||
}
|
||
|
||
func syncStoreSku() {
|
||
syncFlag := 0
|
||
if beego.BConfig.RunMode == "jxgy" {
|
||
//syncFlag = model.SyncFlagPriceMask
|
||
if true {
|
||
syncFlag |= model.SyncFlagSaleMask
|
||
}
|
||
} else {
|
||
syncFlag |= model.SyncFlagSaleMask
|
||
}
|
||
task := tasksch.NewParallelTask("同步京西与平台数据", nil, jxcontext.AdminCtx,
|
||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||
step := batchItemList[0].(int)
|
||
errList := errlist.New()
|
||
db := dao.GetDB()
|
||
switch step {
|
||
case 0:
|
||
if beego.BConfig.RunMode != "jxgy" {
|
||
errList.AddErr(cms.DeleteSkuNameExPrefixOverdue(db))
|
||
errList.AddErr(cms.SetMultiStoreSkuSyncModifyStatus(db, partner.GetMultiStoreVendorIDs()))
|
||
|
||
_, err = cms.CurVendorSync.LoopMultiStoresVendors(jxcontext.AdminCtx, db, "同步多门店平台商品库", false, true,
|
||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||
vendorInfo := batchItemList[0].(*cms.MultiStoreVendorInfo)
|
||
_, err = cms.FullSyncVendorStuff(jxcontext.AdminCtx, task, 0, vendorInfo.VendorID, vendorInfo.OrgCode, false, true)
|
||
return retVal, err
|
||
})
|
||
errList.AddErr(err)
|
||
|
||
_, err = cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{0}, nil, false, nil, []int{27379}, syncFlag, true, true)
|
||
//_, err = cms.CurVendorSync.FullSyncStoresSkus(jxcontext.AdminCtx, db, partner.GetMultiStoreVendorIDs(), nil, false, []int{27379}, true, true)
|
||
errList.AddErr(err)
|
||
}
|
||
case 1:
|
||
//TODO 暂时不同步银豹(可能要从银豹到京西),2020-04-27
|
||
//errList.AddErr(cms.SetSingleStoreSkuSyncModifyStatus(db, []int{1, 3}))
|
||
|
||
// errList.AddErr(cms.SetSingleStoreSkuSyncModifyStatus(db, partner.GetSingleStoreVendorIDs()))
|
||
// _, err = cms.CurVendorSync.AmendAndPruneStoreStuff(jxcontext.AdminCtx, []int{1, 3}, nil, false, true, cms.AmendPruneAll, false)
|
||
|
||
// _, err = cms.CurVendorSync.AmendAndPruneStoreStuff(jxcontext.AdminCtx, partner.GetSingleStoreVendorIDs(), nil, false, true, cms.AmendPruneAll, false)
|
||
errList.AddErr(err)
|
||
|
||
SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID)
|
||
//taskID, err2 := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{1, 3}, nil, false, nil, nil, syncFlag, true, true)
|
||
// taskID, err2 := cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, partner.GetSingleStoreVendorIDs(), nil, false, nil, nil, syncFlag, true, true)
|
||
|
||
//errList.AddErr(err2)
|
||
//SaveImportantTaskID(TaskNameSyncStoreSku, taskID)
|
||
}
|
||
err = errList.GetErrListAsOne()
|
||
return retVal, err
|
||
}, []int{0, 1})
|
||
tasksch.HandleTask(task, nil, true).Run()
|
||
}
|
||
|
||
func syncStoreSkuTiktok() {
|
||
//syncFlag := 0 | model.SyncFlagSaleMask
|
||
syncFlag := 0
|
||
task := tasksch.NewParallelTask("同步京西商品到抖音平台,方案二使用", nil, jxcontext.AdminCtx,
|
||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||
step := batchItemList[0].(int)
|
||
errList := errlist.New()
|
||
db := dao.GetDB()
|
||
switch step {
|
||
case 0:
|
||
if beego.BConfig.RunMode != "jxgy" {
|
||
_, err = cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{model.VendorIDDD}, nil, false, nil, nil, syncFlag, true, true)
|
||
errList.AddErr(err)
|
||
}
|
||
case 1:
|
||
errList.AddErr(err)
|
||
SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID)
|
||
}
|
||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "抖音同步商品", utils.Format4Output(errList, false))
|
||
err = errList.GetErrListAsOne()
|
||
return retVal, err
|
||
}, []int{0, 1})
|
||
tasksch.HandleTask(task, nil, true).Run()
|
||
}
|
||
|
||
var syncLen = 0
|
||
|
||
// syncStoreSkuTao 同步商品到淘鲜达
|
||
func syncStoreSkuTao(beijin []int) {
|
||
syncFlag := 0
|
||
globals.SugarLogger.Debugf("===========beijin %s", utils.Format4Output(beijin, false))
|
||
task := tasksch.NewParallelTask("同步京西商品到淘鲜达平台,方案二使用", nil, jxcontext.AdminCtx,
|
||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||
step := batchItemList[0].(int)
|
||
errList := errlist.New()
|
||
db := dao.GetDB()
|
||
switch step {
|
||
case 0:
|
||
globals.SugarLogger.Debugf("===========beijin %s", utils.Format4Output(beijin, false))
|
||
ddmsg.SendUserMessage(dingdingapi.MsgTyeText, "2452A93EEB9111EC9B06525400E86DC0", "淘鲜达消息:", utils.Format4Output(beijin[syncLen:syncLen+5], false))
|
||
_, err = cms.CurVendorSync.SyncStoresSkus2(jxcontext.AdminCtx, nil, 0, db, []int{model.VendorIDTaoVegetable}, beijin[syncLen:syncLen+5], false, nil, nil, syncFlag, true, true)
|
||
errList.AddErr(err)
|
||
case 1:
|
||
errList.AddErr(err)
|
||
SaveImportantTaskID(TaskNameSyncStoreSku, SpecialTaskID)
|
||
}
|
||
err = errList.GetErrListAsOne()
|
||
return retVal, err
|
||
}, []int{0, 1})
|
||
tasksch.HandleTask(task, nil, true).Run()
|
||
syncLen += 5
|
||
}
|
||
|
||
func doDailyWork2() {
|
||
if beego.BConfig.RunMode == "jxgy" {
|
||
syncStoreSku()
|
||
refreshPointOrderNewEarningPrice()
|
||
}
|
||
//同步京东商城门店的商品
|
||
// cms.CurVendorSync.SyncJdsStoresSkus(jxcontext.AdminCtx, nil, true, true)
|
||
//刷新京东商城的门店库存
|
||
// cms.SyncJdsStoreStock(jxcontext.AdminCtx, true, true)
|
||
}
|
||
|
||
func doDailyWork() {
|
||
//同步商品额外前缀和水印图(打标记)
|
||
cms.SyncSkuExperfixAndWatermark(jxcontext.AdminCtx)
|
||
|
||
dao.SetStoresMapSyncStatus(dao.GetDB(), nil, nil, model.SyncFlagStoreStatus)
|
||
cms.CurVendorSync.SyncStore2(jxcontext.AdminCtx, dao.GetDB(), []int{model.VendorIDMTWM, model.VendorIDJD, model.VendorIDEBAI}, nil, true, true)
|
||
|
||
if beego.BConfig.RunMode == "prod" {
|
||
syncStoreSku()
|
||
}
|
||
InitEx()
|
||
cms.SyncStoresCourierInfo(jxcontext.AdminCtx, nil, false, true)
|
||
netprinter.RebindAllPrinters(jxcontext.AdminCtx, false, true)
|
||
|
||
// 每天补全前一天与当天的订单
|
||
// curDate := utils.Time2Date(time.Now())
|
||
// orderman.FixedOrderManager.AmendMissingOrders(jxcontext.AdminCtx, nil, 0, curDate.Add(-72*time.Hour), curDate, true, true)
|
||
//订单门店归属补漏
|
||
//fromDate, toDate都不传默认刷新当前天5天以前的订单,只传fromDate默认刷新fromDate到当天的订单
|
||
//只传toDate默认刷新toDate到5天以前的订单
|
||
orderman.RefreshOrdersWithoutJxStoreID(jxcontext.AdminCtx, "", "", true, true)
|
||
//刷新京东门店的等级
|
||
// cms.RefreshJdLevel(jxcontext.AdminCtx)
|
||
//删除操作日志
|
||
// event.DeleteOperateEventAndDetail(jxcontext.AdminCtx, time.Now().AddDate(0, -3, 0))
|
||
//禁用没有绑定的门店
|
||
cms.DisabledStoreWithoutVendor(jxcontext.AdminCtx, true, true)
|
||
//刷新物料订单状态
|
||
localjx.RefreshAllMatterOrderStatus(jxcontext.AdminCtx)
|
||
//同步银豹到京西
|
||
// cms.CurVendorSync.SyncStoreSkusFromYb(jxcontext.AdminCtx, nil, true, true)
|
||
//同步上架京东商城待售商品
|
||
// cms.RefreshJdsSkusStatus(jxcontext.AdminCtx)
|
||
//同步美团配送与否状态及美团门店是否存在
|
||
cms.SetMTPSStatus(jxcontext.AdminCtx, 0, 0)
|
||
//售后单如果超过12小时没有审核,就自动通过
|
||
//RefreshAfsOrderStatusAccess(jxcontext.AdminCtx)
|
||
//刷新京东商城订单结算价
|
||
orderman.RefreshJdShopOrdersEarningPrice(jxcontext.AdminCtx, utils.Time2Str(time.Now().AddDate(0, 0, -2)), utils.Time2Str(time.Now()))
|
||
//刷新门店分组管理
|
||
cms.RefreshStoreBind(jxcontext.AdminCtx)
|
||
//刷新京东会员
|
||
report.RefreshJDMembers(jxcontext.AdminCtx)
|
||
}
|
||
|
||
func refreshPointOrderNewEarningPrice() {
|
||
var (
|
||
db = dao.GetDB()
|
||
orders []*model.GoodsOrder
|
||
)
|
||
sql := `
|
||
SELECT * FROM goods_order WHERE earning_type = 2 AND status = 110 AND order_created_at > ?
|
||
`
|
||
sqlParams := []interface{}{time.Now().AddDate(0, 0, -1)}
|
||
dao.GetRows(db, &orders, sql, sqlParams)
|
||
if len(orders) > 0 {
|
||
for _, v := range orders {
|
||
if v.NewEarningPrice == 0 {
|
||
v.NewEarningPrice = int64(int(v.TotalShopMoney) * (100 - v.OrderPayPercentage/2) / 100)
|
||
dao.UpdateEntity(db, v, "NewEarningPrice")
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
//func RefreshAfsOrderStatusAccess(ctx *jxcontext.Context) {
|
||
// var (
|
||
// offset = 0
|
||
// pageSize = 9999
|
||
// db = dao.GetDB()
|
||
// )
|
||
// afsOrderList, _, err := dao.GetAfsOrdersByPage(db, "", "", "", time.Now().AddDate(0, 0, -7), time.Now(), offset, pageSize)
|
||
// if err != nil {
|
||
// return
|
||
// }
|
||
// for _, v := range afsOrderList {
|
||
// if v.Status == model.AfsOrderStatusWait4Approve && time.Now().Sub(v.AfsCreatedAt).Hours() > 12 {
|
||
// defsch.FixedScheduler.AgreeOrRefuseRefund(ctx, v.AfsOrderID, v.VendorID, model.AfsTypePartRefund, "超时系统同意")
|
||
// }
|
||
// }
|
||
//}
|
||
|
||
func RefreshRealMobile(ctx *jxcontext.Context, vendorID int, fromTime, toTime time.Time, isAsync, isContinueWhenError bool) (hint string, err error) {
|
||
handler := partner.GetPurchasePlatformFromVendorID(vendorID)
|
||
if handler == nil {
|
||
return "", fmt.Errorf("不合法的vendorID:%d", vendorID)
|
||
}
|
||
sql := `
|
||
SELECT *
|
||
FROM goods_order
|
||
WHERE vendor_id = ? AND consignee_mobile2 = ''
|
||
`
|
||
sqlParams := []interface{}{
|
||
vendorID,
|
||
}
|
||
if !utils.IsTimeZero(fromTime) {
|
||
sql += " AND order_created_at >= ?"
|
||
sqlParams = append(sqlParams, fromTime)
|
||
}
|
||
if !utils.IsTimeZero(toTime) {
|
||
sql += " AND order_created_at <= ?"
|
||
sqlParams = append(sqlParams, toTime)
|
||
}
|
||
var orderList []*model.GoodsOrder
|
||
db := dao.GetDB()
|
||
if err = dao.GetRows(db, &orderList, sql, sqlParams...); err == nil && len(orderList) > 0 {
|
||
task := tasksch.NewParallelTask("misc RefreshRealMobile", tasksch.NewParallelConfig().SetIsContinueWhenError(isContinueWhenError), ctx,
|
||
func(task *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) {
|
||
order := batchItemList[0].(*model.GoodsOrder)
|
||
mobile, err2 := handler.GetOrderRealMobile(ctx, order)
|
||
if err = err2; err == nil {
|
||
//mobile = jxutils.FormalizeMobile(mobile)
|
||
//if jxutils.IsStringLikeMobile(mobile) && strings.Index(order.ConsigneeMobile, mobile) == -1 {
|
||
order.ConsigneeMobile2 = mobile
|
||
_, err = dao.UpdateEntity(db, order, "ConsigneeMobile2")
|
||
//}
|
||
} else {
|
||
globals.SugarLogger.Infof("RefreshRealMobile orderID:%s failed with error:%v", order.VendorOrderID, err)
|
||
}
|
||
return nil, err
|
||
}, orderList)
|
||
tasksch.HandleTask(task, nil, true).Run()
|
||
hint = task.ID
|
||
if !isAsync {
|
||
_, err = task.GetResult(0)
|
||
}
|
||
}
|
||
return hint, err
|
||
}
|
||
|
||
// 按时间序列循环
|
||
func ScheduleTimerFunc(name string, handler func(), timeList []string) {
|
||
now := time.Now()
|
||
nextTime := jxutils.GetNextTimeFromList(now, timeList)
|
||
duration := nextTime.Sub(now) + 1*time.Second
|
||
utils.AfterFuncWithRecover(duration, func() {
|
||
handler()
|
||
ScheduleTimerFunc(name, handler, timeList)
|
||
})
|
||
}
|
||
|
||
// 按时间调度一次
|
||
func ScheduleTimerFuncOnce(name string, handler func(interface{}), timeStr string, param interface{}) {
|
||
now := time.Now()
|
||
nextTime := jxutils.GetNextTimeFromList(now, []string{timeStr})
|
||
duration := nextTime.Sub(now) + 1*time.Second
|
||
utils.AfterFuncWithRecover(duration, func() {
|
||
handler(param)
|
||
})
|
||
}
|
||
|
||
func ScheduleTimerFuncByInterval(handler func(), delay, inerval time.Duration) {
|
||
utils.AfterFuncWithRecover(delay, func() {
|
||
beginTime := time.Now()
|
||
handler()
|
||
delay = inerval - time.Now().Sub(beginTime)
|
||
if delay < time.Second {
|
||
delay = time.Second
|
||
}
|
||
ScheduleTimerFuncByInterval(handler, delay, inerval)
|
||
})
|
||
}
|