智盟项目
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

svc_meituan_order.go 6.5 KiB

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