智盟项目
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.

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