智盟项目
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

167 řádky
4.3 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. offical "applet/app/db/official"
  6. "applet/app/task/md"
  7. "applet/app/utils"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/cinema_5bms"
  9. "encoding/json"
  10. "github.com/tidwall/gjson"
  11. "strings"
  12. "time"
  13. )
  14. func Cinema5bmsOrder() {
  15. cinema5bmsAppid := offical.SysCfgByKeyStr("cinema5bms_appid")
  16. cinema5bmsAppsecret := offical.SysCfgByKeyStr("cinema5bms_appSecret")
  17. uid := "0"
  18. // 获取上次获取订单时候的时间戳
  19. pvdTimeKey := "cinema5bms_order_time"
  20. now := time.Now().Unix()
  21. past := GetRunTime(uid, pvdTimeKey, "短剧获取订单时间")
  22. var (
  23. beginTime int64 = 0
  24. endTime int64 = 0
  25. pageNo int = 1
  26. pageSize int = 50
  27. )
  28. //怕时间不是走最新的
  29. leave := now - past
  30. if leave > 500 {
  31. leave = 0
  32. }
  33. var eveTime int64 = 3600
  34. past = past + leave
  35. beginTime = past - eveTime
  36. endTime = past
  37. if endTime > now {
  38. endTime = now
  39. }
  40. for {
  41. // 分配堆内存
  42. time.Sleep(time.Microsecond * 500) // 等待500毫秒
  43. //获取订单
  44. arg := map[string]string{
  45. "app_id": cinema5bmsAppid,
  46. "pay_start_date": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"),
  47. "pay_end_date": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
  48. "limit": utils.IntToStr(pageSize),
  49. "p": utils.IntToStr(pageNo),
  50. }
  51. count := GetNewVideoOrder(uid, cinema5bmsAppsecret, arg)
  52. if count == 0 {
  53. goto ChkArg
  54. }
  55. if count <= pageSize {
  56. pageNo++
  57. continue
  58. }
  59. ChkArg:
  60. // 查询完后重置时间, 最后查询时间
  61. if endTime < now {
  62. pageNo = 1
  63. SetRunTime(uid, pvdTimeKey, utils.TimeToStr(endTime))
  64. beginTime = endTime
  65. endTime = endTime + eveTime
  66. if endTime > now {
  67. endTime = now
  68. }
  69. continue
  70. }
  71. break
  72. }
  73. // 更新最后供应商执行订单时间
  74. SetRunTime(uid, pvdTimeKey, utils.TimeToStr(now))
  75. }
  76. func Cinema5bmsOrderDate() {
  77. cinema5bmsAppid := offical.SysCfgByKeyStr("cinema5bms_appid")
  78. cinema5bmsAppsecret := offical.SysCfgByKeyStr("cinema5bms_appSecret")
  79. yesterday := utils.GetTimeRange("yesterday")
  80. var (
  81. pageNo int = 1
  82. pageSize int = 50
  83. )
  84. uid := "0"
  85. for {
  86. // 分配堆内存
  87. time.Sleep(time.Microsecond * 500) // 等待500毫秒
  88. //获取订单
  89. arg := map[string]string{
  90. "app_id": cinema5bmsAppid,
  91. "show_time": time.Unix(yesterday["start"], 0).Format("2006-01-02"),
  92. "limit": utils.IntToStr(pageSize),
  93. "p": utils.IntToStr(pageNo),
  94. }
  95. count := GetNewVideoOrder(uid, cinema5bmsAppsecret, arg)
  96. if count == 0 {
  97. break
  98. }
  99. if count <= pageSize {
  100. pageNo++
  101. continue
  102. }
  103. }
  104. }
  105. func GetNewVideoOrder(uids string, cinema5bmsAppsecret string, arg map[string]string) int {
  106. cinema, _ := cinema_5bms.GetCinema("open/getOrderList", cinema5bmsAppsecret, arg)
  107. data := make([]md.Cinema5bmsOrder, 0)
  108. json.Unmarshal([]byte(gjson.Get(cinema, "data.list").String()), &data)
  109. statusMap := map[string]string{
  110. "等待核销": "订单付款",
  111. "核销成功": "订单完成",
  112. "核销失败": "订单失败",
  113. }
  114. for _, v := range data {
  115. sourceIdArr := strings.Split(v.CustomParams, "_")
  116. mid := ""
  117. uid := ""
  118. if len(sourceIdArr) == 2 {
  119. mid = sourceIdArr[0]
  120. uid = sourceIdArr[1]
  121. }
  122. if mid == "" || uid == "" {
  123. continue
  124. }
  125. Channel := "douyin"
  126. if v.Nsource == "2" {
  127. Channel = "kuaishou"
  128. }
  129. money := v.OrderAmount
  130. commission := utils.StrToFloat64(v.OrderAmount) * (10.0 / 100)
  131. var tmp = model.PlayletSaleOrder{
  132. Uid: mid,
  133. SubUid: utils.StrToInt(uid),
  134. Data: utils.SerializeStr(v),
  135. Oid: v.OrderSn,
  136. Amount: money,
  137. Commission: utils.Float64ToStr(commission),
  138. CreateTime: utils.TimeParseStd(v.PayTime),
  139. UpdateTime: time.Now(),
  140. Title: v.CinemaName + "-" + v.FilmName,
  141. VideoType: Channel,
  142. PlatformType: "5bms",
  143. GoodsType: "playlet",
  144. OrdType: "cinema",
  145. ExtendUid: uids,
  146. }
  147. playletSaleOrderDb := db.PlayletSaleOrderDb{}
  148. playletSaleOrderDb.Set()
  149. ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(v.OrderSn, tmp.OrdType)
  150. tmp.Status = statusMap[v.OrderStatus]
  151. if v.RefundTime != "" {
  152. tmp.RefundTime = utils.TimeParseStd(v.RefundTime)
  153. }
  154. if ord != nil {
  155. playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp)
  156. } else {
  157. tmp.CustomOid = utils.OrderUUID(tmp.SubUid)
  158. playletSaleOrderDb.PlayletVideoOrderInsert(&tmp)
  159. }
  160. }
  161. return len(data)
  162. }