diff --git a/app/hdl/hdl_add_friend.go b/app/hdl/hdl_add_friend.go index 8c23ce4..e41059b 100644 --- a/app/hdl/hdl_add_friend.go +++ b/app/hdl/hdl_add_friend.go @@ -612,13 +612,13 @@ func MyFansUserList(c *gin.Context) { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } - var teamRewardSetting *md2.TeamRewardSettingStruct - err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &teamRewardSetting) + var videoRewardSystem *md2.VideoRewardSystemStruct + err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) if err != nil { e.OutErr(c, e.ERR, err.Error()) return } - var oneRoundDuration = utils.StrToInt(teamRewardSetting.OneRoundDuration) + var oneRoundDuration = utils.StrToInt(videoRewardSystem.EachRoundHour) startTime := now.Add(-time.Hour * time.Duration(oneRoundDuration)).Format("2006-01-02 15:04:05") relateDb := implement.NewUserRelateDb(db.Db) userRelates, err := relateDb.FindUserRelateByParentUid(user.Id, 1) diff --git a/app/hdl/hdl_home_page.go b/app/hdl/hdl_home_page.go index 55f008a..341132b 100644 --- a/app/hdl/hdl_home_page.go +++ b/app/hdl/hdl_home_page.go @@ -11,6 +11,7 @@ import ( "code.fnuoos.com/EggPlanet/egg_models.git/src/model" md2 "code.fnuoos.com/EggPlanet/egg_system_rules.git/rule/egg_energy/md" "encoding/json" + "fmt" "github.com/gin-gonic/gin" "github.com/shopspring/decimal" "time" @@ -186,19 +187,68 @@ func HomePage(c *gin.Context) { // @Failure 400 {object} md.Response "具体错误" // @Router /api/v1/homePage/adRule [get] func HomePageWatchAdRule(c *gin.Context) { + val, exists := c.Get("user") + if !exists { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + user, ok := val.(*model.User) + if !ok { + e.OutErr(c, e.ERR_USER_CHECK_ERR, nil) + return + } + // 1. 查找基础设置 energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) basicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOne() if err != nil { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } + // 2. 计算当前还能看几个广告 + recordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) + records, err := recordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ + "key": "uid", + "value": user.Id, + }) + if err != nil { + return + } var videoRewardSystem md2.VideoRewardSystemStruct utils.Unserialize([]byte(basicSetting.VideoRewardSystem), &videoRewardSystem) + redisKey := fmt.Sprintf(md2.UserNextWatchAdDate, user.Id) + var residueWatchAdNum int + if records == nil { + residueWatchAdNum = utils.StrToInt(videoRewardSystem.RewardTotalNum) + } else { + now := time.Now() + residueWatchAdNum = records.ResidueWatchAdNum + if records.NextWatchAdDate.Before(now) { + //TODO::下一轮时间已在当前时间之前 + residueWatchAdNum = utils.StrToInt(videoRewardSystem.RewardTotalNum) + records.ResidueWatchAdNum = residueWatchAdNum + _, err = recordsDb.EggEnergyUserWatchRecordsUpdate(records.Id, records, "residue_watch_ad_num") + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + cache.SetEx(redisKey, "", 60*60*24) + } + } + nextWatchAdDate, _ := cache.GetString(redisKey) + var nextWatchAdTimes = utils.TimeParseStd(nextWatchAdDate).Unix() - time.Now().Unix() + + utils.FilePutContents("nextWatchAdDate", utils.SerializeStr(map[string]interface{}{ + "nextWatchAdDate": nextWatchAdDate, + "next_watch_ad_times": nextWatchAdTimes, + "uid": utils.Int64ToStr(user.Id), + "time": time.Now().Format("2006-01-02 15:04:05.000"), + })) + resp := md.HomePageWatchAdRuleResp{ - RewardValue: videoRewardSystem.RewardValue, - RewardTotalNum: videoRewardSystem.RewardTotalNum, - IntervalMinutes: videoRewardSystem.IntervalMinutes, - EachRoundHour: videoRewardSystem.EachRoundHour, + ResidueWatchAdNum: residueWatchAdNum, + WatchAdRewardActivePoints: videoRewardSystem.RewardValue, + NextWatchAdDate: nextWatchAdDate, + EachRoundHour: videoRewardSystem.EachRoundHour, } e.OutSuc(c, resp, nil) } @@ -258,7 +308,7 @@ func RealTimePrice(c *gin.Context) { userCount = result["user_count"] isRises = result["is_rises"] risesValue = result["rises"] - nowPrice = result["green_energy_now_price"] + nowPrice = result["egg_energy_now_price"] } isRisesResp, ok := isRises.(bool) diff --git a/app/md/md_home_page.go b/app/md/md_home_page.go index 054ca92..f0228ef 100644 --- a/app/md/md_home_page.go +++ b/app/md/md_home_page.go @@ -16,10 +16,10 @@ type HomePageResp struct { } type HomePageWatchAdRuleResp struct { - RewardValue string `json:"reward_value"` //奖励X个活跃积分 - RewardTotalNum string `json:"reward_total_num"` //一共X个奖励视屏 - IntervalMinutes string `json:"interval_minutes"` //间隔X秒 - EachRoundHour string `json:"each_round_hour"` //每一轮X个小时 + ResidueWatchAdNum int `json:"residue_watch_ad_num"` // 当前剩余可观看视频数 + WatchAdRewardActivePoints string `json:"watch_ad_reward_active_points"` // 观看广告视频奖励X个活跃积分 + NextWatchAdDate string `json:"next_watch_ad_date"` // 下次可观看广告时间,若为允许观看视频 + EachRoundHour string `json:"each_round_hour"` // 每一轮X个小时 } type RealTimePriceResp struct { diff --git a/docs/docs.go b/docs/docs.go index f11263d..7951c22 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -3436,16 +3436,16 @@ const docTemplate = `{ "description": "每一轮X个小时", "type": "string" }, - "interval_minutes": { - "description": "间隔X秒", + "next_watch_ad_date": { + "description": "下次可观看广告时间,若为允许观看视频", "type": "string" }, - "reward_total_num": { - "description": "一共X个奖励视屏", - "type": "string" + "residue_watch_ad_num": { + "description": "当前剩余可观看视频数", + "type": "integer" }, - "reward_value": { - "description": "奖励X个活跃积分", + "watch_ad_reward_active_points": { + "description": "观看广告视频奖励X个活跃积分", "type": "string" } } diff --git a/docs/swagger.json b/docs/swagger.json index 05c7903..c727d99 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -3430,16 +3430,16 @@ "description": "每一轮X个小时", "type": "string" }, - "interval_minutes": { - "description": "间隔X秒", + "next_watch_ad_date": { + "description": "下次可观看广告时间,若为允许观看视频", "type": "string" }, - "reward_total_num": { - "description": "一共X个奖励视屏", - "type": "string" + "residue_watch_ad_num": { + "description": "当前剩余可观看视频数", + "type": "integer" }, - "reward_value": { - "description": "奖励X个活跃积分", + "watch_ad_reward_active_points": { + "description": "观看广告视频奖励X个活跃积分", "type": "string" } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index c321f75..50b493e 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -626,14 +626,14 @@ definitions: each_round_hour: description: 每一轮X个小时 type: string - interval_minutes: - description: 间隔X秒 + next_watch_ad_date: + description: 下次可观看广告时间,若为允许观看视频 type: string - reward_total_num: - description: 一共X个奖励视屏 - type: string - reward_value: - description: 奖励X个活跃积分 + residue_watch_ad_num: + description: 当前剩余可观看视频数 + type: integer + watch_ad_reward_active_points: + description: 观看广告视频奖励X个活跃积分 type: string type: object md.InitialDataResp: diff --git a/go.mod b/go.mod index dfe5f3e..064f1f1 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.19 //replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models // -// replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules +//replace code.fnuoos.com/EggPlanet/egg_system_rules.git => E:/company/Egg/egg_system_rules require ( github.com/boombuler/barcode v1.0.1 @@ -33,7 +33,7 @@ require ( require ( code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241128030209-743f36ef9dad - code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241127090541-fd005650a340 + code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241128063602-ed11b9dad994 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5 github.com/aliyun/aliyun-oss-go-sdk v3.0.2+incompatible