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

svc_master_month_settle.go 2.4 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. masterDb := db.MasterDb{}
  41. masterDb.Set()
  42. master := masterDb.GetMasterId(utils.StrToInt(v.Uid))
  43. if master == nil {
  44. continue
  45. }
  46. oldAmount := v.Amount
  47. oldLastMonthAmount := v.LastMonthAmount
  48. v.Amount = utils.Float64ToStr(utils.StrToFloat64(v.Amount) + utils.StrToFloat64(v.LastMonthAmount))
  49. v.LastMonthAmount = "0"
  50. update := masterAmountDb.MasterAmountUpdate(v.Id, &v)
  51. if update == false {
  52. continue
  53. }
  54. var tmp = model.MasterAmountFlow{
  55. Uid: v.Uid,
  56. Time: time.Now(),
  57. BeforeAmount: oldAmount,
  58. Amount: oldLastMonthAmount,
  59. AfterAmount: v.Amount,
  60. Platform: "playlet",
  61. Oid: utils.IntToStr(v.Id),
  62. Title: "上月结算佣金到账",
  63. FlowType: "last_month_playlet_settle",
  64. IncomeType: 0,
  65. ExtendUid: v.ExtendUid,
  66. }
  67. masterAmountFlowDb := db.MasterAmountFlowDb{}
  68. masterAmountFlowDb.Set()
  69. masterAmountFlowDb.MasterAmountFlowInsert(&tmp)
  70. var tmpLastMonth = model.MasterLastMonthAmountFlow{
  71. Uid: v.Uid,
  72. Time: time.Now(),
  73. BeforeAmount: oldLastMonthAmount,
  74. Amount: oldLastMonthAmount,
  75. AfterAmount: v.LastMonthAmount,
  76. Platform: "playlet",
  77. Oid: utils.IntToStr(v.Id),
  78. Title: "上月结算佣金转到余额",
  79. FlowType: "last_month_playlet_settle",
  80. IncomeType: 1,
  81. ExtendUid: v.ExtendUid,
  82. }
  83. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  84. masterLastMonthAmountFlowDb.Set()
  85. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmpLastMonth)
  86. }
  87. }