From b91c78f22dbcd451af8dd65dbd913aba1d27a1f4 Mon Sep 17 00:00:00 2001 From: huangjiajun <582604932@qq.com> Date: Mon, 9 Dec 2024 13:55:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=AD=E8=A7=86=E9=A2=91=E7=9F=AD=E5=89=A7?= =?UTF-8?q?=E9=A2=86=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/hdl/hdl_playlet.go | 10 +++--- app/hdl/hdl_video.go | 6 ++-- app/md/md_mq.go | 10 ++++++ app/svc/svc_playlet.go | 63 +++++++------------------------------- app/svc/svc_video.go | 69 +++++++++++------------------------------- 5 files changed, 47 insertions(+), 111 deletions(-) diff --git a/app/hdl/hdl_playlet.go b/app/hdl/hdl_playlet.go index d844e9d..f4a7eda 100644 --- a/app/hdl/hdl_playlet.go +++ b/app/hdl/hdl_playlet.go @@ -6,9 +6,9 @@ import ( ) // PlayletBase -// @Summary 短视频-基本信息 +// @Summary 短剧-基本信息 // @Tags 短视频 -// @Description 短视频-基本信息 +// @Description 短剧-基本信息 // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" @@ -20,9 +20,9 @@ func PlayletBase(c *gin.Context) { } // PlayletReward -// @Summary 实名认证-保存 -// @Tags 实名认证 -// @Description 实名认证-保存 +// @Summary 短剧-保存 +// @Tags 短视频 +// @Description 短剧-保存 // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" diff --git a/app/hdl/hdl_video.go b/app/hdl/hdl_video.go index 694e694..d5c7173 100644 --- a/app/hdl/hdl_video.go +++ b/app/hdl/hdl_video.go @@ -20,9 +20,9 @@ func VideoBase(c *gin.Context) { } // VideoReward -// @Summary 实名认证-保存 -// @Tags 实名认证 -// @Description 实名认证-保存 +// @Summary 短视频-领取 +// @Tags 短视频 +// @Description 短视频-领取 // @Accept json // @Produce json // @param Authorization header string true "验证参数Bearer和token空格拼接" diff --git a/app/md/md_mq.go b/app/md/md_mq.go index b5ef86e..3f054f9 100644 --- a/app/md/md_mq.go +++ b/app/md/md_mq.go @@ -8,8 +8,18 @@ const ( EggAdvertisingSign = "advertising_sign" EggAliyunSmsRecordQueueExchange = "egg.aliyun_sms" EggAliyunSmsRecordQueue = "aliyun_sms_record" + EggVideoPlayletExchange = "egg.video_playlet" + EggVideoReward = "video" + EggPlayletReward = "playlet" ) +type VideoReward struct { + Uid string `json:"uid"` +} +type PlayletReward struct { + Uid string `json:"uid"` +} + type JpushRecordFundData struct { Id string `json:"id"` UserId string `json:"user_id"` diff --git a/app/svc/svc_playlet.go b/app/svc/svc_playlet.go index b58dd08..a7c1ff5 100644 --- a/app/svc/svc_playlet.go +++ b/app/svc/svc_playlet.go @@ -5,10 +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/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -53,65 +51,26 @@ func PlayletReward(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - eg := db.Db playletBase := GetSysCfgStr("playlet_base") - sess := eg.NewSession() - defer sess.Close() - sess.Begin() user := GetUser(c) - NewPlayletTotalDb := implement.NewPlayletTotalDb(db.Db) - total, _ := NewPlayletTotalDb.GetPlayletTotalSess(sess, utils.Int64ToStr(user.Id), time.Now().Format("20060102")) - if total == nil { - total = &model.PlayletTotal{ - Uid: int(user.Id), - Date: utils.StrToInt(time.Now().Format("20060102")), - Time: time.Now(), - } - insert, err := sess.Insert(total) - if insert == 0 || err != nil { - sess.Rollback() - - e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) - return - } - } - Leave := utils.StrToInt(gjson.Get(playletBase, "total").String()) - total.Total + //判断数量 读取缓存的 + 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 { - sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "今天已领取完")) return } - total.Total++ - - update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total) - if update == 0 || err2 != nil { - sess.Rollback() - e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) - return - } - sess.Commit() ch, err := rabbit.Cfg.Pool.GetChannel() if err == nil { defer ch.Release() - NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() - err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: user.Id, - Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) + err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{ + Uid: utils.Int64ToStr(user.Id), + }, md.EggPlayletReward) if err != nil { - ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyPlayletRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyPlayletRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: user.Id, - Amount: utils.StrToFloat64(gjson.Get(playletBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) + ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{ + Uid: utils.Int64ToStr(user.Id), + }, md.EggPlayletReward) } } e.OutSuc(c, "success", nil) diff --git a/app/svc/svc_video.go b/app/svc/svc_video.go index 368fdb9..d971787 100644 --- a/app/svc/svc_video.go +++ b/app/svc/svc_video.go @@ -5,10 +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/EggPlanet/egg_models.git/src/model" - "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum" - md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git/rabbit" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" @@ -53,65 +51,34 @@ func VideoReward(c *gin.Context) { e.OutErr(c, e.ERR_INVALID_ARGS, err) return } - eg := db.Db videoBase := GetSysCfgStr("video_base") - sess := eg.NewSession() - defer sess.Close() - sess.Begin() user := GetUser(c) - NewVideoTotalDb := implement.NewVideoTotalDb(db.Db) - total, _ := NewVideoTotalDb.GetVideoTotalSess(sess, utils.Int64ToStr(user.Id), time.Now().Format("20060102")) - if total == nil { - total = &model.VideoTotal{ - Uid: int(user.Id), - Date: utils.StrToInt(time.Now().Format("20060102")), - Time: time.Now(), - } - insert, err := sess.Insert(total) - if insert == 0 || err != nil { - sess.Rollback() - - e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) - return - } + //判断到时间领了没 + timeKey := "video.timer:" + utils.Int64ToStr(user.Id) + timeString, _ := cache.GetString(timeKey) + if timeString == "1" { + e.OutErr(c, 400, e.NewErr(400, "未到时间领取")) + return } - Leave := utils.StrToInt(gjson.Get(videoBase, "total").String()) - total.Total + 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 { - sess.Rollback() e.OutErr(c, 400, e.NewErr(400, "今天已领取完")) return } - total.Total++ - - update, err2 := sess.Where("id=?", total.Id).Cols("total").Update(total) - if update == 0 || err2 != nil { - sess.Rollback() - e.OutErr(c, 400, e.NewErr(400, "获取奖励失败")) - return - } - sess.Commit() ch, err := rabbit.Cfg.Pool.GetChannel() if err == nil { defer ch.Release() - NewEggEnergyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggData, _ := NewEggEnergyBasicSettingDb.EggEnergyBasicSettingGetOne() - err = ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyVideoRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: user.Id, - Amount: utils.StrToFloat64(gjson.Get(videoBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) + err = ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{ + Uid: utils.Int64ToStr(user.Id), + }, md.EggVideoReward) if err != nil { - ch.PublishV2(md2.EggEnergyExchange, md2.EggEnergyStructForDealUserVirtualCoinData{ - Kind: "add", - Title: enum.EggEnergyVideoRewardPersonalActiveCoin.String(), - TransferType: int(enum.EggEnergyVideoRewardPersonalActiveCoin), - CoinId: eggData.PersonEggPointsCoinId, - Uid: user.Id, - Amount: utils.StrToFloat64(gjson.Get(videoBase, "reward").String()), - }, md2.EggEnergyRoutKeyForDealUserVirtualCoinData) + ch.PublishV2(md.EggVideoPlayletExchange, md.PlayletReward{ + Uid: utils.Int64ToStr(user.Id), + }, md.EggVideoReward) } } e.OutSuc(c, "success", nil)