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

139 lines
3.6 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. split := strings.Split(utils.AnyToString(userId), "_")
  54. if len(split) < 3 {
  55. return
  56. }
  57. mid := split[2]
  58. puid := ""
  59. if len(split) == 4 {
  60. puid = split[2]
  61. }
  62. uid := split[1]
  63. title := ""
  64. img := ""
  65. if len(order.ProductList) > 0 {
  66. title = order.ProductList[0].Name
  67. img = order.ProductList[0].Img
  68. }
  69. var ord = &model.GuideOrder{
  70. Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))),
  71. Uid: utils.StrToInt(mid),
  72. ExtendUid: utils.StrToInt(puid),
  73. StationUid: utils.StrToInt(uid),
  74. PvdOid: order.OrderId,
  75. PvdParentOid: order.RootOrderId,
  76. Status: statusArr[order.Status],
  77. CreateTime: order.PayTime,
  78. UpdateTime: int(time.Now().Unix()),
  79. Commission: utils.Float64ToStr(float64(order.CommissionAmount) / 100),
  80. Title: title,
  81. Payment: utils.Float64ToStr(float64(order.PayAmount) / 100),
  82. Pvd: "tikTok_life",
  83. Img: img,
  84. IsShare: isShare,
  85. }
  86. if order.SettleFinish || order.Status != 2 {
  87. var amount int64 = 0
  88. isEnd := 1
  89. var endTime int64 = 0
  90. settleOrders, ok := order.SettleOrders.([]interface{})
  91. if ok {
  92. for _, v := range settleOrders {
  93. tmp, ok := v.(map[string]interface{})
  94. if ok == false || utils.AnyToInt64(tmp["status"]) < 3 {
  95. isEnd = 0
  96. }
  97. if ok && utils.AnyToInt64(tmp["status"]) == 3 {
  98. endTime = utils.AnyToInt64(tmp["settle_time"])
  99. amount += utils.AnyToInt64(tmp["settle_amount"])
  100. }
  101. }
  102. }
  103. if ok == false || len(settleOrders) == 0 {
  104. isEnd = 0
  105. }
  106. if isEnd == 1 {
  107. ord.Status = "订单结算"
  108. if order.Status == 5 {
  109. ord.Status = "部分结算"
  110. }
  111. ord.PlatformSettleTime = int(endTime)
  112. if ord.PlatformSettleTime == 0 {
  113. ord.PlatformSettleTime = ord.UpdateTime
  114. }
  115. ord.RealCommission = utils.Float64ToStr(float64(amount) / 100)
  116. }
  117. }
  118. one := db.GetGuideOrderByOne(ord.PvdOid, utils.IntToStr(ord.Uid), ord.Pvd)
  119. if one == nil {
  120. insertOne, err := db.ZhimengDb.InsertOne(ord)
  121. fmt.Println(insertOne)
  122. fmt.Println(err)
  123. } else {
  124. ord.SettleTime = one.SettleTime
  125. if one.PlatformSettleTime > 0 {
  126. ord.PlatformSettleTime = one.PlatformSettleTime
  127. }
  128. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
  129. }
  130. return
  131. }