diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index 14b8a37fcb9c4709dfbacb1be15f4ac9ee49722c..963d738d890f832225def04043b0aa2d01f285f8 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -256,6 +256,30 @@ func IncrGroupPowerStarOnMic(model *domain.Model, groupPowerId, userId mysql.ID, } score := nowTs - curTs err = IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs) + return err + }) +} + +// 增加势力上麦时长-家族之星 +// 事务操作 +func IncrGroupPowerStarOnMicDay(model *domain.Model, groupPowerId, userId mysql.ID, joinMicTimestamp int64) error { + return model.Transaction(func(model *domain.Model) 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) return err }) diff --git a/domain/model/groupPower_m/group_star.go b/domain/model/groupPower_m/group_star.go index 08b97a0b609f4b37746ab0bda18f99bdb8ac69f4..c796c52b170bd1e18d894c42ee59034ce04e4265 100644 --- a/domain/model/groupPower_m/group_star.go +++ b/domain/model/groupPower_m/group_star.go @@ -80,6 +80,17 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql. return nil } +// 获取家族之星分数 +// 允许返回gorm.ErrRecordNotFound +func GetGroupPowerDayStar(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType) (*GroupPowerDayStar, error) { + res := new(GroupPowerDayStar) + date := time.Now() + if err := model.DB().Where("date = ? AND group_power_id = ? AND user_id = ? AND `type` = ?", date, groupPowerId, userId, _type).First(res).Error; err != nil { + return nil, err + } + return res, nil +} + // 获取家族之星分数 // 允许返回gorm.ErrRecordNotFound func GetGroupPowerMonthStar(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType) (*GroupPowerMonthStar, error) {