From e205ad1f19de4f393e026e8023e66a9a290cda5a Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 14 Jul 2025 10:46:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/task/init.go | 3 + app/task/md/cron_key.go | 2 + app/task/svc/svc_haodanku_tongcheng.go | 213 +++++++++++++++++++++++++ app/task/svc/svc_haodanku_xianyu.go | 212 ++++++++++++++++++++++++ app/task/task_haodanku_tongcheng.go | 21 +++ app/task/task_haodanku_xianyu.go | 21 +++ go.mod | 2 +- 7 files changed, 473 insertions(+), 1 deletion(-) create mode 100644 app/task/svc/svc_haodanku_tongcheng.go create mode 100644 app/task/svc/svc_haodanku_xianyu.go create mode 100644 app/task/task_haodanku_tongcheng.go create mode 100644 app/task/task_haodanku_xianyu.go diff --git a/app/task/init.go b/app/task/init.go index f8c505d..bdeb64c 100644 --- a/app/task/init.go +++ b/app/task/init.go @@ -83,6 +83,9 @@ func doTask(fnName string) func() { // 增加自动任务队列 func initTasks() { + + jobs[taskMd.ZhimengCronHandankuTongcheng] = taskHandankuTongcheng // + jobs[taskMd.ZhimengCronHandankuXianyu] = taskHandankuXianyu // jobs[taskMd.ZhimengCronTikTokChanxuan] = taskTikTokCsjpChanxuan // jobs[taskMd.ZhimengCronAli1688] = taskAli1688 // jobs[taskMd.ZhimengCronAli1688ConfirmTime] = taskAli1688ConfirmTime // diff --git a/app/task/md/cron_key.go b/app/task/md/cron_key.go index 947af38..e6d662d 100644 --- a/app/task/md/cron_key.go +++ b/app/task/md/cron_key.go @@ -4,6 +4,8 @@ const ( ZhimengCronTikTokTaskRelate = "zhimeng_cron_tik_tok_relate" ZhimengCronTikTokCsjp = "zhimeng_cron_tik_tok_csjp" ZhimengCronTikTokChanxuan = "zhimeng_cron_tik_tok_chanxuan" + ZhimengCronHandankuTongcheng = "zhimeng_cron_haodanku_tongcheng" + ZhimengCronHandankuXianyu = "zhimeng_cron_haodanku_xianyu" ZhimengCronAli1688 = "zhimeng_cron_ali1688" ZhimengCronAli1688ConfirmTime = "zhimeng_cron_ali1688_ConfirmTime" ZhimengCronAli1688SettleTime = "zhimeng_cron_ali1688_SettleTime" diff --git a/app/task/svc/svc_haodanku_tongcheng.go b/app/task/svc/svc_haodanku_tongcheng.go new file mode 100644 index 0000000..2ccf2ba --- /dev/null +++ b/app/task/svc/svc_haodanku_tongcheng.go @@ -0,0 +1,213 @@ +package svc + +import ( + "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/haodanku" + "fmt" + "strings" + "time" +) + +func HandankuTongcheng() { + pvdTimeKey := "haodanku_tongcheng_time" + + // 获得最后时间 + latest := offical.SysCfgByKey(pvdTimeKey) + if latest == nil { + offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String()) + latest = offical.SysCfgByKey(pvdTimeKey) + } + // 所有时间都是在操作秒数 + now := time.Now().Unix() + timeStr := latest.V + fmt.Println(timeStr) + past := utils.TimeParseStd(timeStr).Unix() + // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟 + if past > now { + past = now + } + var ( + beginTime int64 = 0 + endTime int64 = 0 + pageNo int = 1 + pageSize int = 50 + ) + + //怕时间不是走最新的 + leave := now - past + if leave > 500 { + leave = 0 + } + past = past + leave + beginTime = past - 20*60 + endTime = past + + if endTime > now { + endTime = now + } + for { + var err error + count := OrdersHaodankuTongchengGet(pageNo, pageSize, beginTime, endTime) + if err != nil || count == 0 { + goto ChkArg + } + if count > 0 { + count = pageSize + } + // 判断是否分页已经全部取完了 + if count == pageSize { + pageNo++ + fmt.Println("========蝉选下一页========" + utils.IntToStr(pageNo)) + continue + } + ChkArg: + // 查询完后重置时间, 最后查询时间 + if endTime < now { + pageNo = 1 + offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) + beginTime = endTime + endTime = endTime + 20*60 + if endTime > now { + endTime = now + } + continue + } + break + } + offical.DbsSysCfgUpdate(pvdTimeKey, time.Unix(now, 0).Format("2006-01-02 15:04:05")) + +} + +var haodankuStationState = map[string]string{ + "1": "订单付款", + "3": "订单退款", + "2": "订单成功", +} + +func OrdersHaodankuTongchengGet(page, pageSize int, sTime, eTime int64) int { + tikTokArgs := map[string]string{ + "date_type": "4", + "back": utils.IntToStr(pageSize), + "min_id": utils.IntToStr(page), + "start_date": utils.Int64ToStr(time.Unix(sTime, 0).Unix()), + "end_date": utils.Int64ToStr(time.Unix(eTime, 0).Unix()), + } + order := haodanku.HaodankuTontchengOrder(tikTokArgs) + for _, v := range order { + if v.ChannelCode == "" { + continue + } + isShare := 0 + if strings.Contains(v.ChannelCode, "s") { + isShare = 1 + } + v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "o", "") + v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "s", "") + ex := strings.Split(v.ChannelCode, "u") + if len(ex) != 2 { + continue + } + mid := "" + uid := "" + one := db.GetLifeOrderByOne1(utils.AnyToString(v.TradeId), "tongcheng") + if one != nil { + isShare = one.IsShare + mid = utils.IntToStr(one.Uid) + uid = utils.IntToStr(one.StationUid) + } else { + mid = ex[0] + uid = ex[1] + } + if mid == "" || uid == "" { + continue + } + var ord = &model.LifeOrder{ + Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))), + Uid: utils.StrToInt(mid), + StationUid: utils.StrToInt(uid), + PvdOid: utils.AnyToString(v.TradeId), + PvdParentOid: v.TradeParentId, + Status: haodankuStationState[v.OrderStatus], + UpdateTime: int(time.Now().Unix()), + Commission: v.PredictMoney, + Title: utils.AnyToString(v.ShopName), + Payment: v.PayPrice, + Pvd: "tongcheng", + Img: "", + IsShare: isShare, + Gid: v.TradeId, + } + if v.CreateTime != "" { + ord.CreateTime = int(utils.TimeStdParseUnix(v.CreateTime)) + } + if v.EarningTime != "" { + ord.PlatformSettleTime = int(utils.TimeStdParseUnix(utils.AnyToString(v.EarningTime))) + } + if utils.StrToFloat64(v.ActualMoney) > 0 { + ord.RealCommission = v.ActualMoney + } + if v.PaidTime != "" && v.OrderStatus == "3" { + ord.Status = "订单退款" + } + if v.SettledStatus == 1 && v.OrderStatus == "2" && v.EarningTime != "" { + ord.Status = "订单结算" + } + if v.SettledStatus == 2 { + ord.RealCommission = "0" + ord.Commission = "0" + } + 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 = "违规订单" + } + if ord.SettleTime > 0 && ord.Status == "订单退款" { + ord.SettleTime = 0 + masterDb := db.MasterDb{} + masterDb.Set() + master := masterDb.GetMaster(utils.IntToStr(ord.Uid)) + if master != nil { + masterAmountDb := db.MasterAmountDb{} + masterAmountDb.Set() + amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(ord.ExtendUid), "playlet") + if amount != nil { + oldAmount := amount.Amount + amount.Amount = utils.Float64ToStr(utils.StrToFloat64(amount.Amount) - utils.StrToFloat64(ord.RealCommission)) + update := masterAmountDb.MasterAmountUpdate(amount.Id, amount) + if update { + var tmp = model.MasterAmountFlow{ + Uid: utils.IntToStr(ord.Uid), + Time: time.Now(), + BeforeAmount: oldAmount, + Amount: ord.RealCommission, + AfterAmount: amount.Amount, + Platform: "playlet", + Oid: utils.Int64ToStr(ord.Oid), + Title: "订单退款扣除", + FlowType: "order_refund_deduct", + IncomeType: 0, + ExtendUid: utils.IntToStr(ord.ExtendUid), + } + masterAmountFlowDb := db.MasterAmountFlowDb{} + masterAmountFlowDb.Set() + masterAmountFlowDb.MasterAmountFlowInsert(&tmp) + } + } + } + } + db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) + } + + } + return len(order) +} diff --git a/app/task/svc/svc_haodanku_xianyu.go b/app/task/svc/svc_haodanku_xianyu.go new file mode 100644 index 0000000..bf8eee0 --- /dev/null +++ b/app/task/svc/svc_haodanku_xianyu.go @@ -0,0 +1,212 @@ +package svc + +import ( + "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/haodanku" + "fmt" + "strings" + "time" +) + +func HandankuXianyu() { + pvdTimeKey := "haodanku_xianyu_time" + + // 获得最后时间 + latest := offical.SysCfgByKey(pvdTimeKey) + if latest == nil { + offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String()) + latest = offical.SysCfgByKey(pvdTimeKey) + } + // 所有时间都是在操作秒数 + now := time.Now().Unix() + timeStr := latest.V + fmt.Println(timeStr) + past := utils.TimeParseStd(timeStr).Unix() + // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟 + if past > now { + past = now + } + var ( + beginTime int64 = 0 + endTime int64 = 0 + pageNo int = 1 + pageSize int = 50 + ) + + //怕时间不是走最新的 + leave := now - past + if leave > 500 { + leave = 0 + } + past = past + leave + beginTime = past - 20*60 + endTime = past + + if endTime > now { + endTime = now + } + for { + var err error + count := OrdersHaodankuXianyuGet(pageNo, pageSize, beginTime, endTime) + if err != nil || count == 0 { + goto ChkArg + } + if count > 0 { + count = pageSize + } + // 判断是否分页已经全部取完了 + if count == pageSize { + pageNo++ + fmt.Println("========蝉选下一页========" + utils.IntToStr(pageNo)) + continue + } + ChkArg: + // 查询完后重置时间, 最后查询时间 + if endTime < now { + pageNo = 1 + offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) + beginTime = endTime + endTime = endTime + 20*60 + if endTime > now { + endTime = now + } + continue + } + break + } + offical.DbsSysCfgUpdate(pvdTimeKey, time.Unix(now, 0).Format("2006-01-02 15:04:05")) + +} + +var haodankuXianyuStationState = map[string]string{ + "4": "订单付款", + "3": "订单退款", + "2": "订单成功", +} + +func OrdersHaodankuXianyuGet(page, pageSize int, sTime, eTime int64) int { + tikTokArgs := map[string]string{ + "date_type": "4", + "back": utils.IntToStr(pageSize), + "min_id": utils.IntToStr(page), + "start_date": utils.Int64ToStr(time.Unix(sTime, 0).Unix()), + "end_date": utils.Int64ToStr(time.Unix(eTime, 0).Unix()), + } + order := haodanku.HaodankuXianyuOrder(tikTokArgs) + for _, v := range order { + if v.ChannelCode == "" || v.OrderStatus == "1" { + continue + } + isShare := 0 + if strings.Contains(v.ChannelCode, "s") { + isShare = 1 + } + v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "o", "") + v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "s", "") + ex := strings.Split(v.ChannelCode, "u") + if len(ex) != 2 { + continue + } + mid := "" + uid := "" + one := db.GetLifeOrderByOne1(utils.AnyToString(v.TradeId), "xianyu") + if one != nil { + isShare = one.IsShare + mid = utils.IntToStr(one.Uid) + uid = utils.IntToStr(one.StationUid) + } else { + mid = ex[0] + uid = ex[1] + } + if mid == "" || uid == "" { + continue + } + var ord = &model.LifeOrder{ + Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))), + Uid: utils.StrToInt(mid), + StationUid: utils.StrToInt(uid), + PvdOid: utils.AnyToString(v.TradeId), + Status: haodankuXianyuStationState[v.OrderStatus], + UpdateTime: int(time.Now().Unix()), + Commission: v.PredictMoney, + Title: utils.AnyToString(v.ItemTitle), + Payment: v.PayPrice, + Pvd: "xianyu", + Img: v.ItemImg, + IsShare: isShare, + Gid: v.TradeId, + } + if v.CreateTime != "" { + ord.CreateTime = int(utils.TimeStdParseUnix(v.CreateTime)) + } + if v.EarningTime != "" { + ord.PlatformSettleTime = int(utils.TimeStdParseUnix(utils.AnyToString(v.EarningTime))) + } + if utils.StrToFloat64(v.ActualMoney) > 0 { + ord.RealCommission = v.ActualMoney + } + if v.PaidTime != "" && v.OrderStatus == "3" { + ord.Status = "订单退款" + } + if v.SettledStatus == 1 && v.OrderStatus == "2" && v.EarningTime != "" { + ord.Status = "订单结算" + } + if v.SettledStatus == 2 { + ord.RealCommission = "0" + ord.Commission = "0" + } + 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 = "违规订单" + } + if ord.SettleTime > 0 && ord.Status == "订单退款" { + ord.SettleTime = 0 + masterDb := db.MasterDb{} + masterDb.Set() + master := masterDb.GetMaster(utils.IntToStr(ord.Uid)) + if master != nil { + masterAmountDb := db.MasterAmountDb{} + masterAmountDb.Set() + amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(ord.ExtendUid), "playlet") + if amount != nil { + oldAmount := amount.Amount + amount.Amount = utils.Float64ToStr(utils.StrToFloat64(amount.Amount) - utils.StrToFloat64(ord.RealCommission)) + update := masterAmountDb.MasterAmountUpdate(amount.Id, amount) + if update { + var tmp = model.MasterAmountFlow{ + Uid: utils.IntToStr(ord.Uid), + Time: time.Now(), + BeforeAmount: oldAmount, + Amount: ord.RealCommission, + AfterAmount: amount.Amount, + Platform: "playlet", + Oid: utils.Int64ToStr(ord.Oid), + Title: "订单退款扣除", + FlowType: "order_refund_deduct", + IncomeType: 0, + ExtendUid: utils.IntToStr(ord.ExtendUid), + } + masterAmountFlowDb := db.MasterAmountFlowDb{} + masterAmountFlowDb.Set() + masterAmountFlowDb.MasterAmountFlowInsert(&tmp) + } + } + } + } + db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) + } + + } + return len(order) +} diff --git a/app/task/task_haodanku_tongcheng.go b/app/task/task_haodanku_tongcheng.go new file mode 100644 index 0000000..41e52f8 --- /dev/null +++ b/app/task/task_haodanku_tongcheng.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskHandankuTongcheng() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.HandankuTongcheng() + <-ch +} diff --git a/app/task/task_haodanku_xianyu.go b/app/task/task_haodanku_xianyu.go new file mode 100644 index 0000000..584afb4 --- /dev/null +++ b/app/task/task_haodanku_xianyu.go @@ -0,0 +1,21 @@ +package task + +import ( + "applet/app/task/svc" + "math/rand" + "time" +) + +func taskHandankuXianyu() { + for { + if len(ch) > workerNum { + time.Sleep(time.Millisecond * time.Duration(rand.Intn(1000))) + } else { + goto START + } + } +START: + ch <- 1 + svc.HandankuXianyu() + <-ch +} diff --git a/go.mod b/go.mod index 1faba1a..b29176b 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 require ( code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20230707081910-52e70aa52998 - code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20250628020002-5817026668c4 + code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git v1.1.21-0.20250712085003-8824d2f475c7 github.com/360EntSecGroup-Skylar/excelize v1.4.1 github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5 github.com/boombuler/barcode v1.0.1