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

93 lines
3.0 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/md"
  6. "applet/app/utils"
  7. "applet/app/utils/cache"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  9. "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
  10. "github.com/gin-gonic/gin"
  11. "github.com/tidwall/gjson"
  12. "time"
  13. )
  14. func VideoBase(c *gin.Context) {
  15. videoBase := GetSysCfgStr("video_base")
  16. var res = md.VideoBaseData{
  17. Reward: gjson.Get(videoBase, "reward").String(),
  18. Total: gjson.Get(videoBase, "total").String(),
  19. Timer: gjson.Get(videoBase, "timer").String(),
  20. Leave: gjson.Get(videoBase, "total").String(),
  21. Sum: "0.00",
  22. CoinName: "活跃值",
  23. Interval: gjson.Get(videoBase, "interval").String(),
  24. }
  25. user := GetUser(c)
  26. //剩余次数
  27. NewVideoTotalDb := implement.NewVideoTotalDb(db.Db)
  28. total, _ := NewVideoTotalDb.GetVideoTotal(utils.Int64ToStr(user.Id), time.Now().Format("20060102"))
  29. if total != nil {
  30. res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - total.Total)
  31. if utils.StrToInt(res.Leave) < 0 {
  32. res.Leave = "0"
  33. }
  34. }
  35. NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
  36. eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne()
  37. NewUserVirtualAmountDb := implement.NewUserVirtualAmountDb(db.Db)
  38. var eggPoints float64 = 0
  39. coin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.PersonEggPointsCoinId)
  40. if coin != nil {
  41. eggPoints += utils.StrToFloat64(coin.Amount)
  42. }
  43. TeamEggPointsCoin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.TeamEggPointsCoinId)
  44. if TeamEggPointsCoin != nil {
  45. eggPoints += utils.StrToFloat64(TeamEggPointsCoin.Amount)
  46. }
  47. res.Sum = utils.Float64ToStrPrec8(eggPoints)
  48. e.OutSuc(c, res, nil)
  49. return
  50. }
  51. func VideoReward(c *gin.Context) {
  52. var args md.VideoRewardRequest
  53. if err := c.ShouldBindJSON(&args); err != nil {
  54. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  55. return
  56. }
  57. videoBase := GetSysCfgStr("video_base")
  58. user := GetUser(c)
  59. //判断到时间领了没
  60. timeKey := "video.timer:" + utils.Int64ToStr(user.Id)
  61. timeString, _ := cache.GetString(timeKey)
  62. if timeString == "1" {
  63. e.OutErr(c, 400, e.NewErr(400, "未到时间领取"))
  64. return
  65. }
  66. cache.SetEx(timeKey, "1", utils.StrToInt(gjson.Get(videoBase, "interval").String()))
  67. //判断数量 读取缓存的
  68. numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id)
  69. numString, _ := cache.GetString(numKey)
  70. Leave := utils.StrToInt(gjson.Get(videoBase, "total").String()) - utils.StrToInt(numString)
  71. if Leave-1 < 0 {
  72. e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
  73. return
  74. }
  75. ch, err := rabbit.Cfg.Pool.GetChannel()
  76. if err == nil {
  77. defer ch.Release()
  78. err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  79. Uid: utils.Int64ToStr(user.Id),
  80. }, md.EggVideoReward)
  81. if err != nil {
  82. ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  83. Uid: utils.Int64ToStr(user.Id),
  84. }, md.EggVideoReward)
  85. }
  86. }
  87. e.OutSuc(c, "success", nil)
  88. return
  89. }