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

217 lines
5.4 KiB

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