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/t3" "fmt" "strings" "time" ) func T3Order() { pvdTimeKey := "t3_time" // 获得最后时间 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 ) //怕时间不是走最新的 leave := now - past if leave > 500 { leave = 0 } past = past + leave beginTime = past - 300 endTime = past if endTime > now { endTime = now } for { count := 0 count, _ = OrdersT3Get(pageNo, pageSize, beginTime, endTime, "update", 1) if count == 0 { goto ChkArg } // 判断是否分页已经全部取完了 if count <= pageSize { pageNo++ fmt.Println("========下一页========" + utils.IntToStr(pageNo)) count = 0 continue } ChkArg: // 查询完后重置时间, 最后查询时间 if endTime < now { pageNo = 1 offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) beginTime = endTime endTime = endTime + 300 if endTime > now { endTime = now } count = 0 continue } count = 0 break } offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime)) } func OrdersT3Get(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) { args := map[string]string{ "startTime": utils.Int64ToStr(sTime * 1000), "endTime": utils.Int64ToStr(eTime * 1000), "pageNo": utils.IntToStr(p), "pageSize": utils.IntToStr(pageSize), "supplierUuid": "3ab61dc6801f488ca085fb016d37cf68", } order := t3.GetT3Order("QOHEgCUTeK", "tsTSxrCgibcFbxGOxRDEBGQUhRVJLsFs", args) if order == nil || len(order) == 0 { return 0, "" } t3FirstCommission := db.ZhimengSysCfgGetOneData("t3_first_commission") for _, v := range order { status := "订单付款" settleTime := 0 if v.ParticipationStatus == 1 { status = "订单结算" settleTime = int(time.Now().Unix()) } if v.CreateTime == 0 { v.CreateTime = time.Now().Unix() * 1000 } var res = model.LifeOrder{ PvdParentOid: v.BusinessId, Pvd: "own_t3car", Status: status, CreateTime: int(v.CreateTime / 1000), } ex := strings.Split(v.SourceId, "_") if len(ex) < 4 || strings.Contains(v.SourceId, "own") == false { continue } orderType := 0 if ex[1] == "share" { orderType = 1 } res.PlatformSettleTime = settleTime res.Uid = utils.StrToInt(ex[2]) res.StationUid = utils.StrToInt(ex[3]) res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2]))) res.PvdOid = v.BusinessId res.UpdateTime = int(time.Now().Unix()) res.Title = "T3打车" res.Gid = res.PvdOid res.IsShare = orderType if v.PayAmount == 0 { v.PayAmount = v.OrderAmount } res.Payment = utils.Float64ToStr(v.PayAmount) var commission float64 = 0 if v.ParticipationStatus == 1 { if v.CpaType == "CPA" || v.CpaType == "NEW_CPA" { if v.AttributionalFirstOrder { commission = utils.StrToFloat64(t3FirstCommission) } } if v.CpaType == "CPS" || v.CpaType == "NEW_CPS" { commission = v.PayAmount * float64(v.Rate) / 100 } if v.CpaType == "CPA_CPS" || v.CpaType == "NEW_CPA_CPS" { if v.AttributionalFirstOrder { commission = utils.StrToFloat64(t3FirstCommission) } commission += v.PayAmount * float64(v.Rate) / 100 } } res.Commission = utils.Float64ToStr(commission) res.RealCommission = utils.Float64ToStr(commission) one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd) if one == nil { insertOne, err := db.ZhimengDb.InsertOne(&res) fmt.Println(insertOne) fmt.Println(err) } else { res.SettleTime = one.SettleTime res.CreateTime = one.CreateTime if one.PlatformSettleTime > 0 { res.PlatformSettleTime = one.PlatformSettleTime } db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res) } } return len(order), "" }