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

svc_playlet.go 4.5 KiB

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