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

112 lines
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 HwOrderSettle() {
  11. day := time.Now().Day()
  12. if day < 15 {
  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.GetHwOrderList(arg)
  27. if len(order) == 0 {
  28. return
  29. }
  30. fmt.Println(utils.SerializeStr(order))
  31. platformMap := map[string]string{
  32. "starbucks": "星巴克", "movie": "电影", "mcdonald": "麦当劳", "nayuki": "奈雪", "luckin": "瑞幸咖啡", "pizza": "必胜客",
  33. "pagoda": "百果园", "burger_king": "汉堡王", "heytea": "喜茶", "to_kfc": "肯德基", "wallace": "华莱士", "flowerCake": "鲜花", "delivery": "比价寄", "tourism": "出游",
  34. }
  35. for _, v := range order {
  36. fmt.Println("=================00")
  37. // 加锁 防止并发提取
  38. mutexKey := fmt.Sprintf("hw_order_settle3:%d", v.Id)
  39. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
  40. if err != nil {
  41. fmt.Println("=================0")
  42. fmt.Println(err)
  43. continue
  44. }
  45. if withdrawAvailable != "OK" {
  46. fmt.Println("=================1")
  47. continue
  48. }
  49. if v.SettleTime > 0 {
  50. fmt.Println("=================2")
  51. continue
  52. }
  53. //加到上月结算
  54. if v.Uid == 0 {
  55. fmt.Println("=================3")
  56. continue
  57. }
  58. masterDb := db.MasterDb{}
  59. masterDb.Set()
  60. master := masterDb.GetMaster(utils.IntToStr(v.Uid))
  61. if master == nil {
  62. fmt.Println("=================4")
  63. continue
  64. }
  65. masterAmountDb := db.MasterAmountDb{}
  66. masterAmountDb.Set()
  67. amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), v.ExtendUid, "playlet")
  68. if amount == nil {
  69. fmt.Println("=================5")
  70. continue
  71. }
  72. if v.Commission <= 0 {
  73. v.SettleTime = int(time.Now().Unix())
  74. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  75. continue
  76. }
  77. oldAmount := amount.LastMonthAmount
  78. amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + v.Commission)
  79. update := masterAmountDb.MasterAmountUpdate(amount.Id, amount)
  80. if update == false {
  81. fmt.Println("=================7")
  82. continue
  83. }
  84. var tmp = model.MasterLastMonthAmountFlow{
  85. Uid: utils.IntToStr(master.Id),
  86. Time: time.Now(),
  87. BeforeAmount: oldAmount,
  88. Amount: utils.Float64ToStr(v.Commission),
  89. AfterAmount: amount.LastMonthAmount,
  90. Platform: v.Type,
  91. Oid: v.Oid,
  92. Title: platformMap[v.Type] + "结算",
  93. FlowType: v.Type + "_settle",
  94. ExtendUid: v.ExtendUid,
  95. }
  96. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  97. masterLastMonthAmountFlowDb.Set()
  98. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
  99. v.SettleTime = int(time.Now().Unix())
  100. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  101. }
  102. return
  103. }