diff --git a/app/task/init.go b/app/task/init.go index ab33f6c..f8c505d 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -83,7 +83,11 @@ func doTask(fnName string) func() { // 增加自动任务队列 func initTasks() { - jobs[taskMd.ZhimengCronTikTokChanxuan] = taskTikTokCsjpChanxuan // + jobs[taskMd.ZhimengCronTikTokChanxuan] = taskTikTokCsjpChanxuan // + jobs[taskMd.ZhimengCronAli1688] = taskAli1688 // + jobs[taskMd.ZhimengCronAli1688ConfirmTime] = taskAli1688ConfirmTime // + jobs[taskMd.ZhimengCronAli1688SettleTime] = taskAli1688SettleTime // + jobs[taskMd.ZhimengCronAli1688RightsEndTime] = taskAli1688RightsEndTime // jobs[taskMd.ZhimengCronWphOrder] = taskWphOrder // jobs[taskMd.ZhimengCronWphRefundOrder] = taskWphRefundOrder // diff --git a/app/task/md/cron_key.go b/app/task/md/cron_key.go index b0435b4..947af38 100644 --- a/app/task/md/cron_key.go +++ b/app/task/md/cron_key.go @@ -4,6 +4,10 @@ const ( ZhimengCronTikTokTaskRelate = "zhimeng_cron_tik_tok_relate" ZhimengCronTikTokCsjp = "zhimeng_cron_tik_tok_csjp" ZhimengCronTikTokChanxuan = "zhimeng_cron_tik_tok_chanxuan" + ZhimengCronAli1688 = "zhimeng_cron_ali1688" + ZhimengCronAli1688ConfirmTime = "zhimeng_cron_ali1688_ConfirmTime" + ZhimengCronAli1688SettleTime = "zhimeng_cron_ali1688_SettleTime" + ZhimengCronAli1688RightsEndTime = "zhimeng_cron_ali1688_RightsEndTime" ZhimengCronTikTokChanxuanPay = "zhimeng_cron_tik_tok_chanxuan_pay" ZhimengCronTikTokChanxuanSettle = "zhimeng_cron_tik_tok_chanxuan_settle" ZhimengCronCinema5bms = "zhimeng_cron_cinema5bms" diff --git a/app/task/svc/svc_ali1688_order.go b/app/task/svc/svc_ali1688_order.go new file mode 100644 index 0000000..f74f259 --- /dev/null +++ b/app/task/svc/svc_ali1688_order.go @@ -0,0 +1,123 @@ +package svc + +import ( + "applet/app/cfg" + "applet/app/db" + "applet/app/db/model" + offical "applet/app/db/official" + "applet/app/utils" + "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/thirdParty/ali1688" + "fmt" + "github.com/tidwall/gjson" + "strings" + "time" +) + +func Ali1688Order(timeType string) { + var ( + beginTime int64 = 0 + endTime int64 = 0 + pageNo int = 1 + pageSize int = 50 + ) + today := utils.GetTimeRange("today") + beginTime = today["start"] + endTime = today["end"] + unionData := offical.SysCfgByKeyStr("ali1688_data") + for { + count := 0 + count, _ = OrdersAli1688Get(pageNo, pageSize, beginTime, endTime, timeType, 1, unionData) + if count == 0 { + break + } + // 判断是否分页已经全部取完了 + if count <= pageSize { + pageNo++ + fmt.Println("========下一页========" + utils.IntToStr(pageNo)) + count = 0 + continue + } + } + return +} + +func OrdersAli1688Get(p int, pageSize int, sTime, eTime int64, timeType string, pvd int, unionData string) (int, string) { + args := map[string]string{ + "queryOrderType": "orderAll", + "queryStartTime": time.Unix(sTime, 0).Format("2006-01-02"), + "queryEndTime": time.Unix(eTime, 0).Format("2006-01-02"), + "pageNo": utils.IntToStr(p), + "pageSize": utils.IntToStr(pageSize), + "queryTimeType": timeType, + } + key := gjson.Get(unionData, "key").String() + secret := gjson.Get(unionData, "secret").String() + token := gjson.Get(unionData, "token").String() + order := ali1688.AliGoodsOrder(key, secret, token, args) + if order == nil || len(order) == 0 { + return 0, "" + } + count := len(order) + stateArr := map[int]string{ + 20: "订单付款", + 50: "订单完成", + 80: "订单失败", + } + for _, v := range order { + if v.OrderState == 10 { + continue + } + status := stateArr[v.OrderState] + ex := strings.Split(v.Ext, "_") + if strings.Contains(utils.AnyToString(v.Ext), "zhiying") == false { + continue + } + if strings.Contains(utils.AnyToString(v.Ext), "dev") && cfg.Prd { + continue + } + if strings.Contains(utils.AnyToString(v.Ext), "prd") && cfg.Prd == false { + continue + } + var ord = &model.GuideOrder{ + Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[3]))), + Uid: utils.StrToInt(ex[2]), + StationUid: utils.StrToInt(ex[3]), + PvdOid: utils.Int64ToStr(v.BizSubId), + Status: status, + UpdateTime: int(time.Now().Unix()), + Title: utils.AnyToString(v.Name), + Payment: utils.Float64ToStr(v.TradeAmount), + Pvd: "ali1688", + IsShare: utils.StrToInt(ex[4]), + ThreeType: "ali1688", + PvdParentOid: utils.Int64ToStr(v.BizId), + CreateTime: int(utils.TimeStdParseUnix(v.CreateTime)), + } + if v.SettleState == 1 { + ord.Status = "订单结算" + ord.PlatformSettleTime = int(utils.TimeStdParseUnix(v.SettleTime)) + } + if v.RightsState == 30 { + ord.Status = "订单失败" + } + ord.Commission = utils.Float64ToStr(v.Commission) + ord.RealCommission = utils.Float64ToStr(v.Commission) + one := db.GetGuideOrderByOid(utils.AnyToString(v.BizSubId), "ali1688") + if one == nil { + insertOne, err := db.ZhimengDb.InsertOne(ord) + fmt.Println(insertOne) + fmt.Println(err) + } else { + ord.SettleTime = one.SettleTime + if one.PlatformSettleTime > 0 { + ord.PlatformSettleTime = one.PlatformSettleTime + } + if one.Status == "违规订单" { + ord.Status = "违规订单" + } + db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) + } + + } + return count, "" +} diff --git a/app/task/task_ali1688.go b/app/task/task_ali1688.go new file mode 100644 index 0000000..a2f5121 --- /dev/null +++ b/app/task/task_ali1688.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskAli1688() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.Ali1688Order("gmtCreateTime") + <-ch +} diff --git a/app/task/task_ali1688_ConfirmTime.go b/app/task/task_ali1688_ConfirmTime.go new file mode 100644 index 0000000..a4a03ba --- /dev/null +++ b/app/task/task_ali1688_ConfirmTime.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskAli1688ConfirmTime() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.Ali1688Order("confirmTime") + <-ch +} diff --git a/app/task/task_ali1688_RightsEndTime.go b/app/task/task_ali1688_RightsEndTime.go new file mode 100644 index 0000000..fb70327 --- /dev/null +++ b/app/task/task_ali1688_RightsEndTime.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskAli1688RightsEndTime() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.Ali1688Order("rightsEndTime") + <-ch +} diff --git a/app/task/task_ali1688_SettleTime.go b/app/task/task_ali1688_SettleTime.go new file mode 100644 index 0000000..e58d4c5 --- /dev/null +++ b/app/task/task_ali1688_SettleTime.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskAli1688SettleTime() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.Ali1688Order("settleTime") + <-ch +}