From 6b24a3d7804ca28bbd03708a763bd26e145b7dda Mon Sep 17 00:00:00 2001 From: dengbiao Date: Tue, 17 Dec 2024 22:50:22 +0800 Subject: [PATCH] uipdate --- app/hdl/hdl_home_page.go | 82 ++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/app/hdl/hdl_home_page.go b/app/hdl/hdl_home_page.go index e841be1..0a14841 100644 --- a/app/hdl/hdl_home_page.go +++ b/app/hdl/hdl_home_page.go @@ -379,39 +379,55 @@ func IsCanSignIn(c *gin.Context) { return } - //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 - energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) - eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ - "key": "is_open", - "value": 1, - }) - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - var videoRewardSystem *md2.VideoRewardSystemStruct - err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) - if err != nil { - e.OutErr(c, e.ERR, err.Error()) - return - } - rewardTotalNum := utils.StrToInt(videoRewardSystem.RewardTotalNum) - - //2、查询当前用户观看视屏记录 - watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) - userWatchRecords, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ - "key": "uid", - "value": user.Id, - }) - if err != nil { - e.OutErr(c, e.ERR_DB_ORM, err.Error()) - return - } - - var isCan bool now := time.Now() - if userWatchRecords != nil && userWatchRecords.ResidueWatchAdNum == rewardTotalNum && userWatchRecords.NextWatchAdDate.After(now) { - isCan = true + cacheKey := fmt.Sprintf("IsCanSignIn:%d", user.Id) + var isCan bool + if cache.Exists(cacheKey) { + isCan = false + } else { + signInDb := implement.NewEggSignInDb(db.Db) + nowStr := now.Format("2006-01-02 15:04:05") + has, _, err := signInDb.EggSignINGetOneByTimeAndUid("", nowStr, user.Id, 0) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if has { + isCan = false + } else { + //1、查找 `OneCirclesPublicPlatoonBasicSetting` 基础设置 + energyBasicSettingDb := implement.NewEggEnergyBasicSettingDb(db.Db) + eggEnergyBasicSetting, err := energyBasicSettingDb.EggEnergyBasicSettingGetOneByParams(map[string]interface{}{ + "key": "is_open", + "value": 1, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + var videoRewardSystem *md2.VideoRewardSystemStruct + err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) + if err != nil { + e.OutErr(c, e.ERR, err.Error()) + return + } + rewardTotalNum := utils.StrToInt(videoRewardSystem.RewardTotalNum) + + //2、查询当前用户观看视屏记录 + watchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(db.Db) + userWatchRecords, err := watchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ + "key": "uid", + "value": user.Id, + }) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + + if userWatchRecords != nil && userWatchRecords.ResidueWatchAdNum == rewardTotalNum && userWatchRecords.NextWatchAdDate.After(now) { + isCan = true + } + } } utils.FilePutContents("HomePageIsCanSignIn", utils.SerializeStr(map[string]interface{}{ @@ -423,6 +439,8 @@ func IsCanSignIn(c *gin.Context) { resp := md.IsCanSignInResp{ IsCan: isCan, } + + cache.SetEx(cacheKey, "run", 30) e.OutSuc(c, resp, nil) return }