智盟项目
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

svc_meituan_order.go 5.7 KiB

1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
1 anno fa
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. offical "applet/app/db/official"
  6. md2 "applet/app/md"
  7. "applet/app/utils"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/meituan_cps"
  9. "encoding/json"
  10. "fmt"
  11. "github.com/tidwall/gjson"
  12. "strings"
  13. "time"
  14. )
  15. func MeituanOrder() {
  16. pvdTimeKey := "meituan_time"
  17. // 获得最后时间
  18. latest := offical.SysCfgByKey(pvdTimeKey)
  19. if latest == nil {
  20. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  21. latest = offical.SysCfgByKey(pvdTimeKey)
  22. }
  23. // 所有时间都是在操作秒数
  24. now := time.Now().Unix()
  25. strs := strings.Split(latest.V, ":")
  26. timeStr := latest.V
  27. if len(strs) == 3 {
  28. timeStr = strs[0] + ":" + strs[1] + ":00"
  29. }
  30. fmt.Println(timeStr)
  31. past := utils.TimeParseStd(timeStr).Unix()
  32. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  33. if past < now-180*86400 || past > now {
  34. past = now
  35. }
  36. var (
  37. beginTime int64 = 0
  38. endTime int64 = 0
  39. pageNo int = 1
  40. pageSize int = 50
  41. nextPositionIndex string = ""
  42. )
  43. //怕时间不是走最新的
  44. leave := now - past
  45. if leave > 500 {
  46. leave = 0
  47. }
  48. past = past + leave
  49. beginTime = past - 300
  50. endTime = past
  51. if endTime > now {
  52. endTime = now
  53. }
  54. for {
  55. count := 0
  56. var positionIndex = ""
  57. if pageNo == 1 {
  58. nextPositionIndex = ""
  59. }
  60. count, positionIndex = OrdersMeituanGet(nextPositionIndex, pageSize, beginTime, endTime, "update", 1)
  61. if count == 0 {
  62. nextPositionIndex = ""
  63. goto ChkArg
  64. }
  65. // 判断是否分页已经全部取完了
  66. if count <= pageSize {
  67. nextPositionIndex = positionIndex
  68. pageNo++
  69. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  70. count = 0
  71. continue
  72. }
  73. ChkArg:
  74. nextPositionIndex = ""
  75. // 查询完后重置时间, 最后查询时间
  76. if endTime < now {
  77. pageNo = 1
  78. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  79. beginTime = endTime
  80. endTime = endTime + 300
  81. if endTime > now {
  82. endTime = now
  83. }
  84. count = 0
  85. continue
  86. }
  87. count = 0
  88. break
  89. }
  90. }
  91. func OrdersMeituanGet(nextPositionIndex string, pageSize int, sTime, eTime int64, timeType string, pvd int) (int, string) {
  92. key := offical.SysCfgByKeyStr("meituan_cps_key")
  93. secret := offical.SysCfgByKeyStr("meituan_cps_secret")
  94. arg := map[string]interface{}{
  95. "queryTimeType": 2, // 1 按订单支付时间查询, 2 按照更新时间查询, 默认为1
  96. "page": 1, //页码,默认1,从1开始,若searchType选择2,本字段必须传1,若不传参数默认1
  97. "searchType": 2, //订单分页查询方案选择,不填则默认为1。1 分页查询(最多能查询到1万条订单),当选择本查询方案,page参数不能为空。此查询方式后续不再维护,建议使用2逐页查询。2 逐页查询(不限制查询订单数,只能逐页查询,不能指定页数),当选择本查询方案,需配合scrollId参数使用
  98. "startTime": sTime, //
  99. "endTime": eTime, //
  100. "limit": pageSize,
  101. "platform": pvd,
  102. "scrollId": nextPositionIndex,
  103. }
  104. method1 := "query_order"
  105. send, err := meituan_cps.Send(method1, key, secret, arg)
  106. goods := gjson.Get(send, "data.dataList").String()
  107. newPcursor := gjson.Get(send, "data.scrollId").String()
  108. if goods == "" || err != nil {
  109. return 0, ""
  110. }
  111. var list = make([]md2.MeituanOrder, 0)
  112. err = json.Unmarshal([]byte(goods), &list)
  113. if err != nil {
  114. return 0, ""
  115. }
  116. var meituanState = map[string]string{
  117. "2": "订单付款",
  118. "3": "订单完成",
  119. "4": "订单失效",
  120. "5": "风控",
  121. "6": "订单结算",
  122. }
  123. for _, v := range list {
  124. var res = model.LifeOrder{
  125. PvdParentOid: v.OrderId,
  126. Pvd: "meituan",
  127. Status: meituanState[v.Status],
  128. CreateTime: v.PayTime,
  129. }
  130. if v.PayTime == 0 {
  131. res.CreateTime = int(time.Now().Unix())
  132. }
  133. if v.UpdateTime > 0 && v.Status == "6" {
  134. res.PlatformSettleTime = v.UpdateTime
  135. }
  136. ex := strings.Split(v.Sid, "_")
  137. if len(ex) < 3 {
  138. continue
  139. }
  140. orderType := 0
  141. if ex[0] == "share" {
  142. orderType = 1
  143. }
  144. res.Uid = utils.StrToInt(ex[1])
  145. res.StationUid = utils.StrToInt(ex[2])
  146. orderDetail, ok := v.OrderDetail.([]interface{})
  147. Profit := v.Profit
  148. state := "1"
  149. if ok {
  150. if len(orderDetail) > 0 {
  151. allEnd := "1"
  152. for k1, v1 := range orderDetail {
  153. v2, ok1 := v1.(map[string]interface{})
  154. if ok1 {
  155. if k1 == 0 {
  156. state = utils.AnyToString(v2["couponStatus"])
  157. }
  158. if utils.StrToInt(utils.AnyToString(v2["couponStatus"])) < utils.StrToInt(state) {
  159. state = utils.AnyToString(v2["couponStatus"])
  160. }
  161. if utils.InArr(utils.AnyToString(v2["couponStatus"]), []string{"1", "2", "3"}) {
  162. allEnd = "0"
  163. }
  164. }
  165. }
  166. if allEnd == "0" {
  167. res.Status = state
  168. res.PlatformSettleTime = 0
  169. }
  170. }
  171. }
  172. res.Oid = utils.StrToInt64(utils.OrderUUID(utils.StrToInt(ex[1])))
  173. res.PvdOid = v.OrderId
  174. res.Uid = utils.StrToInt(ex[1])
  175. res.StationUid = utils.StrToInt(ex[2])
  176. res.UpdateTime = int(time.Now().Unix())
  177. res.Commission = Profit
  178. res.RealCommission = Profit
  179. res.Title = v.ProductName
  180. if v.ProductId == "null" {
  181. v.ProductId = v.OrderId
  182. }
  183. res.Gid = v.ProductId
  184. res.IsShare = orderType
  185. res.Payment = v.PayPrice
  186. one := db.GetLifeOrderByOne(res.PvdOid, utils.IntToStr(res.Uid), res.Pvd)
  187. if one == nil {
  188. insertOne, err := db.ZhimengDb.InsertOne(&res)
  189. fmt.Println(insertOne)
  190. fmt.Println(err)
  191. } else {
  192. res.SettleTime = one.SettleTime
  193. res.CreateTime = one.CreateTime
  194. if one.PlatformSettleTime > 0 {
  195. res.PlatformSettleTime = one.PlatformSettleTime
  196. }
  197. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(&res)
  198. }
  199. }
  200. return len(list), newPcursor
  201. }