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

213 regels
5.7 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/haodanku"
  8. "fmt"
  9. "strings"
  10. "time"
  11. )
  12. func HandankuXianyu() {
  13. pvdTimeKey := "haodanku_xianyu_time"
  14. // 获得最后时间
  15. latest := offical.SysCfgByKey(pvdTimeKey)
  16. if latest == nil {
  17. offical.DbsSysCfgInserts(pvdTimeKey, time.Now().String())
  18. latest = offical.SysCfgByKey(pvdTimeKey)
  19. }
  20. // 所有时间都是在操作秒数
  21. now := time.Now().Unix()
  22. timeStr := latest.V
  23. fmt.Println(timeStr)
  24. past := utils.TimeParseStd(timeStr).Unix()
  25. // 如果上次记录超过30天或者 过去时间大于当前时间戳, 把时间设置为此前20分钟
  26. if past > now {
  27. past = now
  28. }
  29. var (
  30. beginTime int64 = 0
  31. endTime int64 = 0
  32. pageNo int = 1
  33. pageSize int = 50
  34. )
  35. //怕时间不是走最新的
  36. leave := now - past
  37. if leave > 500 {
  38. leave = 0
  39. }
  40. past = past + leave
  41. beginTime = past - 20*60
  42. endTime = past
  43. if endTime > now {
  44. endTime = now
  45. }
  46. for {
  47. var err error
  48. count := OrdersHaodankuXianyuGet(pageNo, pageSize, beginTime, endTime)
  49. if err != nil || count == 0 {
  50. goto ChkArg
  51. }
  52. if count > 0 {
  53. count = pageSize
  54. }
  55. // 判断是否分页已经全部取完了
  56. if count == pageSize {
  57. pageNo++
  58. fmt.Println("========蝉选下一页========" + utils.IntToStr(pageNo))
  59. continue
  60. }
  61. ChkArg:
  62. // 查询完后重置时间, 最后查询时间
  63. if endTime < now {
  64. pageNo = 1
  65. offical.DbsSysCfgUpdate(pvdTimeKey, utils.TimeToStr(endTime))
  66. beginTime = endTime
  67. endTime = endTime + 20*60
  68. if endTime > now {
  69. endTime = now
  70. }
  71. continue
  72. }
  73. break
  74. }
  75. offical.DbsSysCfgUpdate(pvdTimeKey, time.Unix(now, 0).Format("2006-01-02 15:04:05"))
  76. }
  77. var haodankuXianyuStationState = map[string]string{
  78. "4": "订单付款",
  79. "3": "订单退款",
  80. "2": "订单成功",
  81. }
  82. func OrdersHaodankuXianyuGet(page, pageSize int, sTime, eTime int64) int {
  83. tikTokArgs := map[string]string{
  84. "date_type": "4",
  85. "back": utils.IntToStr(pageSize),
  86. "min_id": utils.IntToStr(page),
  87. "start_date": utils.Int64ToStr(time.Unix(sTime, 0).Unix()),
  88. "end_date": utils.Int64ToStr(time.Unix(eTime, 0).Unix()),
  89. }
  90. order := haodanku.HaodankuXianyuOrder(tikTokArgs)
  91. for _, v := range order {
  92. if v.ChannelCode == "" || v.OrderStatus == "1" {
  93. continue
  94. }
  95. isShare := 0
  96. if strings.Contains(v.ChannelCode, "s") {
  97. isShare = 1
  98. }
  99. v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "o", "")
  100. v.ChannelCode = strings.ReplaceAll(v.ChannelCode, "s", "")
  101. ex := strings.Split(v.ChannelCode, "u")
  102. if len(ex) != 2 {
  103. continue
  104. }
  105. mid := ""
  106. uid := ""
  107. one := db.GetLifeOrderByOne1(utils.AnyToString(v.TradeId), "xianyu")
  108. if one != nil {
  109. isShare = one.IsShare
  110. mid = utils.IntToStr(one.Uid)
  111. uid = utils.IntToStr(one.StationUid)
  112. } else {
  113. mid = ex[0]
  114. uid = ex[1]
  115. }
  116. if mid == "" || uid == "" {
  117. continue
  118. }
  119. var ord = &model.LifeOrder{
  120. Oid: utils.StrToInt64(utils.OrderUUID(utils.StrToInt(uid))),
  121. Uid: utils.StrToInt(mid),
  122. StationUid: utils.StrToInt(uid),
  123. PvdOid: utils.AnyToString(v.TradeId),
  124. Status: haodankuXianyuStationState[v.OrderStatus],
  125. UpdateTime: int(time.Now().Unix()),
  126. Commission: v.PredictMoney,
  127. Title: utils.AnyToString(v.ItemTitle),
  128. Payment: v.PayPrice,
  129. Pvd: "xianyu",
  130. Img: v.ItemImg,
  131. IsShare: isShare,
  132. Gid: v.TradeId,
  133. }
  134. if v.CreateTime != "" {
  135. ord.CreateTime = int(utils.TimeStdParseUnix(v.CreateTime))
  136. }
  137. if v.EarningTime != "" {
  138. ord.PlatformSettleTime = int(utils.TimeStdParseUnix(utils.AnyToString(v.EarningTime)))
  139. }
  140. if utils.StrToFloat64(v.ActualMoney) > 0 {
  141. ord.RealCommission = v.ActualMoney
  142. }
  143. if v.PaidTime != "" && v.OrderStatus == "3" {
  144. ord.Status = "订单退款"
  145. }
  146. if v.SettledStatus == 1 && v.OrderStatus == "2" && v.EarningTime != "" {
  147. ord.Status = "订单结算"
  148. }
  149. if v.SettledStatus == 2 {
  150. ord.RealCommission = "0"
  151. ord.Commission = "0"
  152. }
  153. if one == nil {
  154. insertOne, err := db.ZhimengDb.InsertOne(ord)
  155. fmt.Println(insertOne)
  156. fmt.Println(err)
  157. } else {
  158. ord.SettleTime = one.SettleTime
  159. if one.PlatformSettleTime > 0 {
  160. ord.PlatformSettleTime = one.PlatformSettleTime
  161. }
  162. if one.Status == "违规订单" {
  163. ord.Status = "违规订单"
  164. }
  165. if ord.SettleTime > 0 && ord.Status == "订单退款" {
  166. ord.SettleTime = 0
  167. masterDb := db.MasterDb{}
  168. masterDb.Set()
  169. master := masterDb.GetMaster(utils.IntToStr(ord.Uid))
  170. if master != nil {
  171. masterAmountDb := db.MasterAmountDb{}
  172. masterAmountDb.Set()
  173. amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(ord.ExtendUid), "playlet")
  174. if amount != nil {
  175. oldAmount := amount.Amount
  176. amount.Amount = utils.Float64ToStr(utils.StrToFloat64(amount.Amount) - utils.StrToFloat64(ord.RealCommission))
  177. update := masterAmountDb.MasterAmountUpdate(amount.Id, amount)
  178. if update {
  179. var tmp = model.MasterAmountFlow{
  180. Uid: utils.IntToStr(ord.Uid),
  181. Time: time.Now(),
  182. BeforeAmount: oldAmount,
  183. Amount: ord.RealCommission,
  184. AfterAmount: amount.Amount,
  185. Platform: "playlet",
  186. Oid: utils.Int64ToStr(ord.Oid),
  187. Title: "订单退款扣除",
  188. FlowType: "order_refund_deduct",
  189. IncomeType: 0,
  190. ExtendUid: utils.IntToStr(ord.ExtendUid),
  191. }
  192. masterAmountFlowDb := db.MasterAmountFlowDb{}
  193. masterAmountFlowDb.Set()
  194. masterAmountFlowDb.MasterAmountFlowInsert(&tmp)
  195. }
  196. }
  197. }
  198. }
  199. db.ZhimengDb.Where("id=?", one.Id).AllCols().Update(ord)
  200. }
  201. }
  202. return len(order)
  203. }