package svc import ( "applet/app/db" "applet/app/db/model" offical "applet/app/db/official" "applet/app/utils" "fmt" "strings" "time" ) var oilstationState = map[string]int{ "订单付款": 0, "订单成功": 2, "订单完成": 2, "订单失效": 4, "订单退款": 4, "订单结算": 3, } func TikTokCsjp(ordType int) { pvdTimeKey := "csjp_time_" + utils.IntToStr(ordType) // 获得最后时间 latest := offical.SysCfgByKey(pvdTimeKey) if latest == nil { offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String()) latest = offical.SysCfgByKey(pvdTimeKey) } // 所有时间都是在操作秒数 now := time.Now().Unix() strs := strings.Split(latest.V, ":") timeStr := latest.V if len(strs) == 3 { timeStr = strs[0] + ":" + strs[1] + ":00" } fmt.Println(timeStr) past := utils.TimeParseStd(timeStr).Unix() // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟 if past < now-180*86400 || past > now { past = now } var ( beginTime int64 = 0 endTime int64 = 0 pageNo int = 1 pageSize int = 50 nextPositionIndex string = "" ) //怕时间不是走最新的 leave := now - past if leave > 500 { leave = 0 } past = past + leave beginTime = past - 300 endTime = past if endTime > now { endTime = now } for { ordData := new([]map[string]string) var positionIndex = "" var err error if pageNo == 1 { nextPositionIndex = "0" } if nextPositionIndex != "" { ordData, positionIndex, err = OrdersTikTokGet(nextPositionIndex, pageSize, beginTime, endTime, "update", ordType) } count := 0 if ordData == nil { nextPositionIndex = "" goto ChkArg } count = len(*ordData) if err != nil || ordData == nil || len(*ordData) == 0 { nextPositionIndex = "" goto ChkArg } if count > 0 { count = pageSize } // 判断是否分页已经全部取完了 if count == pageSize { nextPositionIndex = positionIndex pageNo++ fmt.Println("========下一页========" + utils.IntToStr(pageNo)) ordData = nil continue } ChkArg: nextPositionIndex = "" // 查询完后重置时间, 最后查询时间 if endTime < now { pageNo = 1 offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) beginTime = endTime endTime = endTime + 300 if endTime > now { endTime = now } ordData = nil continue } ordData = nil break } } func OrdersTikTokGet(nextPositionIndex string, pageSize int, sTime, eTime int64, timeType string, pvd int) (*[]map[string]string, string, error) { distributionType := pvd tikTokArgs := map[string]string{ "size": utils.IntToStr(pageSize), "cursor": nextPositionIndex, "start_time": utils.Int64ToStr(time.Unix(sTime, 0).Unix()), "end_time": utils.Int64ToStr(time.Unix(eTime, 0).Unix()), "time_type": timeType, "order_type": utils.IntToStr(distributionType), } //if cfg.Prd == false { // tikTokArgs["start_time"] = "2023-09-18 15:59:00" // tikTokArgs["end_time"] = "2023-09-18 16:02:00" //} order := CsjpOrder(tikTokArgs) cursor := utils.AnyToString(order["cursor"]) list, ok := order["order"].([]map[string]string) if ok { for _, v := range list { if utils.StrToInt(v["uid"]) == 0 { continue } orderType := 0 if v["is_share"] == "1" { orderType = 1 } // 判断免单 if v["is_share"] == "2" { orderType = 2 } if v["is_share"] == "3" { orderType = 10 } if v["is_share"] == "4" { orderType = 11 } if v["is_share"] == "5" { orderType = 12 } if v["is_share"] == "6" { orderType = 13 } if v["type"] == "" { v["type"] = "csjp" } var ord = &model.GuideOrder{ Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(v["uid"]))), Uid: utils.StrToInt(v["mid"]), StationUid: utils.StrToInt(v["uid"]), PvdOid: utils.AnyToString(v["oid"]), Status: v["status"], CreateTime: utils.StrToInt(v["create_time"]), UpdateTime: int(time.Now().Unix()), Commission: v["commission"], RealCommission: v["commission"], Title: utils.AnyToString(v["info"]), Payment: v["payment"], Pvd: v["type"], Img: v["product_img"], IsShare: orderType, Gid: v["product_id"], } if utils.StrToInt(v["lm_js_time"]) > 0 { ord.PlatformSettleTime = utils.StrToInt(v["lm_js_time"]) } one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd) 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 == "违规订单" { one.Status = "违规订单" } db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord) } } return &list, cursor, nil } return nil, "", nil }