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

svc_tik_tok_csjp.go 4.9 KiB

10 months ago
8 months ago
10 months ago
10 months ago
10 months ago
7 months ago
10 months ago
8 months ago
10 months ago
8 months ago
10 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. offical "applet/app/db/official"
  6. "applet/app/utils"
  7. "fmt"
  8. "strings"
  9. "time"
  10. )
  11. var oilstationState = map[string]int{
  12. "订单付款": 0,
  13. "订单成功": 2,
  14. "订单完成": 2,
  15. "订单失效": 4,
  16. "订单退款": 4,
  17. "订单结算": 3,
  18. }
  19. func TikTokCsjp(ordType int) {
  20. pvdTimeKey := "csjp_time_" + utils.IntToStr(ordType)
  21. // 获得最后时间
  22. latest := offical.SysCfgByKey(pvdTimeKey)
  23. if latest == nil {
  24. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  25. latest = offical.SysCfgByKey(pvdTimeKey)
  26. }
  27. // 所有时间都是在操作秒数
  28. now := time.Now().Unix()
  29. strs := strings.Split(latest.V, ":")
  30. timeStr := latest.V
  31. if len(strs) == 3 {
  32. timeStr = strs[0] + ":" + strs[1] + ":00"
  33. }
  34. fmt.Println(timeStr)
  35. past := utils.TimeParseStd(timeStr).Unix()
  36. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  37. if past < now-180*86400 || past > now {
  38. past = now
  39. }
  40. var (
  41. beginTime int64 = 0
  42. endTime int64 = 0
  43. pageNo int = 1
  44. pageSize int = 50
  45. nextPositionIndex string = ""
  46. )
  47. //怕时间不是走最新的
  48. leave := now - past
  49. if leave > 500 {
  50. leave = 0
  51. }
  52. past = past + leave
  53. beginTime = past - 300
  54. endTime = past
  55. if endTime > now {
  56. endTime = now
  57. }
  58. for {
  59. ordData := new([]map[string]string)
  60. var positionIndex = ""
  61. var err error
  62. if pageNo == 1 {
  63. nextPositionIndex = "0"
  64. }
  65. if nextPositionIndex != "" {
  66. ordData, positionIndex, err = OrdersTikTokGet(nextPositionIndex, pageSize, beginTime, endTime, "update", ordType)
  67. }
  68. count := 0
  69. if ordData == nil {
  70. nextPositionIndex = ""
  71. goto ChkArg
  72. }
  73. count = len(*ordData)
  74. if err != nil || ordData == nil || len(*ordData) == 0 {
  75. nextPositionIndex = ""
  76. goto ChkArg
  77. }
  78. if count > 0 {
  79. count = pageSize
  80. }
  81. // 判断是否分页已经全部取完了
  82. if count == pageSize {
  83. nextPositionIndex = positionIndex
  84. pageNo++
  85. fmt.Println("========下一页========" + utils.IntToStr(pageNo))
  86. ordData = nil
  87. continue
  88. }
  89. ChkArg:
  90. nextPositionIndex = ""
  91. // 查询完后重置时间, 最后查询时间
  92. if endTime < now {
  93. pageNo = 1
  94. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  95. beginTime = endTime
  96. endTime = endTime + 300
  97. if endTime > now {
  98. endTime = now
  99. }
  100. ordData = nil
  101. continue
  102. }
  103. ordData = nil
  104. break
  105. }
  106. }
  107. func OrdersTikTokGet(nextPositionIndex string, pageSize int, sTime, eTime int64, timeType string, pvd int) (*[]map[string]string, string, error) {
  108. distributionType := pvd
  109. tikTokArgs := map[string]string{
  110. "size": utils.IntToStr(pageSize),
  111. "cursor": nextPositionIndex,
  112. "start_time": utils.Int64ToStr(time.Unix(sTime, 0).Unix()),
  113. "end_time": utils.Int64ToStr(time.Unix(eTime, 0).Unix()),
  114. "time_type": timeType,
  115. "order_type": utils.IntToStr(distributionType),
  116. }
  117. //if cfg.Prd == false {
  118. // tikTokArgs["start_time"] = "2023-09-18 15:59:00"
  119. // tikTokArgs["end_time"] = "2023-09-18 16:02:00"
  120. //}
  121. order := CsjpOrder(tikTokArgs)
  122. cursor := utils.AnyToString(order["cursor"])
  123. list, ok := order["order"].([]map[string]string)
  124. if ok {
  125. for _, v := range list {
  126. if utils.StrToInt(v["uid"]) == 0 {
  127. continue
  128. }
  129. orderType := 0
  130. if v["is_share"] == "1" {
  131. orderType = 1
  132. }
  133. // 判断免单
  134. if v["is_share"] == "2" {
  135. orderType = 2
  136. }
  137. if v["is_share"] == "3" {
  138. orderType = 10
  139. }
  140. if v["is_share"] == "4" {
  141. orderType = 11
  142. }
  143. if v["is_share"] == "5" {
  144. orderType = 12
  145. }
  146. if v["is_share"] == "6" {
  147. orderType = 13
  148. }
  149. if v["type"] == "" {
  150. v["type"] = "csjp"
  151. }
  152. var ord = &model.GuideOrder{
  153. Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(v["uid"]))),
  154. Uid: utils.StrToInt(v["mid"]),
  155. StationUid: utils.StrToInt(v["uid"]),
  156. PvdOid: utils.AnyToString(v["oid"]),
  157. Status: v["status"],
  158. CreateTime: utils.StrToInt(v["create_time"]),
  159. UpdateTime: int(time.Now().Unix()),
  160. Commission: v["commission"],
  161. RealCommission: v["commission"],
  162. Title: utils.AnyToString(v["info"]),
  163. Payment: v["payment"],
  164. Pvd: v["type"],
  165. Img: v["product_img"],
  166. IsShare: orderType,
  167. Gid: v["product_id"],
  168. }
  169. if utils.StrToInt(v["lm_js_time"]) > 0 {
  170. ord.PlatformSettleTime = utils.StrToInt(v["lm_js_time"])
  171. }
  172. one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd)
  173. if one == nil {
  174. insertOne, err := db.ZhimengDb.InsertOne(ord)
  175. fmt.Println(insertOne)
  176. fmt.Println(err)
  177. } else {
  178. ord.SettleTime = one.SettleTime
  179. if one.PlatformSettleTime > 0 {
  180. ord.PlatformSettleTime = one.PlatformSettleTime
  181. }
  182. if one.Status == "违规订单" {
  183. one.Status = "违规订单"
  184. }
  185. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
  186. }
  187. }
  188. return &list, cursor, nil
  189. }
  190. return nil, "", nil
  191. }