蛋蛋星球-客户端
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.
 
 
 
 
 

120 lines
4.0 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  10. md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md"
  11. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  12. "github.com/gin-gonic/gin"
  13. "github.com/tidwall/gjson"
  14. "time"
  15. )
  16. func PlayletBase(c *gin.Context) {
  17. playletBase := GetSysCfgStr("playlet_base")
  18. var res = md.PlayletBaseData{
  19. Reward: gjson.Get(playletBase, "reward").String(),
  20. Total: gjson.Get(playletBase, "total").String(),
  21. FirstCount: gjson.Get(playletBase, "first_count").String(),
  22. SecondCount: gjson.Get(playletBase, "second_count").String(),
  23. Leave: gjson.Get(playletBase, "total").String(),
  24. Sum: "0.00",
  25. CoinName: "活跃值",
  26. }
  27. user := GetUser(c)
  28. //剩余次数
  29. NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db)
  30. total, _ := NewPlayletTotalDb.GetPlayletTotal(utils.Int64ToStr(user.Id), time.Now().Format("20060102"))
  31. if total != nil {
  32. res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - total.Total)
  33. if utils.StrToInt(res.Leave) < 0 {
  34. res.Leave = "0"
  35. }
  36. }
  37. NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  38. eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne()
  39. NewUserVirtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
  40. coin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.PersonEggPointsCoinId)
  41. if coin != nil {
  42. res.Sum = coin.Amount
  43. }
  44. e.OutSuc(c, res, nil)
  45. return
  46. }
  47. func PlayletReward(c *gin.Context) {
  48. var args md.PlayletRewardRequest
  49. if err := c.ShouldBindJSON(&args); err != nil {
  50. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  51. return
  52. }
  53. eg := db.Db
  54. playletBase := GetSysCfgStr("playlet_base")
  55. sess := eg.NewSession()
  56. defer sess.Close()
  57. sess.Begin()
  58. user := GetUser(c)
  59. NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db)
  60. total, _ := NewPlayletTotalDb.GetPlayletTotalSess(sess, utils.Int64ToStr(user.Id), time.Now().Format("20060102"))
  61. if total == nil {
  62. total = &model.PlayletTotal{
  63. Uid: int(user.Id),
  64. Date: utils.StrToInt(time.Now().Format("20060102")),
  65. Time: time.Now(),
  66. }
  67. insert, err := sess.Insert(total)
  68. if insert == 0 || err != nil {
  69. sess.Rollback()
  70. e.OutErr(c, 400, e.NewErr(400, "获取奖励失败"))
  71. return
  72. }
  73. }
  74. Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - total.Total
  75. if Leave-1 < 0 {
  76. sess.Rollback()
  77. e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
  78. return
  79. }
  80. total.Total++
  81. update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total)
  82. if update == 0 || err2 != nil {
  83. sess.Rollback()
  84. e.OutErr(c, 400, e.NewErr(400, "获取奖励失败"))
  85. return
  86. }
  87. sess.Commit()
  88. ch, err := rabbit.Cfg.Pool.GetChannel()
  89. if err == nil {
  90. defer ch.Release()
  91. NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  92. eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne()
  93. err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{
  94. Kind: "add",
  95. Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(),
  96. TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin),
  97. CoinId: eggData.PersonEggPointsCoinId,
  98. Uid: user.Id,
  99. Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()),
  100. }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData)
  101. if err != nil {
  102. ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{
  103. Kind: "add",
  104. Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(),
  105. TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin),
  106. CoinId: eggData.PersonEggPointsCoinId,
  107. Uid: user.Id,
  108. Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()),
  109. }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData)
  110. }
  111. }
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }