智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_didi_order.go 4.3 KiB

4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. offical "applet/app/db/official"
  6. "applet/app/utils"
  7. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/didi"
  8. "fmt"
  9. "strings"
  10. "time"
  11. )
  12. func DidiOrder() {
  13. pvdTimeKey := "didi_time"
  14. // 获得最后时间
  15. latest := offical.SysCfgByKey(pvdTimeKey)
  16. if latest == nil {
  17. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  18. latest = offical.SysCfgByKey(pvdTimeKey)
  19. }
  20. // 所有时间都是在操作秒数
  21. now := time.Now().Unix()
  22. strs := strings.Split(latest.V, ":")
  23. timeStr := latest.V
  24. if len(strs) == 3 {
  25. timeStr = strs[0] + ":" + strs[1] + ":00"
  26. }
  27. fmt.Println(timeStr)
  28. past := utils.TimeParseStd(timeStr).Unix()
  29. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  30. if past < now-180*86400 || past > now {
  31. past = now
  32. }
  33. var (
  34. beginTime int64 = 0
  35. endTime int64 = 0
  36. pageNo int = 1
  37. pageSize int = 50
  38. )
  39. //怕时间不是走最新的
  40. leave := now - past
  41. if leave > 500 {
  42. leave = 0
  43. }
  44. past = past + leave
  45. beginTime = past - 300
  46. endTime = past
  47. if endTime > now {
  48. endTime = now
  49. }
  50. for {
  51. count := 0
  52. count, _ = OrdersDidiGet(pageNo, pageSize, beginTime, endTime, "update", 1)
  53. if count == 0 {
  54. goto ChkArg
  55. }
  56. // 判断是否分页已经全部取完了
  57. if count <= pageSize {
  58. pageNo++
  59. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  60. count = 0
  61. continue
  62. }
  63. ChkArg:
  64. // 查询完后重置时间, 最后查询时间
  65. if endTime < now {
  66. pageNo = 1
  67. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  68. beginTime = endTime
  69. endTime = endTime + 300
  70. if endTime > now {
  71. endTime = now
  72. }
  73. count = 0
  74. continue
  75. }
  76. count = 0
  77. break
  78. }
  79. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  80. }
  81. func OrdersDidiGet(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) {
  82. key := "42c22ffdc81caf4c9c0621492f10cd1c"
  83. secret := "Pyqb416Pagi7kYC0CMxdIckNYdAyoyfy"
  84. args := map[string]interface{}{
  85. "pay_end_time": eTime,
  86. "pay_start_time": sTime,
  87. "page": p,
  88. "size": pageSize,
  89. }
  90. order := didi.GetDidiOrder(key, secret, args)
  91. if order == nil || len(order) == 0 {
  92. return 0, ""
  93. }
  94. var stateList = map[int]string{
  95. 2: "订单付款",
  96. 8: "订单失效",
  97. }
  98. typeArr := map[string]string{"159": "own_oilstation", "210": "own_didi_online_car", "393": "own_didi_freight", "500": "own_king_flower", "120": "own_didi_chauffeur"}
  99. for _, v := range order {
  100. status := stateList[v.OrderStatus]
  101. var settleTime int64 = 0
  102. if v.Status >= 4 {
  103. status = "订单结算"
  104. settleTime = time.Now().Unix()
  105. if v.Status == 6 {
  106. status = "订单失效"
  107. v.FailReason = "联盟判断不结算"
  108. settleTime = 0
  109. }
  110. }
  111. var res = model.LifeOrder{
  112. PvdParentOid: v.OrderId,
  113. Pvd: typeArr[utils.IntToStr(v.ProductId)],
  114. Status: status,
  115. CreateTime: v.PayTime,
  116. }
  117. if res.Pvd == "" {
  118. res.Pvd = "own_didi_online_car"
  119. }
  120. ex := strings.Split(v.SourceId, "_")
  121. if len(ex) < 4 || strings.Contains(v.SourceId, "own") == false {
  122. continue
  123. }
  124. orderType := 0
  125. if ex[1] == "share" {
  126. orderType = 1
  127. }
  128. res.Ext = v.FailReason
  129. res.Uid = utils.StrToInt(ex[2])
  130. res.StationUid = utils.StrToInt(ex[3])
  131. res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2])))
  132. res.PvdOid = v.OrderId
  133. res.UpdateTime = int(time.Now().Unix())
  134. res.Title = v.Title
  135. res.Gid = res.PvdOid
  136. res.IsShare = orderType
  137. res.Payment = utils.Float64ToStr(float64(v.PayPrice) / 100)
  138. var commission = float64(v.CpsProfit) / 100
  139. if v.CpaProfit > 0 {
  140. commission += float64(v.CpaProfit) / 100 * 0.5
  141. }
  142. if settleTime > 0 {
  143. res.PlatformSettleTime = int(settleTime)
  144. }
  145. res.Commission = utils.Float64ToStr(commission)
  146. res.RealCommission = utils.Float64ToStr(commission)
  147. one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd)
  148. if one == nil {
  149. insertOne, err := db.ZhimengDb.InsertOne(&res)
  150. fmt.Println(insertOne)
  151. fmt.Println(err)
  152. } else {
  153. res.SettleTime = one.SettleTime
  154. res.CreateTime = one.CreateTime
  155. if one.PlatformSettleTime > 0 {
  156. res.PlatformSettleTime = one.PlatformSettleTime
  157. }
  158. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res)
  159. }
  160. }
  161. return len(order), ""
  162. }