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/elm" "fmt" "strings" "time" ) func ElmOrder() { pvdTimeKey := "elm_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, _ = OrdersElmGet(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 OrdersElmGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) { key := "34319215" secret := "bb07710660e60a321350a35e1e3b91e8" args := map[string]string{ "end_time": time.Unix(eTime, 0).Format("2006-01-02 15:04:05"), "start_time": time.Unix(sTime, 0).Format("2006-01-02 15:04:05"), "p": utils.IntToStr(p), "size": utils.IntToStr(pageSize), } order, _ := elm.ElemePromotionOrder(key, secret, args) if order == nil { return 0, "" } var stateList = map[string]string{ "2": "订单付款", "4": "订单完成", "1": "创建订单", "0": "订单失效", } for _, v := range order.Result { if *v.OrderState == 1 { continue } createTime := utils.TimeStdParseUnix(*v.TkCreateTime) if v.PayTime != nil { createTime = utils.TimeStdParseUnix(*v.PayTime) } var res = model.LifeOrder{ PvdParentOid: utils.Int64ToStr(*v.ParentOrderId), Pvd: "own_ele", Status: stateList[utils.Int64ToStr(*v.OrderState)], CreateTime: int(createTime), } if *v.SettleState == 1 && v.SettleTime != nil { res.Status = "订单结算" res.PlatformSettleTime = int(utils.TimeStdParseUnix(*v.SettleTime)) } ex := strings.Split(*v.Sid, "_") if len(ex) < 4 || strings.Contains(*v.Sid, "own") == false { continue } orderType := 0 if ex[1] == "share" { orderType = 1 } res.Uid = utils.StrToInt(ex[2]) res.StationUid = utils.StrToInt(ex[3]) res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2]))) res.PvdOid = utils.Int64ToStr(*v.BizOrderId) res.UpdateTime = int(time.Now().Unix()) if utils.StrToFloat64(*v.PlatformCommissionFee) == 0 { amount := utils.StrToFloat64(*v.Income) if utils.StrToFloat64(*v.Settle) > 0 { amount = utils.StrToFloat64(*v.Settle) } fee := float64(int(amount*0.1*100)) / 100 *v.PlatformCommissionFee = utils.Float64ToStr(fee) } res.Commission = utils.Float64ToStr(utils.StrToFloat64(*v.Income) - utils.StrToFloat64(*v.PlatformCommissionFee)) if v.Settle != nil && utils.StrToFloat64(*v.Settle) > 0 { res.RealCommission = utils.Float64ToStr(utils.StrToFloat64(*v.Settle) - utils.StrToFloat64(*v.PlatformCommissionFee)) } res.Title = *v.Title res.Img = *v.PicUrl res.Gid = res.PvdOid res.IsShare = orderType res.Payment = *v.PayAmount 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.Result), "" }