智盟项目
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

100 linhas
2.5 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/db/model"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  8. "fmt"
  9. "time"
  10. )
  11. func LifeOrderSettle(arg map[string]string) {
  12. day := time.Now().Day()
  13. if day < 20 {
  14. return
  15. }
  16. order := db.GetLifeOrderList(arg)
  17. if len(order) == 0 {
  18. return
  19. }
  20. fmt.Println(utils.SerializeStr(order))
  21. platformMap := md.SettlePvd
  22. for _, v := range order {
  23. fmt.Println("=================00")
  24. // 加锁 防止并发提取
  25. mutexKey := fmt.Sprintf("life_order_settle3:%d", v.Id)
  26. withdrawAvailable, err := cache.Do("SET", mutexKey, 1, "EX", 1800, "NX")
  27. if err != nil {
  28. fmt.Println("=================0")
  29. fmt.Println(err)
  30. continue
  31. }
  32. if withdrawAvailable != "OK" {
  33. fmt.Println("=================1")
  34. continue
  35. }
  36. if v.SettleTime > 0 {
  37. fmt.Println("=================2")
  38. continue
  39. }
  40. //加到上月结算
  41. if v.Uid == 0 {
  42. fmt.Println("=================3")
  43. continue
  44. }
  45. masterDb := db.MasterDb{}
  46. masterDb.Set()
  47. master := masterDb.GetMaster(utils.IntToStr(v.Uid))
  48. if master == nil {
  49. fmt.Println("=================4")
  50. continue
  51. }
  52. masterAmountDb := db.MasterAmountDb{}
  53. masterAmountDb.Set()
  54. amount := masterAmountDb.GetMasterAmountByExtendUid(utils.IntToStr(master.Id), utils.IntToStr(v.ExtendUid), "playlet")
  55. if amount == nil {
  56. fmt.Println("=================5")
  57. continue
  58. }
  59. if utils.StrToFloat64(v.RealCommission) <= 0 {
  60. v.SettleTime = int(time.Now().Unix())
  61. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  62. continue
  63. }
  64. oldAmount := amount.LastMonthAmount
  65. amount.LastMonthAmount = utils.Float64ToStr(utils.StrToFloat64(amount.LastMonthAmount) + utils.StrToFloat64(v.RealCommission))
  66. update := masterAmountDb.MasterAmountUpdate(amount.Id, amount)
  67. if update == false {
  68. fmt.Println("=================7")
  69. continue
  70. }
  71. var tmp = model.MasterLastMonthAmountFlow{
  72. Uid: utils.IntToStr(master.Id),
  73. Time: time.Now(),
  74. BeforeAmount: oldAmount,
  75. Amount: v.RealCommission,
  76. AfterAmount: amount.LastMonthAmount,
  77. Platform: v.Pvd,
  78. Oid: utils.Int64ToStr(v.Oid),
  79. Title: platformMap[v.Pvd] + "结算",
  80. FlowType: v.Pvd + "_settle",
  81. ExtendUid: utils.IntToStr(v.ExtendUid),
  82. }
  83. masterLastMonthAmountFlowDb := db.MasterLastMonthAmountFlowDb{}
  84. masterLastMonthAmountFlowDb.Set()
  85. masterLastMonthAmountFlowDb.MasterLastMonthAmountFlowInsert(&tmp)
  86. v.SettleTime = int(time.Now().Unix())
  87. db.ZhimengDb.Where("id=?", v.Id).Update(&v)
  88. }
  89. return
  90. }