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

84 lines
2.2 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 MasterMonthSettle() {
  11. day := time.Now().Day()
  12. masterListCfgDb := db.MasterListCfgDb{}
  13. masterListCfgDb.Set()
  14. withdrawalDay := masterListCfgDb.MasterListCfgGetOneData("0", "withdrawal_day")
  15. if day < utils.StrToInt(withdrawalDay) {
  16. return
  17. }
  18. args := map[string]string{
  19. "p": "1",
  20. "size": "100",
  21. }
  22. masterAmountDb := db.MasterAmountDb{}
  23. masterAmountDb.Set()
  24. list := masterAmountDb.GetMasterAmountList(args)
  25. if list == nil {
  26. return
  27. }
  28. for _, v := range *list {
  29. mutexKey := fmt.Sprintf("master_month_settle:%d", v.Id)
  30. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
  31. if err != nil {
  32. continue
  33. }
  34. if withdrawAvailable != "OK" {
  35. continue
  36. }
  37. if utils.StrToFloat64(v.LastMonthAmount) <= 0 {
  38. continue
  39. }
  40. oldAmount := v.Amount
  41. oldLastMonthAmount := v.LastMonthAmount
  42. v.Amount = utils.Float64ToStr(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(v.LastMonthAmount))
  43. v.LastMonthAmount = "0"
  44. update := masterAmountDb.MasterAmountUpdate(v.Id, &v)
  45. if update == false {
  46. continue
  47. }
  48. var tmp = model.MasterAmountFlow{
  49. Uid: v.Uid,
  50. Time: time.Now(),
  51. BeforeAmount: oldAmount,
  52. Amount: oldLastMonthAmount,
  53. AfterAmount: v.Amount,
  54. Platform: "playlet",
  55. Oid: utils.IntToStr(v.Id),
  56. Title: "短剧上月结算佣金到账",
  57. FlowType: "last_month_playlet_settle",
  58. IncomeType: 0,
  59. }
  60. masterAmountFlowDb := db.MasterAmountFlowDb{}
  61. masterAmountFlowDb.Set()
  62. masterAmountFlowDb.MasterAmountFlowInsert(&tmp)
  63. var tmpLastMonth = model.MasterLastMonthAmountFlow{
  64. Uid: v.Uid,
  65. Time: time.Now(),
  66. BeforeAmount: oldLastMonthAmount,
  67. Amount: oldLastMonthAmount,
  68. AfterAmount: v.LastMonthAmount,
  69. Platform: "playlet",
  70. Oid: utils.IntToStr(v.Id),
  71. Title: "短剧上月结算佣金转到余额",
  72. FlowType: "last_month_playlet_settle",
  73. IncomeType: 1,
  74. }
  75. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  76. masterLastMonthAmountFlowDb.Set()
  77. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmpLastMonth)
  78. }
  79. }