智盟项目
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

142 lignes
3.8 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/md/csjp"
  8. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
  9. "fmt"
  10. "strings"
  11. "time"
  12. )
  13. func CsjpLocalLifeOrder() {
  14. p := ""
  15. for true {
  16. _, curor, hasMore := GetCsjpLocalLifeOrder(p)
  17. if hasMore == false {
  18. break
  19. }
  20. p = curor
  21. }
  22. }
  23. func GetCsjpLocalLifeOrder(p string) (int, string, bool) {
  24. endTime := time.Now().Unix()
  25. startTime := endTime - 3600
  26. tikTokCsjpAppId := offical.SysCfgByKeyStr("tik_tok_csjp_life_app_id")
  27. tikTokCsjpAppSecret := offical.SysCfgByKeyStr("tik_tok_csjp_life_app_secret")
  28. param := map[string]string{
  29. "cursor": p,
  30. "count": "50",
  31. "update_time_begin": utils.Int64ToStr(startTime),
  32. "update_time_end": utils.Int64ToStr(endTime),
  33. }
  34. param["app_id"] = tikTokCsjpAppId
  35. param["app_secret"] = tikTokCsjpAppSecret
  36. data, cursor, hasMore := tik_tok.CsjpLifeGetOrder(param)
  37. count := 0
  38. if data != nil {
  39. for _, v := range *data {
  40. AddCsjpLocalLifeOrder(v)
  41. }
  42. return count, utils.Int64ToStr(cursor), hasMore
  43. }
  44. return count, "", false
  45. }
  46. func AddCsjpLocalLifeOrder(order csjp.CsjpOrder) {
  47. statusArr := map[int]string{1: "订单付款", 2: "订单退款", 3: "订单成功", 4: "部分核销", 5: "部分退款"}
  48. userId := order.CommandExternalInfo
  49. isShare := 0
  50. if strings.Contains(utils.AnyToString(userId), "s") {
  51. isShare = 1
  52. }
  53. if strings.Contains(utils.AnyToString(userId), "ddstar") || strings.Contains(utils.AnyToString(userId), "ygd") {
  54. return
  55. }
  56. split := strings.Split(utils.AnyToString(userId), "_")
  57. if len(split) < 3 {
  58. return
  59. }
  60. mid := split[2]
  61. puid := ""
  62. if len(split) == 4 {
  63. puid = split[2]
  64. }
  65. uid := split[1]
  66. title := ""
  67. img := ""
  68. if len(order.ProductList) > 0 {
  69. title = order.ProductList[0].Name
  70. img = order.ProductList[0].Img
  71. }
  72. var ord = &model.GuideOrder{
  73. Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))),
  74. Uid: utils.StrToInt(mid),
  75. ExtendUid: utils.StrToInt(puid),
  76. StationUid: utils.StrToInt(uid),
  77. PvdOid: order.OrderId,
  78. PvdParentOid: order.RootOrderId,
  79. Status: statusArr[order.Status],
  80. CreateTime: order.PayTime,
  81. UpdateTime: int(time.Now().Unix()),
  82. Commission: utils.Float64ToStr(float64(order.CommissionAmount) / 100),
  83. Title: title,
  84. Payment: utils.Float64ToStr(float64(order.PayAmount) / 100),
  85. Pvd: "tikTok_life",
  86. Img: img,
  87. IsShare: isShare,
  88. }
  89. if order.SettleFinish || order.Status != 2 {
  90. var amount int64 = 0
  91. isEnd := 1
  92. var endTime int64 = 0
  93. settleOrders, ok := order.SettleOrders.([]interface{})
  94. if ok {
  95. for _, v := range settleOrders {
  96. tmp, ok := v.(map[string]interface{})
  97. if ok == false || utils.AnyToInt64(tmp["status"]) < 3 {
  98. isEnd = 0
  99. }
  100. if ok && utils.AnyToInt64(tmp["status"]) == 3 {
  101. endTime = utils.AnyToInt64(tmp["settle_time"])
  102. amount += utils.AnyToInt64(tmp["settle_amount"])
  103. }
  104. }
  105. }
  106. if ok == false || len(settleOrders) == 0 {
  107. isEnd = 0
  108. }
  109. if isEnd == 1 {
  110. ord.Status = "订单结算"
  111. if order.Status == 5 {
  112. ord.Status = "部分结算"
  113. }
  114. ord.PlatformSettleTime = int(endTime)
  115. if ord.PlatformSettleTime == 0 {
  116. ord.PlatformSettleTime = ord.UpdateTime
  117. }
  118. ord.RealCommission = utils.Float64ToStr(float64(amount) / 100)
  119. }
  120. }
  121. one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd)
  122. if one == nil {
  123. insertOne, err := db.ZhimengDb.InsertOne(ord)
  124. fmt.Println(insertOne)
  125. fmt.Println(err)
  126. } else {
  127. ord.SettleTime = one.SettleTime
  128. if one.PlatformSettleTime > 0 {
  129. ord.PlatformSettleTime = one.PlatformSettleTime
  130. }
  131. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
  132. }
  133. return
  134. }