@@ -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) | |||
@@ -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) | |||
@@ -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 { | |||
@@ -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" | |||
} | |||
} | |||
@@ -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" | |||
} | |||
} | |||
@@ -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: | |||
@@ -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 | |||