Browse Source

短剧

master
huangjiajun 1 week ago
parent
commit
9ba15efdac
4 changed files with 89 additions and 34 deletions
  1. +15
    -0
      app/hdl/hdl_playlet.go
  2. +6
    -1
      app/md/md_playlet.go
  3. +3
    -2
      app/router/router.go
  4. +65
    -31
      app/svc/svc_playlet.go

+ 15
- 0
app/hdl/hdl_playlet.go View File

@@ -19,6 +19,21 @@ func PlayletBase(c *gin.Context) {
svc.PlayletBase(c)
}

// PlayletUnlockNum
// @Summary 短剧-解锁数量
// @Tags 短视频
// @Description 短剧-解锁数量
// @Accept json
// @Produce json
// @param Authorization header string true "验证参数Bearer和token空格拼接"
// @Param req body md.PlayletUnlockRequest true "参数"
// @Success 200 {object} md.PlayletUnlockResp "具体数据"
// @Failure 400 {object} md.Response "具体错误"
// @Router /api/v1/playlet/unlockNum [post]
func PlayletUnlockNum(c *gin.Context) {
svc.PlayletUnlockNum(c)
}

// PlayletReward
// @Summary 短剧-保存
// @Tags 短视频


+ 6
- 1
app/md/md_playlet.go View File

@@ -8,7 +8,6 @@ type PlayletBaseData struct {
Leave string `json:"leave" example:"剩余次数"`
Sum string `json:"sum" example:"奖励总数"`
CoinName string `json:"coin_name" example:"积分名称"`
DayAllCount string `json:"day_all_count" example:"每天全部短剧解锁次数"`
DayOneCount string `json:"day_one_count" example:"每天每个短剧解锁次数"`
AndroidAdvId string `json:"android_adv_id" example:"安卓激励视频广告位"`
IosAdvId string `json:"ios_adv_id" example:"iOS激励视频广告位"`
@@ -16,3 +15,9 @@ type PlayletBaseData struct {
type PlayletRewardRequest struct {
Id string `json:"id" example:"广告id"`
}
type PlayletUnlockRequest struct {
Id string `json:"id" example:"短剧id"`
}
type PlayletUnlockResp struct {
Num string `json:"num"`
}

+ 3
- 2
app/router/router.go View File

@@ -195,8 +195,9 @@ func route(r *gin.RouterGroup) {
}
rPlaylet := r.Group("/playlet") //短剧
{
rPlaylet.GET("/base", hdl.PlayletBase) //基础数据
rPlaylet.POST("/reward", hdl.PlayletReward) //奖励
rPlaylet.GET("/base", hdl.PlayletBase) //基础数据
rPlaylet.POST("/unlockNum", hdl.PlayletUnlockNum) //基础数据
rPlaylet.POST("/reward", hdl.PlayletReward) //奖励
}
}



+ 65
- 31
app/svc/svc_playlet.go View File

@@ -5,9 +5,8 @@ import (
"applet/app/e"
"applet/app/md"
"applet/app/utils"
"applet/app/utils/cache"
"code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
"code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit"
"code.fnuoos.com/EggPlanet/egg_models.git/src/model"
"github.com/gin-gonic/gin"
"github.com/tidwall/gjson"
"time"
@@ -15,28 +14,25 @@ import (

func PlayletBase(c *gin.Context) {
playletBase := GetSysCfgStr("playlet_base")
playletIncentiveBase := GetSysCfgStr("playlet_incentive_base")
var res = md.PlayletBaseData{
Reward: gjson.Get(playletBase, "reward").String(),
Total: gjson.Get(playletBase, "total").String(),
FirstCount: gjson.Get(playletBase, "first_count").String(),
SecondCount: gjson.Get(playletBase, "second_count").String(),
Leave: gjson.Get(playletBase, "total").String(),
DayAllCount: gjson.Get(playletBase, "day_all_count").String(),
DayOneCount: gjson.Get(playletBase, "day_one_count").String(),
AndroidAdvId: gjson.Get(playletBase, "android_adv_id").String(),
IosAdvId: gjson.Get(playletBase, "ios_adv_id").String(),
AndroidAdvId: gjson.Get(playletIncentiveBase, "android_adv_id").String(),
IosAdvId: gjson.Get(playletIncentiveBase, "ios_adv_id").String(),
Sum: "0.00",
CoinName: "活跃值",
}
user := GetUser(c)
//剩余次数
NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db)
total, _ := NewPlayletTotalDb.GetPlayletTotal(utils.Int64ToStr(user.Id), time.Now().Format("20060102"))
if total != nil {
res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - total.Total)
if utils.StrToInt(res.Leave) < 0 {
res.Leave = "0"
}
sum, _ := db.Db.Where("uid=? and date=?", user.Id, time.Now().Format("20060102")).Sum(&model.PlayletTotal{}, "total")
res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - int(sum))
if utils.StrToInt(res.Leave) < 0 {
res.Leave = "0"
}
NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db)
eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne()
@@ -48,35 +44,73 @@ func PlayletBase(c *gin.Context) {
e.OutSuc(c, res, nil)
return
}

func PlayletReward(c *gin.Context) {
func PlayletUnlockNum(c *gin.Context) {
var args md.PlayletRewardRequest
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
playletBase := GetSysCfgStr("playlet_base")
playletIncentiveBase := GetSysCfgStr("playlet_incentive_base")
var res = md.PlayletBaseData{
Reward: gjson.Get(playletBase, "reward").String(),
Total: gjson.Get(playletBase, "total").String(),
FirstCount: gjson.Get(playletBase, "first_count").String(),
SecondCount: gjson.Get(playletBase, "second_count").String(),
Leave: gjson.Get(playletBase, "total").String(),
DayOneCount: gjson.Get(playletBase, "day_one_count").String(),
AndroidAdvId: gjson.Get(playletIncentiveBase, "android_adv_id").String(),
IosAdvId: gjson.Get(playletIncentiveBase, "ios_adv_id").String(),
Sum: "0.00",
CoinName: "活跃值",
}
user := GetUser(c)
//判断数量 读取缓存的
numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id)
numString, _ := cache.GetString(numKey)
Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - utils.StrToInt(numString)
if Leave-1 < 0 {
e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
return
//剩余次数
num := "0"
sum, _ := db.Db.Where("uid=? and date=?", user.Id, time.Now().Format("20060102")).Sum(&model.PlayletTotal{}, "total")
res.Leave = utils.IntToStr(utils.StrToInt(res.Total) - int(sum))
if utils.StrToInt(res.Leave) < 0 {
res.Leave = "0"
}
ch, err := rabbit.Cfg.Pool.GetChannel()
if err == nil {
defer ch.Release()
err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
Uid: utils.Int64ToStr(user.Id),
}, md.EggPlayletReward)
if err != nil {
ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
Uid: utils.Int64ToStr(user.Id),
}, md.EggPlayletReward)
if utils.StrToFloat64(res.Leave) > 0 { //总的还有 就判断单个剧还能不能看
sumOne, _ := db.Db.Where("uid=? and date=? and short_id=?", user.Id, time.Now().Format("20060102"), args.Id).Sum(&model.PlayletTotal{}, "total")
leaves := utils.StrToInt(res.DayOneCount) - int(sumOne)
if leaves > 0 {
num = res.SecondCount
}
}
re := md.PlayletUnlockResp{Num: num}
e.OutSuc(c, re, nil)
return
}
func PlayletReward(c *gin.Context) {
var args md.PlayletRewardRequest
if err := c.ShouldBindJSON(&args); err != nil {
e.OutErr(c, e.ERR_INVALID_ARGS, err)
return
}
//playletBase := GetSysCfgStr("playlet_base")
//user := GetUser(c)
////判断数量 读取缓存的
//numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id)
//numString, _ := cache.GetString(numKey)
//Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - utils.StrToInt(numString)
//if Leave-1 < 0 {
// e.OutErr(c, 400, e.NewErr(400, "今天已领取完"))
// return
//}
//ch, err := rabbit.Cfg.Pool.GetChannel()
//if err == nil {
// defer ch.Release()
// err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
// Uid: utils.Int64ToStr(user.Id),
// }, md.EggPlayletReward)
// if err != nil {
// ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{
// Uid: utils.Int64ToStr(user.Id),
// }, md.EggPlayletReward)
// }
//}
e.OutSuc(c, "success", nil)
return
}

Loading…
Cancel
Save