智盟项目
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_t3_order.go 4.4 KiB

4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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/t3"
  8. "fmt"
  9. "strings"
  10. "time"
  11. )
  12. func T3Order() {
  13. pvdTimeKey := "t3_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, _ = OrdersT3Get(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 OrdersT3Get(p int, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) {
  82. args := map[string]string{
  83. "startTime": utils.Int64ToStr(sTime * 1000),
  84. "endTime": utils.Int64ToStr(eTime * 1000),
  85. "pageNo": utils.IntToStr(p),
  86. "pageSize": utils.IntToStr(pageSize),
  87. "supplierUuid": "3ab61dc6801f488ca085fb016d37cf68",
  88. }
  89. order := t3.GetT3Order("QOHEgCUTeK", "tsTSxrCgibcFbxGOxRDEBGQUhRVJLsFs", args)
  90. if order == nil || len(order) == 0 {
  91. return 0, ""
  92. }
  93. t3FirstCommission := db.ZhimengSysCfgGetOneData("t3_first_commission")
  94. for _, v := range order {
  95. status := "订单付款"
  96. settleTime := 0
  97. if v.ParticipationStatus == 1 {
  98. status = "订单结算"
  99. settleTime = int(time.Now().Unix())
  100. }
  101. if v.CreateTime == 0 {
  102. v.CreateTime = time.Now().Unix() * 1000
  103. }
  104. var res = model.LifeOrder{
  105. PvdParentOid: v.BusinessId,
  106. Pvd: "own_t3car",
  107. Status: status,
  108. CreateTime: int(v.CreateTime / 1000),
  109. }
  110. ex := strings.Split(v.SourceId, "_")
  111. if len(ex) < 4 || strings.Contains(v.SourceId, "own") == false {
  112. continue
  113. }
  114. orderType := 0
  115. if ex[1] == "share" {
  116. orderType = 1
  117. }
  118. res.PlatformSettleTime = settleTime
  119. res.Uid = utils.StrToInt(ex[2])
  120. res.StationUid = utils.StrToInt(ex[3])
  121. res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[2])))
  122. res.PvdOid = v.BusinessId
  123. res.UpdateTime = int(time.Now().Unix())
  124. res.Title = "T3打车"
  125. res.Gid = res.PvdOid
  126. res.IsShare = orderType
  127. if v.PayAmount == 0 {
  128. v.PayAmount = v.OrderAmount
  129. }
  130. res.Payment = utils.Float64ToStr(v.PayAmount)
  131. var commission float64 = 0
  132. if v.ParticipationStatus == 1 {
  133. if v.CpaType == "CPA" || v.CpaType == "NEW_CPA" {
  134. if v.AttributionalFirstOrder {
  135. commission = utils.StrToFloat64(t3FirstCommission)
  136. }
  137. }
  138. if v.CpaType == "CPS" || v.CpaType == "NEW_CPS" {
  139. commission = v.PayAmount * float64(v.Rate) / 100
  140. }
  141. if v.CpaType == "CPA_CPS" || v.CpaType == "NEW_CPA_CPS" {
  142. if v.AttributionalFirstOrder {
  143. commission = utils.StrToFloat64(t3FirstCommission)
  144. }
  145. commission += v.PayAmount * float64(v.Rate) / 100
  146. }
  147. }
  148. res.Commission = utils.Float64ToStr(commission)
  149. res.RealCommission = utils.Float64ToStr(commission)
  150. one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd)
  151. if one == nil {
  152. insertOne, err := db.ZhimengDb.InsertOne(&res)
  153. fmt.Println(insertOne)
  154. fmt.Println(err)
  155. } else {
  156. res.SettleTime = one.SettleTime
  157. res.CreateTime = one.CreateTime
  158. if one.PlatformSettleTime > 0 {
  159. res.PlatformSettleTime = one.PlatformSettleTime
  160. }
  161. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res)
  162. }
  163. }
  164. return len(order), ""
  165. }