Commit 04b986e8 authored by JiebinHu's avatar JiebinHu

feat:1分钟统一60秒

parent d41ec14f
......@@ -63,7 +63,8 @@ func OnMicQueue() {
}
// 用户上麦
if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
//if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
if err := mic_m.IncrUserOnMicV2(model, onMic.UserId); err != nil {
model.Log.Errorf("cron micIn IncrUserOnMic err:%v", err)
} else {
model.Log.Infof("cron micIn IncrUserOnMic success,userId:%v,cost:%vs", onMic.UserId, time.Now().Sub(start).Seconds())
......
......@@ -158,22 +158,24 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID)
// 事务操作
func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
// 月统计
star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
curTs := joinMicTimestamp
nowTs := time.Now().Unix()
month0Ts := now.BeginningOfMonth().Unix()
if err != nil && err != gorm.ErrRecordNotFound {
return err
}
if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
curTs = star.LastCalTs
}
// 跨月
if curTs < month0Ts {
curTs = month0Ts
}
score := nowTs - curTs
err = IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
//star, err := GetGroupPowerMonthStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
//curTs := joinMicTimestamp
//nowTs := time.Now().Unix()
//month0Ts := now.BeginningOfMonth().Unix()
//if err != nil && err != gorm.ErrRecordNotFound {
// return err
//}
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
// curTs = star.LastCalTs
//}
//// 跨月
//if curTs < month0Ts {
// curTs = month0Ts
//}
//score := nowTs - curTs
score := 60
err := IncrGroupPowerMonthStarScore(model, groupPowerId, userId,
groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0)
return err
}
......@@ -181,22 +183,24 @@ func IncrGroupPowerStarOnMicMonth(model *domain.Model, groupPowerId, userId mysq
// 事务操作
func IncrGroupPowerStarOnMicDay(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error {
// 日统计
star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
curTs := joinMicTimestamp
nowTs := time.Now().Unix()
day0Ts := now.BeginningOfDay().Unix()
if err != nil && err != gorm.ErrRecordNotFound {
return err
}
if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
curTs = star.LastCalTs
}
// 跨天
if curTs < day0Ts {
curTs = day0Ts
}
score := nowTs - curTs
err = IncrGroupPowerDayStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
//star, err := GetGroupPowerDayStar(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive)
//curTs := joinMicTimestamp
//nowTs := time.Now().Unix()
//day0Ts := now.BeginningOfDay().Unix()
//if err != nil && err != gorm.ErrRecordNotFound {
// return err
//}
//if star != nil && joinMicTimestamp < star.LastCalTs { // 加入的时间比上次计算时间小
// curTs = star.LastCalTs
//}
//// 跨天
//if curTs < day0Ts {
// curTs = day0Ts
//}
//score := nowTs - curTs
score := 60
err := IncrGroupPowerDayStarScore(model, groupPowerId, userId,
groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), 0)
return err
}
......
......@@ -75,6 +75,29 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
})
}
// 增加用户上麦时长
// 事务操作
func IncrUserOnMicV2(model *domain.Model, userId mysql.ID) error {
for _, tz := range timezone_e.Timezones {
day := time.Now().In(timezone_e.TimezoneLocMap[tz]).Format("2006-01-02")
if err := model.DB().Model(UserOnMic{}).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "date"}, {Name: "user_id"}, {Name: "tz"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"seconds": gorm.Expr("seconds + ?", 60),
}),
}).Create(&UserOnMic{
Date: day,
UserId: userId,
Seconds: 60,
Tz: tz,
}).Error; err != nil {
model.Log.Errorf("IncrUserOnMic fail:%v", err)
return err
}
}
return nil
}
// 批量获取用户上麦时长
// @return userId->seconds
func MGetUserOnMicSeconds(model *domain.Model, day string, tz timezone_e.Timezone, userIds []uint64) (map[mysql.ID]mysql.Num, error) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment