From 87a22ad56aafce13e24dd975ca5eccf802ffb01c Mon Sep 17 00:00:00 2001 From: hujiebin Date: Wed, 22 Mar 2023 12:26:23 +0800 Subject: [PATCH] =?UTF-8?q?fix=EF=BC=9A=E4=BF=AE=E5=A4=8D=E8=B7=A8?= =?UTF-8?q?=E5=A4=A9=E7=9A=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/model/groupPower_m/group_grade.go | 24 ++++++++++++++++++++++++ domain/model/groupPower_m/group_star.go | 11 +++++++++++ 2 files changed, 35 insertions(+) diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index 14b8a37..963d738 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 08b97a0..c796c52 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) { -- 2.22.0