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

87 regels
2.7 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. coin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.PersonEggPointsCoinId)
  39. if coin != nil {
  40. res.Sum = coin.Amount
  41. }
  42. e.OutSuc(c, res, nil)
  43. return
  44. }
  45. func VideoReward(c *gin.Context) {
  46. var args md.VideoRewardRequest
  47. if err := c.ShouldBindJSON(&args); err != nil {
  48. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  49. return
  50. }
  51. videoBase := GetSysCfgStr("video_base")
  52. user := GetUser(c)
  53. //判断到时间领了没
  54. timeKey := "video.timer:" + utils.Int64ToStr(user.Id)
  55. timeString, _ := cache.GetString(timeKey)
  56. if timeString == "1" {
  57. e.OutErr(c, 400, e.NewErr(400, "未到时间领取"))
  58. return
  59. }
  60. cache.SetEx(timeKey, "1", utils.StrToInt(gjson.Get(videoBase, "interval").String()))
  61. //判断数量 读取缓存的
  62. numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id)
  63. numString, _ := cache.GetString(numKey)
  64. Leave := utils.StrToInt(gjson.Get(videoBase, "total").String()) - utils.StrToInt(numString)
  65. if Leave-1 < 0 {
  66. e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
  67. return
  68. }
  69. ch, err := rabbit.Cfg.Pool.GetChannel()
  70. if err == nil {
  71. defer ch.Release()
  72. err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  73. Uid: utils.Int64ToStr(user.Id),
  74. }, md.EggVideoReward)
  75. if err != nil {
  76. ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  77. Uid: utils.Int64ToStr(user.Id),
  78. }, md.EggVideoReward)
  79. }
  80. }
  81. e.OutSuc(c, "success", nil)
  82. return
  83. }