package svc import ( "applet/app/db" "applet/app/e" "applet/app/md" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "time" ) 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(), 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) //剩余次数 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() NewUserVirtualAmountDb := implement.NewUserVirtualAmountDb(db.Db) coin, _ := NewUserVirtualAmountDb.GetUserVirtualWalletBySession(user.Id, eggData.PersonEggPointsCoinId) if coin != nil { res.Sum = coin.Amount } e.OutSuc(c, res, nil) return } 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) //剩余次数 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" } 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 }