智盟项目
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

116 рядки
3.0 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/utils"
  6. "applet/app/utils/cache"
  7. "fmt"
  8. "time"
  9. )
  10. func LifeOrderSettle() {
  11. day := time.Now().Day()
  12. if day < 20 {
  13. return
  14. }
  15. month := utils.GetTimeRange("current_month")
  16. fmt.Println(month)
  17. arg := map[string]string{
  18. "status": "订单结算",
  19. "sort": "id desc",
  20. "is_to_settle": "1",
  21. "is_commission": "1",
  22. "to_settle_time": utils.Int64ToStr(month["start"]),
  23. "p": "1",
  24. "size": "100",
  25. }
  26. order := db.GetLifeOrderList(arg)
  27. if len(order) == 0 {
  28. return
  29. }
  30. fmt.Println(utils.SerializeStr(order))
  31. platformMap := map[string]string{
  32. "tikTok_life": "抖音本地生活",
  33. "csjp": "穿山甲抖音",
  34. "csjp_live": "穿山甲抖音直播商品",
  35. "kuaishou": "快手",
  36. "kuaishou_live": "快手直播商品",
  37. "meituan": "美团",
  38. }
  39. for _, v := range order {
  40. fmt.Println("=================00")
  41. // 加锁 防止并发提取
  42. mutexKey := fmt.Sprintf("life_order_settle3:%d", v.Id)
  43. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
  44. if err != nil {
  45. fmt.Println("=================0")
  46. fmt.Println(err)
  47. continue
  48. }
  49. if withdrawAvailable != "OK" {
  50. fmt.Println("=================1")
  51. continue
  52. }
  53. if v.SettleTime > 0 {
  54. fmt.Println("=================2")
  55. continue
  56. }
  57. //加到上月结算
  58. if v.Uid == 0 {
  59. fmt.Println("=================3")
  60. continue
  61. }
  62. masterDb := db.MasterDb{}
  63. masterDb.Set()
  64. master := masterDb.GetMaster(utils.IntToStr(v.Uid))
  65. if master == nil {
  66. fmt.Println("=================4")
  67. continue
  68. }
  69. masterAmountDb := db.MasterAmountDb{}
  70. masterAmountDb.Set()
  71. amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(v.ExtendUid), "playlet")
  72. if amount == nil {
  73. fmt.Println("=================5")
  74. continue
  75. }
  76. if utils.StrToFloat64(v.RealCommission) <= 0 {
  77. v.SettleTime = int(time.Now().Unix())
  78. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  79. continue
  80. }
  81. oldAmount := amount.LastMonthAmount
  82. amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.RealCommission))
  83. update := masterAmountDb.MasterAmountUpdate(amount.Id, amount)
  84. if update == false {
  85. fmt.Println("=================7")
  86. continue
  87. }
  88. var tmp = model.MasterLastMonthAmountFlow{
  89. Uid: utils.IntToStr(master.Id),
  90. Time: time.Now(),
  91. BeforeAmount: oldAmount,
  92. Amount: v.RealCommission,
  93. AfterAmount: amount.LastMonthAmount,
  94. Platform: v.Pvd,
  95. Oid: utils.Int64ToStr(v.Oid),
  96. Title: platformMap[v.Pvd] + "结算",
  97. FlowType: v.Pvd + "_settle",
  98. ExtendUid: utils.IntToStr(v.ExtendUid),
  99. }
  100. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  101. masterLastMonthAmountFlowDb.Set()
  102. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
  103. v.SettleTime = int(time.Now().Unix())
  104. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  105. }
  106. return
  107. }