Browse Source

fix: update to count team assistance data

master
shenjiachi 1 day ago
parent
commit
2f84fbf4ae
3 changed files with 49 additions and 27 deletions
  1. +46
    -25
      consume/egg_energy_team_assistance_consume.go
  2. +2
    -1
      consume/egg_energy_team_assistance_consume_test.go
  3. +1
    -1
      go.mod

+ 46
- 25
consume/egg_energy_team_assistance_consume.go View File

@@ -73,34 +73,44 @@ func handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error {
// return err // return err
//} //}


cacheKey := fmt.Sprintf("EggEnergyTeamAssistance:%d", msg.Uid)
if !cache.Exists(cacheKey) {
targetTime, err1 := time.Parse("2006-01-02 15:04:05", msg.SignEnd)
if err1 != nil {
fmt.Println("解析时间错误:", err1)
return err1
}
diff := targetTime.Sub(time.Now()).Seconds()
_, err = cache.SetEx(cacheKey, nil, int(diff))
if err != nil {
return err
}
}

count, err1 := cache.GetBit(cacheKey, msg.AssistanceUid)
if err1 != nil {
return err1
// 2.查询数据库数据用户是否已经助力过
detailDb := implement.NewEggEnergyAssistanceDetailDb(db.Db)
exist, err := detailDb.AssistanceDetailExist(msg.Uid, msg.AssistanceUid, msg.SignId)
if err != nil {
return err
} }
if count == 0 {
_, err = cache.SetBit(cacheKey, msg.AssistanceUid, 1)
if err != nil {
return err
now := time.Now()
if !exist {
// 数据库显示没有助力过才需要二次确认
cacheKey := fmt.Sprintf("EggEnergyTeamAssistance:%d", msg.Uid)
if cache.Exists(cacheKey) {
// 3. 判断 redis 该用户是否助力过
count, err1 := cache.GetBit(cacheKey, msg.AssistanceUid)
if err1 != nil {
return err1
}
if count != 0 {
// 3.1 该用户已经助力过
exist = true
// 3.2 插入助力数据
detail := model.EggEnergyAssistanceDetail{
Uid: msg.Uid,
AssistedUid: msg.AssistanceUid,
SignId: msg.SignId,
CreatedAt: now.Format("2006-01-02 15:04:05"),
UpdatedAt: now.Format("2006-01-02 15:04:05"),
}
_, err = detailDb.AssistanceDetailInsert(&detail)
if err != nil {
return err
}
}
} }
} }


// 3. 变更数据
// 4. 变更数据
assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db) assistanceDb := implement.NewEggEnergyTeamAssistanceDb(db.Db)
now := time.Now()
date := now.Format("2006-01-02") date := now.Format("2006-01-02")
session := db.Db.Where("") session := db.Db.Where("")
teamAssistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneByParamsBySession(session, map[string]interface{}{ teamAssistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneByParamsBySession(session, map[string]interface{}{
@@ -127,9 +137,20 @@ func handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error {
} }
} else { } else {
teamAssistance.RewardScore = utils2.Float64ToStr(msg.AssistanceValue + utils2.StrToFloat64(teamAssistance.RewardScore)) teamAssistance.RewardScore = utils2.Float64ToStr(msg.AssistanceValue + utils2.StrToFloat64(teamAssistance.RewardScore))
// 如果是第一条说明还没有被记录过, 助力人数 + 1
if count == 0 {
// 如果未助力过, 助力人数 + 1 添加助力信息
if !exist {
teamAssistance.AssistedNum++ teamAssistance.AssistedNum++
m := model.EggEnergyAssistanceDetail{
Uid: msg.Uid,
AssistedUid: msg.AssistanceUid,
SignId: msg.SignId,
CreatedAt: now.Format("2006-01-02 15:04:05"),
UpdatedAt: now.Format("2006-01-02 15:04:05"),
}
_, err = detailDb.AssistanceDetailInsert(&m)
if err != nil {
return err
}
} }
teamAssistance.AssistedTimes++ teamAssistance.AssistedTimes++
_, err = assistanceDb.EggEnergyTeamAssistanceUpdate(teamAssistance.Id, teamAssistance, "assisted_num", "reward_score", "assisted_times") _, err = assistanceDb.EggEnergyTeamAssistanceUpdate(teamAssistance.Id, teamAssistance, "assisted_num", "reward_score", "assisted_times")


+ 2
- 1
consume/egg_energy_team_assistance_consume_test.go View File

@@ -33,10 +33,11 @@ func TestEggEnergyTeamAssistanceConsume(t *testing.T) {
} }
defer ch.Release() defer ch.Release()
ch.Publish(md2.EggEnergyExchange, md2.EggEnergyTeamAssistanceReq{ ch.Publish(md2.EggEnergyExchange, md2.EggEnergyTeamAssistanceReq{
AssistanceUid: 17,
AssistanceUid: 19,
Uid: 2, Uid: 2,
AssistanceValue: 100, AssistanceValue: 100,
SignStart: "2024-12-20 08:00:00", SignStart: "2024-12-20 08:00:00",
SignEnd: "2024-12-21 08:00:00", SignEnd: "2024-12-21 08:00:00",
SignId: 13,
}, md2.EggEnergyTeamAssistance) }, md2.EggEnergyTeamAssistance)
} }

+ 1
- 1
go.mod View File

@@ -2,7 +2,7 @@ module applet


go 1.19 go 1.19


// replace code.fnuoos.com/EggPlanet/egg_models.git => E:/company/Egg/egg_models
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




Loading…
Cancel
Save