蛋蛋星球-客户端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

svc_video.go 3.9 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 VideoBase(c *gin.Context) {
  17. videoBase := GetSysCfgStr("video_base")
  18. var res = md.VideoBaseData{
  19. Reward: gjson.Get(videoBase, "reward").String(),
  20. Total: gjson.Get(videoBase, "total").String(),
  21. Timer: gjson.Get(videoBase, "timer").String(),
  22. Leave: gjson.Get(videoBase, "total").String(),
  23. Sum: "0.00",
  24. CoinName: "活跃值",
  25. Interval: gjson.Get(videoBase, "interval").String(),
  26. }
  27. user := GetUser(c)
  28. //剩余次数
  29. NewVideoTotalDb := implement.NewVideoTotalDb(db.Db)
  30. total, _ := NewVideoTotalDb.GetVideoTotal(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 VideoReward(c *gin.Context) {
  48. var args md.VideoRewardRequest
  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. videoBase := GetSysCfgStr("video_base")
  55. sess := eg.NewSession()
  56. defer sess.Close()
  57. sess.Begin()
  58. user := GetUser(c)
  59. NewVideoTotalDb := implement.NewVideoTotalDb(db.Db)
  60. total, _ := NewVideoTotalDb.GetVideoTotalSess(sess, utils.Int64ToStr(user.Id), time.Now().Format("20060102"))
  61. if total == nil {
  62. total = &model.VideoTotal{
  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(videoBase, "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.EggEnergyVideoRewardPersonalActiveCoin.String(),
  96. TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin),
  97. CoinId: eggData.PersonEggPointsCoinId,
  98. Uid: user.Id,
  99. Amount: utils.StrToFloat64(gjson.Get(videoBase, "reward").String()),
  100. }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData)
  101. if err != nil {
  102. ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{
  103. Kind: "add",
  104. Title: enum.EggEnergyVideoRewardPersonalActiveCoin.String(),
  105. TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin),
  106. CoinId: eggData.PersonEggPointsCoinId,
  107. Uid: user.Id,
  108. Amount: utils.StrToFloat64(gjson.Get(videoBase, "reward").String()),
  109. }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData)
  110. }
  111. }
  112. e.OutSuc(c, "success", nil)
  113. return
  114. }