|
|
@@ -73,34 +73,44 @@ func handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error { |
|
|
|
// 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) |
|
|
|
now := time.Now() |
|
|
|
|
|
|
|
date := now.Format("2006-01-02") |
|
|
|
session := db.Db.Where("") |
|
|
|
teamAssistance, err := assistanceDb.EggEnergyTeamAssistanceGetOneByParamsBySession(session, map[string]interface{}{ |
|
|
@@ -127,9 +137,20 @@ func handleEggEnergyTeamAssistanceDataConsume(msgData []byte) error { |
|
|
|
} |
|
|
|
} else { |
|
|
|
teamAssistance.RewardScore = utils2.Float64ToStr(msg.AssistanceValue + utils2.StrToFloat64(teamAssistance.RewardScore)) |
|
|
|
// 如果是第一条说明还没有被记录过, 助力人数 + 1 |
|
|
|
if count == 0 { |
|
|
|
// 如果未助力过, 助力人数 + 1 添加助力信息 |
|
|
|
if !exist { |
|
|
|
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++ |
|
|
|
_, err = assistanceDb.EggEnergyTeamAssistanceUpdate(teamAssistance.Id, teamAssistance, "assisted_num", "reward_score", "assisted_times") |
|
|
|