|
- 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/didi"
- "fmt"
- "strings"
- "time"
- )
-
- func DidiOrder() {
- pvdTimeKey := "didi_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, _ = OrdersDidiGet(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 OrdersDidiGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) {
- key := "42c22ffdc81caf4c9c0621492f10cd1c"
- secret := "Pyqb416Pagi7kYC0CMxdIckNYdAyoyfy"
- args := map[string]interface{}{
- "pay_end_time": eTime,
- "pay_start_time": sTime,
- "page": p,
- "size": pageSize,
- }
- order := didi.GetDidiOrder(key, secret, args)
- if order == nil || len(order) == 0 {
- return 0, ""
- }
-
- var stateList = map[int]string{
- 2: "订单付款",
- 8: "订单失效",
- }
- typeArr := map[string]string{"159": "own_oilstation", "210": "own_didi_online_car", "393": "own_didi_freight", "500": "own_king_flower", "120": "own_didi_chauffeur"}
- for _, v := range order {
- status := stateList[v.OrderStatus]
- var settleTime int64 = 0
- if v.Status >= 4 {
- status = "订单结算"
- settleTime = time.Now().Unix()
- if v.Status == 6 {
- status = "订单失效"
- v.FailReason = "联盟判断不结算"
- settleTime = 0
- }
- }
- var res = model.LifeOrder{
- PvdParentOid: v.OrderId,
- Pvd: typeArr[utils.IntToStr(v.ProductId)],
- Status: status,
- CreateTime: v.PayTime,
- }
- if res.Pvd == "" {
- res.Pvd = "own_didi_online_car"
- }
- 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.Ext = v.FailReason
- 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.OrderId
- res.UpdateTime = int(time.Now().Unix())
- res.Title = v.Title
- res.Gid = res.PvdOid
- res.IsShare = orderType
- res.Payment = utils.Float64ToStr(float64(v.PayPrice) / 100)
- var commission = float64(v.CpsProfit) / 100
- if v.CpaProfit > 0 {
- commission += float64(v.CpaProfit) / 100 * 0.5
- }
- if settleTime > 0 {
- res.PlatformSettleTime = int(settleTime)
- }
- 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), ""
- }
|