智盟项目
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

svc_playlet_buhai_order.go 3.9 KiB

10 månader sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. "applet/app/utils/cache"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/playlet_bihai"
  10. "encoding/json"
  11. "github.com/tidwall/gjson"
  12. "strings"
  13. "time"
  14. )
  15. func PlayletBihaiOrder() {
  16. bihaiAppId := offical.SysCfgByKeyStr("bihai_app_id")
  17. key := "bihai_token_" + bihaiAppId
  18. bihaiAppSecret := offical.SysCfgByKeyStr("bihai_app_secret")
  19. getString, err := cache.GetString(key)
  20. if getString == "" || err != nil {
  21. args := map[string]string{
  22. "app_id": bihaiAppId,
  23. "app_secret": bihaiAppSecret,
  24. }
  25. login, _ := playlet_bihai.Login(args)
  26. token := gjson.Get(login, "data.access_token").String()
  27. expiresIn := gjson.Get(login, "data.expires_in").Int()
  28. if token != "" {
  29. cache.SetEx(key, token, int(expiresIn))
  30. }
  31. getString = token
  32. }
  33. if getString == "" {
  34. return
  35. }
  36. uid := "0"
  37. // 获取上次获取订单时候的时间戳
  38. pvdTimeKey := "bihai_order_time"
  39. now := time.Now().Unix()
  40. past := GetRunTime(uid, pvdTimeKey, "短剧获取订单时间")
  41. var (
  42. beginTime int64 = 0
  43. endTime int64 = 0
  44. pageNo int = 1
  45. pageSize int = 100
  46. )
  47. //怕时间不是走最新的
  48. leave := now - past
  49. if leave > 500 {
  50. leave = 0
  51. }
  52. var eveTime int64 = 3600
  53. past = past + leave
  54. beginTime = past - eveTime
  55. endTime = past
  56. if endTime > now {
  57. endTime = now
  58. }
  59. nextId := "0"
  60. for {
  61. // 分配堆内存
  62. time.Sleep(time.Microsecond * 500) // 等待500毫秒
  63. //获取订单
  64. arg := map[string]string{
  65. "start_at": time.Unix(beginTime, 0).Format("2006-01-02 15:04:05"),
  66. "end_at": time.Unix(endTime, 0).Format("2006-01-02 15:04:05"),
  67. "page_size": utils.IntToStr(pageSize),
  68. "next_id": nextId,
  69. }
  70. link, _ := playlet_bihai.OrderList(getString, arg)
  71. var order md.BihaiOrder
  72. err := json.Unmarshal([]byte(gjson.Get(link, "data").String()), &order)
  73. if err != nil {
  74. break
  75. }
  76. statusMap := map[string]string{
  77. "1": "订单付款",
  78. "2": "订单失败",
  79. }
  80. for _, v := range order.List {
  81. if utils.StrToInt(v.Status) < 1 {
  82. continue
  83. }
  84. sourceIdArr := strings.Split(v.Ext.QwExt, "_")
  85. mid := ""
  86. uid1 := ""
  87. if len(sourceIdArr) == 2 {
  88. mid = sourceIdArr[0]
  89. uid1 = sourceIdArr[1]
  90. }
  91. if mid == "" || uid1 == "" {
  92. continue
  93. }
  94. Channel := "douyin"
  95. if v.MarketId == "2" {
  96. Channel = "kuaishou"
  97. }
  98. money := utils.Float64ToStr(utils.StrToFloat64(v.Price) / 100)
  99. commission := utils.StrToFloat64(money) * (80.0 / 100)
  100. var tmp = model.PlayletSaleOrder{
  101. Uid: mid,
  102. SubUid: utils.StrToInt(uid1),
  103. Data: utils.SerializeStr(v),
  104. Oid: v.OrderId,
  105. Amount: money,
  106. Commission: utils.Float64ToStr(commission),
  107. CreateTime: utils.TimeParseStd(v.CreatedAt),
  108. UpdateTime: time.Now(),
  109. Title: "碧海剧场",
  110. VideoType: Channel,
  111. PlatformType: "bihai",
  112. GoodsType: "playlet",
  113. OrdType: "video",
  114. ExtendUid: uid,
  115. }
  116. playletSaleOrderDb := db.PlayletSaleOrderDb{}
  117. playletSaleOrderDb.Set()
  118. ord := playletSaleOrderDb.GetPlayletVideoOrderByOid(v.OrderId, tmp.OrdType)
  119. tmp.Status = statusMap[v.Status]
  120. if ord != nil {
  121. playletSaleOrderDb.PlayletVideoOrderUpdate(ord.Id, &tmp)
  122. } else {
  123. tmp.CustomOid = utils.OrderUUID(tmp.SubUid)
  124. playletSaleOrderDb.PlayletVideoOrderInsert(&tmp)
  125. }
  126. }
  127. if order.HasMore == false {
  128. nextId = "0"
  129. goto ChkArg
  130. }
  131. if len(order.List) == pageSize {
  132. nextId = utils.IntToStr(order.NextId)
  133. pageNo++
  134. continue
  135. }
  136. ChkArg:
  137. // 查询完后重置时间, 最后查询时间
  138. if endTime < now {
  139. nextId = "0"
  140. pageNo = 1
  141. SetRunTime(uid, pvdTimeKey, utils.TimeToStr(endTime))
  142. beginTime = endTime
  143. endTime = endTime + eveTime
  144. if endTime > now {
  145. endTime = now
  146. }
  147. continue
  148. }
  149. break
  150. }
  151. // 更新最后供应商执行订单时间
  152. SetRunTime(uid, pvdTimeKey, utils.TimeToStr(now))
  153. }