智盟项目
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

97 righe
2.5 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 PlayletOrderSettle() {
  11. day := time.Now().Day()
  12. if day < 5 {
  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": time.Unix(month["start"], 0).Format("2006-01-02 15:04:05"),
  23. "p": "1",
  24. "size": "100",
  25. }
  26. playletSaleOrderDb := db.PlayletSaleOrderDb{}
  27. playletSaleOrderDb.Set()
  28. order := playletSaleOrderDb.GetPlayletVideoOrderList(arg)
  29. if len(order) == 0 {
  30. return
  31. }
  32. fmt.Println(utils.SerializeStr(order))
  33. for _, v := range order {
  34. // 加锁 防止并发提取
  35. mutexKey := fmt.Sprintf("playlet_order_settle1:%s", v.CustomOid)
  36. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
  37. if err != nil {
  38. fmt.Println(err)
  39. continue
  40. }
  41. if withdrawAvailable != "OK" {
  42. continue
  43. }
  44. if v.SettleTime > 0 {
  45. continue
  46. }
  47. //加到上月结算
  48. if v.Uid == "" || v.Uid == "0" {
  49. continue
  50. }
  51. masterDb := db.MasterDb{}
  52. masterDb.Set()
  53. master := masterDb.GetMaster(v.Uid)
  54. if master == nil {
  55. continue
  56. }
  57. masterAmountDb := db.MasterAmountDb{}
  58. masterAmountDb.Set()
  59. amount := masterAmountDb.GetMasterAmount(utils.IntToStr(master.Id), "playlet")
  60. if amount == nil {
  61. continue
  62. }
  63. if utils.StrToFloat64(v.Commission) <= 0 {
  64. v.SettleTime = int(time.Now().Unix())
  65. playletSaleOrderDb.PlayletVideoOrderUpdate(v.Id, &v)
  66. continue
  67. }
  68. oldAmount := amount.LastMonthAmount
  69. amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.Commission))
  70. update := masterAmountDb.MasterAmountUpdate(master.Id, amount)
  71. if update == false {
  72. continue
  73. }
  74. var tmp = model.MasterLastMonthAmountFlow{
  75. Uid: utils.IntToStr(master.Id),
  76. Time: time.Now(),
  77. BeforeAmount: oldAmount,
  78. Amount: v.Commission,
  79. AfterAmount: amount.LastMonthAmount,
  80. Platform: "playlet",
  81. Oid: v.Oid,
  82. Title: "短剧订单结算",
  83. FlowType: "playlet_settle",
  84. ExtendUid: master.ExtendUid,
  85. }
  86. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  87. masterLastMonthAmountFlowDb.Set()
  88. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
  89. v.SettleTime = int(time.Now().Unix())
  90. playletSaleOrderDb.PlayletVideoOrderUpdate(v.Id, &v)
  91. }
  92. return
  93. }