package svc import ( "applet/app/db" offical "applet/app/db/official" "applet/app/utils" "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/thirdParty/wph" "fmt" "github.com/syyongx/php2go" "strings" "time" ) func WphRefundOrder() { pvdTimeKey := "wph_refund_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 nextPositionIndex string = "" ) //怕时间不是走最新的 leave := now - past if leave > 500 { leave = 0 } past = past + leave beginTime = past - 300 endTime = past if endTime > now { endTime = now } wphData := WphComm() for { count := 0 var positionIndex = "" if pageNo == 1 { nextPositionIndex = "0" } if nextPositionIndex != "" { positionIndex, count, _ = OrdersWphRefundGet(pageNo, pageSize, beginTime, endTime, "update", 1, nextPositionIndex, wphData) } if count == 0 { nextPositionIndex = "" goto ChkArg } // 判断是否分页已经全部取完了 if count <= pageSize { nextPositionIndex = positionIndex pageNo++ fmt.Println("========下一页========" + utils.IntToStr(pageNo)) count = 0 continue } ChkArg: nextPositionIndex = "" // 查询完后重置时间, 最后查询时间 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 } } func OrdersWphRefundGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int, nextPositionIndex string, wphData map[string]string) (string, int, string) { queryModel := map[string]string{ "pageSize": utils.IntToStr(pageSize), "page": utils.IntToStr(p), "searchType": "1", "searchTimeStart": utils.Int64ToStr(sTime * 1000), "searchTimeEnd": utils.Int64ToStr(eTime * 1000), "requestId": wphData["uuid"] + utils.Int64ToStr(time.Now().Unix()) + utils.IntToStr(php2go.Rand(1000, 9999)), } paramData := map[string]interface{}{ "request": queryModel, } param := utils.SerializeStr(paramData) order := wph.GetRefundOrder(wphData, param) if order == nil { return "", 0, "" } orderCount := len(order) for _, v := range order { one := db.GetGuideOrderByOid(v["oid"], "vip") if one != nil { if v["state"] == "-1" { one.Status = "订单失效" } else if v["commission"] != "" { one.Commission = v["commission"] } db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(one) } } return "", orderCount, "" }