蛋蛋星球-客户端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

117 строки
4.2 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. "github.com/gin-gonic/gin"
  10. "github.com/tidwall/gjson"
  11. "time"
  12. )
  13. func PlayletBase(c *gin.Context) {
  14. playletBase := GetSysCfgStr("playlet_base")
  15. playletIncentiveBase := GetSysCfgStr("playlet_incentive_base")
  16. var res = md.PlayletBaseData{
  17. Reward: gjson.Get(playletBase, "reward").String(),
  18. Total: gjson.Get(playletBase, "total").String(),
  19. FirstCount: gjson.Get(playletBase, "first_count").String(),
  20. SecondCount: gjson.Get(playletBase, "second_count").String(),
  21. Leave: gjson.Get(playletBase, "total").String(),
  22. DayOneCount: gjson.Get(playletBase, "day_one_count").String(),
  23. AndroidAdvId: gjson.Get(playletIncentiveBase, "android_adv_id").String(),
  24. IosAdvId: gjson.Get(playletIncentiveBase, "ios_adv_id").String(),
  25. Sum: "0.00",
  26. CoinName: "活跃值",
  27. }
  28. user := GetUser(c)
  29. //剩余次数
  30. sum, _ := db.Db.Where("uid=? and date=?", user.Id, time.Now().Format("20060102")).Sum(&model.PlayletTotal{}, "total")
  31. res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - int(sum))
  32. if utils.StrToInt(res.Leave) < 0 {
  33. res.Leave = "0"
  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 PlayletUnlockNum(c *gin.Context) {
  46. var args md.PlayletRewardRequest
  47. if err := c.ShouldBindJSON(&args); err != nil {
  48. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  49. return
  50. }
  51. playletBase := GetSysCfgStr("playlet_base")
  52. playletIncentiveBase := GetSysCfgStr("playlet_incentive_base")
  53. var res = md.PlayletBaseData{
  54. Reward: gjson.Get(playletBase, "reward").String(),
  55. Total: gjson.Get(playletBase, "total").String(),
  56. FirstCount: gjson.Get(playletBase, "first_count").String(),
  57. SecondCount: gjson.Get(playletBase, "second_count").String(),
  58. Leave: gjson.Get(playletBase, "total").String(),
  59. DayOneCount: gjson.Get(playletBase, "day_one_count").String(),
  60. AndroidAdvId: gjson.Get(playletIncentiveBase, "android_adv_id").String(),
  61. IosAdvId: gjson.Get(playletIncentiveBase, "ios_adv_id").String(),
  62. Sum: "0.00",
  63. CoinName: "活跃值",
  64. }
  65. user := GetUser(c)
  66. //剩余次数
  67. num := "0"
  68. sum, _ := db.Db.Where("uid=? and date=?", user.Id, time.Now().Format("20060102")).Sum(&model.PlayletTotal{}, "total")
  69. res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - int(sum))
  70. if utils.StrToInt(res.Leave) < 0 {
  71. res.Leave = "0"
  72. }
  73. if utils.StrToFloat64(res.Leave) > 0 { //总的还有 就判断单个剧还能不能看
  74. sumOne, _ := db.Db.Where("uid=? and date=? and short_id=?", user.Id, time.Now().Format("20060102"), args.Id).Sum(&model.PlayletTotal{}, "total")
  75. leaves := utils.StrToInt(res.DayOneCount) - int(sumOne)
  76. if leaves > 0 {
  77. num = res.SecondCount
  78. }
  79. }
  80. re := md.PlayletUnlockResp{Num: num}
  81. e.OutSuc(c, re, nil)
  82. return
  83. }
  84. func PlayletReward(c *gin.Context) {
  85. var args md.PlayletRewardRequest
  86. if err := c.ShouldBindJSON(&args); err != nil {
  87. e.OutErr(c, e.ERR_INVALID_ARGS, err)
  88. return
  89. }
  90. //playletBase := GetSysCfgStr("playlet_base")
  91. //user := GetUser(c)
  92. ////判断数量 读取缓存的
  93. //numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id)
  94. //numString, _ := cache.GetString(numKey)
  95. //Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - utils.StrToInt(numString)
  96. //if Leave-1 < 0 {
  97. // e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
  98. // return
  99. //}
  100. //ch, err := rabbit.Cfg.Pool.GetChannel()
  101. //if err == nil {
  102. // defer ch.Release()
  103. // err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  104. // Uid: utils.Int64ToStr(user.Id),
  105. // }, md.EggPlayletReward)
  106. // if err != nil {
  107. // ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
  108. // Uid: utils.Int64ToStr(user.Id),
  109. // }, md.EggPlayletReward)
  110. // }
  111. //}
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }