|
@@ -42,12 +42,13 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm strin |
|
|
err = errors.New("蛋蛋能量设置未开启!") |
|
|
err = errors.New("蛋蛋能量设置未开启!") |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
var videoRewardSystem *md2.VideoRewardSystemStruct |
|
|
|
|
|
err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
if eggEnergyBasicSetting.VideoRewardIsOpen == 1 { |
|
|
if eggEnergyBasicSetting.VideoRewardIsOpen == 1 { |
|
|
var videoRewardSystem *md2.VideoRewardSystemStruct |
|
|
|
|
|
err = json.Unmarshal([]byte(eggEnergyBasicSetting.VideoRewardSystem), &videoRewardSystem) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
|
|
|
} |
|
|
|
|
|
if videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" { |
|
|
if videoRewardSystem.RewardTotalNum == "" || videoRewardSystem.IntervalMinutes == "" || videoRewardSystem.EachRoundHour == "" { |
|
|
err = errors.New("视屏奖励机制设置未完全!") |
|
|
err = errors.New("视屏奖励机制设置未完全!") |
|
|
return |
|
|
return |
|
@@ -189,46 +190,22 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm strin |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//增加 egg_user_watch_records 记录 |
|
|
|
|
|
eggEnergyUserWatchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(engine) |
|
|
|
|
|
eggEnergyUserWatchRecords, err1 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ |
|
|
|
|
|
"key": "uid", |
|
|
|
|
|
"value": uid, |
|
|
|
|
|
}) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
return rewardValue, err1 |
|
|
|
|
|
|
|
|
//处理直推奖励 |
|
|
|
|
|
var directPushRewardSetting *md2.DirectPushRewardSettingStruct |
|
|
|
|
|
err = json.Unmarshal([]byte(eggEnergyBasicSetting.DirectPushReward), &directPushRewardSetting) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
return |
|
|
} |
|
|
} |
|
|
now := time.Now() |
|
|
|
|
|
if eggEnergyUserWatchRecords == nil { |
|
|
|
|
|
residueWatchAdNum := egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1 |
|
|
|
|
|
if residueWatchAdNum < 0 { |
|
|
|
|
|
residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) |
|
|
|
|
|
} |
|
|
|
|
|
eggEnergyUserWatchRecords = &model.EggEnergyUserWatchRecords{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
NextWatchAdDate: now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour))), |
|
|
|
|
|
ResidueWatchAdNum: egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1, |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
} |
|
|
|
|
|
_, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsInsert(eggEnergyUserWatchRecords) |
|
|
|
|
|
if err2 != nil { |
|
|
|
|
|
return rewardValue, err2 |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
residueWatchAdNum := eggEnergyUserWatchRecords.ResidueWatchAdNum - 1 |
|
|
|
|
|
nextWatchAdDate := eggEnergyUserWatchRecords.NextWatchAdDate |
|
|
|
|
|
if residueWatchAdNum == 0 { //最后一条广告 |
|
|
|
|
|
residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) |
|
|
|
|
|
} |
|
|
|
|
|
if residueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum)-1 { //第一条广告 |
|
|
|
|
|
nextWatchAdDate = now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour))) |
|
|
|
|
|
|
|
|
fatherRewardValue := rewardValue * (egg_system_rules.StrToFloat64(directPushRewardSetting.RewardRateValue) / 100) |
|
|
|
|
|
if directPushRewardSetting.MemberSelfIsOpenGetTeamReward == "1" { |
|
|
|
|
|
var m model.EggSignIn |
|
|
|
|
|
has, err44 := engine.Where("uid =?", user.ParentUid).And("end_time >=?", time.Now().Format("2006-01-02 15:04:05")).Get(&m) |
|
|
|
|
|
if err44 != nil { |
|
|
|
|
|
return rewardValue, err44 |
|
|
} |
|
|
} |
|
|
eggEnergyUserWatchRecords.ResidueWatchAdNum = residueWatchAdNum |
|
|
|
|
|
eggEnergyUserWatchRecords.NextWatchAdDate = nextWatchAdDate |
|
|
|
|
|
_, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsUpdate(eggEnergyUserWatchRecords.Id, eggEnergyUserWatchRecords, "residue_watch_ad_num", "next_watch_ad_date") |
|
|
|
|
|
if err2 != nil { |
|
|
|
|
|
return rewardValue, err2 |
|
|
|
|
|
|
|
|
if !has { |
|
|
|
|
|
//不活跃不需要奖励 |
|
|
|
|
|
fatherRewardValue = 0 |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@@ -256,6 +233,21 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm strin |
|
|
return rewardValue, err |
|
|
return rewardValue, err |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//给相应的用户上级加上"个人"活跃积分 |
|
|
|
|
|
err = rule.DealUserVirtualCoin(session, md.DealUserVirtualCoinReq{ |
|
|
|
|
|
Kind: "add", |
|
|
|
|
|
Title: enum.UserVirtualAmountFlowTransferType.String(enum.EggEnergyWatchAdRewardFansActiveCoin), |
|
|
|
|
|
TransferType: int(enum.EggEnergyWatchAdRewardFansActiveCoin), |
|
|
|
|
|
CoinId: eggEnergyBasicSetting.TeamEggEnergyCoinId, |
|
|
|
|
|
Uid: user.ParentUid, |
|
|
|
|
|
Amount: fatherRewardValue, |
|
|
|
|
|
}) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
_ = session.Rollback() |
|
|
|
|
|
fmt.Println("err:::::2222", err) |
|
|
|
|
|
return rewardValue, err |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//给相应的用户加上"团队"活跃积分 |
|
|
//给相应的用户加上"团队"活跃积分 |
|
|
for _, vv := range rewardFather { |
|
|
for _, vv := range rewardFather { |
|
|
//TODO::推入rabbitmq 异步处理 |
|
|
//TODO::推入rabbitmq 异步处理 |
|
@@ -273,21 +265,61 @@ func SettlementGiveActivityCoin(engine *xorm.Engine, user model.User, ecpm strin |
|
|
_ = session.Rollback() |
|
|
_ = session.Rollback() |
|
|
return rewardValue, errors.New("事务提交失败") |
|
|
return rewardValue, errors.New("事务提交失败") |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
redisKey := fmt.Sprintf(md2.UserNextWatchAdDate, uid) |
|
|
|
|
|
var watchAdDate string |
|
|
|
|
|
if eggEnergyUserWatchRecords.ResidueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) { |
|
|
|
|
|
if eggEnergyUserWatchRecords.NextWatchAdDate.Before(time.Now()) { |
|
|
|
|
|
watchAdDate = "" |
|
|
|
|
|
} else { |
|
|
|
|
|
watchAdDate = eggEnergyUserWatchRecords.NextWatchAdDate.Format("2006-01-02 15:04:05") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//增加 egg_user_watch_records 记录 |
|
|
|
|
|
eggEnergyUserWatchRecordsDb := implement.NewEggEnergyUserWatchRecordsDb(engine) |
|
|
|
|
|
eggEnergyUserWatchRecords, err1 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsGetOneByParams(map[string]interface{}{ |
|
|
|
|
|
"key": "uid", |
|
|
|
|
|
"value": uid, |
|
|
|
|
|
}) |
|
|
|
|
|
if err1 != nil { |
|
|
|
|
|
return rewardValue, err1 |
|
|
|
|
|
} |
|
|
|
|
|
if eggEnergyUserWatchRecords == nil { |
|
|
|
|
|
residueWatchAdNum := egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1 |
|
|
|
|
|
if residueWatchAdNum < 0 { |
|
|
|
|
|
residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) |
|
|
|
|
|
} |
|
|
|
|
|
eggEnergyUserWatchRecords = &model.EggEnergyUserWatchRecords{ |
|
|
|
|
|
Uid: uid, |
|
|
|
|
|
NextWatchAdDate: now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour))), |
|
|
|
|
|
ResidueWatchAdNum: egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) - 1, |
|
|
|
|
|
CreateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
UpdateAt: now.Format("2006-01-02 15:04:05"), |
|
|
|
|
|
} |
|
|
|
|
|
_, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsInsert(eggEnergyUserWatchRecords) |
|
|
|
|
|
if err2 != nil { |
|
|
|
|
|
return rewardValue, err2 |
|
|
|
|
|
} |
|
|
|
|
|
} else { |
|
|
|
|
|
residueWatchAdNum := eggEnergyUserWatchRecords.ResidueWatchAdNum - 1 |
|
|
|
|
|
nextWatchAdDate := eggEnergyUserWatchRecords.NextWatchAdDate |
|
|
|
|
|
if residueWatchAdNum == 0 { //最后一条广告 |
|
|
|
|
|
residueWatchAdNum = egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) |
|
|
|
|
|
} |
|
|
|
|
|
if residueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum)-1 { //第一条广告 |
|
|
|
|
|
nextWatchAdDate = now.Add(time.Hour * time.Duration(egg_system_rules.StrToInt(videoRewardSystem.EachRoundHour))) |
|
|
|
|
|
} |
|
|
|
|
|
eggEnergyUserWatchRecords.ResidueWatchAdNum = residueWatchAdNum |
|
|
|
|
|
eggEnergyUserWatchRecords.NextWatchAdDate = nextWatchAdDate |
|
|
|
|
|
_, err2 := eggEnergyUserWatchRecordsDb.EggEnergyUserWatchRecordsUpdate(eggEnergyUserWatchRecords.Id, eggEnergyUserWatchRecords, "residue_watch_ad_num", "next_watch_ad_date") |
|
|
|
|
|
if err2 != nil { |
|
|
|
|
|
return rewardValue, err2 |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
redisKey := fmt.Sprintf(md2.UserNextWatchAdDate, uid) |
|
|
|
|
|
var watchAdDate string |
|
|
|
|
|
if eggEnergyUserWatchRecords.ResidueWatchAdNum == egg_system_rules.StrToInt(videoRewardSystem.RewardTotalNum) { |
|
|
|
|
|
if eggEnergyUserWatchRecords.NextWatchAdDate.Before(time.Now()) { |
|
|
|
|
|
watchAdDate = "" |
|
|
} else { |
|
|
} else { |
|
|
watchAdDate = time.Now().Add(time.Duration(egg_system_rules.StrToInt64(videoRewardSystem.IntervalMinutes)) * time.Second).Format("2006-01-02 15:04:05") |
|
|
|
|
|
|
|
|
watchAdDate = eggEnergyUserWatchRecords.NextWatchAdDate.Format("2006-01-02 15:04:05") |
|
|
} |
|
|
} |
|
|
cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时 |
|
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
watchAdDate = time.Now().Add(time.Duration(egg_system_rules.StrToInt64(videoRewardSystem.IntervalMinutes)) * time.Second).Format("2006-01-02 15:04:05") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
cache.SetEx(redisKey, watchAdDate, 60*60*24) //TODO::默认缓存1小时 |
|
|
return |
|
|
return |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|