package svc import ( "applet/app/db" "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" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "time" ) func VideoBase(c *gin.Context) { videoBase := GetSysCfgStr("video_base") var res = md.VideoBaseData{ Reward: gjson.Get(videoBase, "reward").String(), Total: gjson.Get(videoBase, "total").String(), Timer: gjson.Get(videoBase, "timer").String(), Leave: gjson.Get(videoBase, "total").String(), Sum: "0.00", CoinName: "活跃值", Interval: gjson.Get(videoBase, "interval").String(), } user := GetUser(c) //剩余次数 NewVideoTotalDb := implement.NewVideoTotalDb(db.Db) total, _ := NewVideoTotalDb.GetVideoTotal(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" } } 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 VideoReward(c *gin.Context) { var args md.VideoRewardRequest if err := c.ShouldBindJSON(&args); err != nil { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } videoBase := GetSysCfgStr("video_base") user := GetUser(c) //判断到时间领了没 timeKey := "video.timer:" + utils.Int64ToStr(user.Id) timeString, _ := cache.GetString(timeKey) if timeString == "1" { e.OutErr(c, 400, e.NewErr(400, "未到时间领取")) return } cache.SetEx(timeKey, "1", utils.StrToInt(gjson.Get(videoBase, "interval").String())) //判断数量 读取缓存的 numKey := "video.num:" + time.Now().Format("20060102") + "." + utils.Int64ToStr(user.Id) numString, _ := cache.GetString(numKey) Leave := utils.StrToInt(gjson.Get(videoBase, "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.EggVideoReward) if err != nil { ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{ Uid: utils.Int64ToStr(user.Id), }, md.EggVideoReward) } } e.OutSuc(c, "success", nil) return }