diff --git a/domain/model/groupPower_m/group_grade.go b/domain/model/groupPower_m/group_grade.go index 1a4a7f48037d5f91e50a1d7bcbd1230a66484dfa..cae79d074587010dc51affa7a97515adcb3de719 100644 --- a/domain/model/groupPower_m/group_grade.go +++ b/domain/model/groupPower_m/group_grade.go @@ -14,20 +14,31 @@ import ( type GroupPowerDayExp struct { Date string GroupPowerId mysql.ID - Exp int64 + Exp mysql.Num CreatedTime time.Time `gorm:"->"` UpdatedTime time.Time `gorm:"->"` } type GroupPowerGrade struct { GroupPowerId mysql.ID - Exp int64 + Exp mysql.Num Grade groupPower_e.GroupPowerGrade ExpireAt time.Time CreatedTime time.Time `gorm:"->"` UpdatedTime time.Time `gorm:"->"` } +type GroupPowerExpDetail struct { + mysql.Entity + GroupPowerId mysql.ID + UserId mysql.ID + Exp mysql.Num + AddReduce mysql.AddReduce + BefNum mysql.Num + AftNum mysql.Num + Remark string +} + type GroupPowerOnMic struct { Date string GroupPowerId mysql.ID @@ -50,7 +61,7 @@ type GroupPowerOnMicDetail struct { // 增加家族经验 // 达到经验值之后升级 // 单进程同步执行,不考虑并发 -func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp int64) error { +func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.Num, userId mysql.ID, remark string) error { var err error defer func() { if err != nil { @@ -81,13 +92,27 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp int64) "exp": gorm.Expr("exp + ?", gpg.Exp)})}).Create(gpg).Error; err != nil { return err } - // 达到经验值之后升级 + // 当前写后读 latestGrade := new(GroupPowerGrade) if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil { return err } + // 记录明细 + detail := &GroupPowerExpDetail{ + GroupPowerId: groupPowerId, + UserId: userId, + Exp: exp, + AddReduce: mysql.ADD, + BefNum: latestGrade.Exp - exp, + AftNum: latestGrade.Exp, + Remark: remark, + } + if err = txModel.DB().Model(GroupPowerExpDetail{}).Create(detail).Error; err != nil { + return err + } + // 达到经验值之后升级 for grade := groupPower_e.GroupPowerGradeMax; grade >= groupPower_e.GroupPowerGrade0; grade-- { - if latestGrade.Exp > groupPower_e.GroupPowerGradeExp[grade] { + if latestGrade.Exp > mysql.Num(groupPower_e.GroupPowerGradeExp[grade]) { if latestGrade.Grade < grade { // 积分清零后,等级保持一段时间 expireAt := now.EndOfMonth() expireAt = utils.AddDate(expireAt, 0, 1) // 等级有效期到下个月月底 @@ -176,7 +201,7 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID, return err } // 每10分钟增加100点经验 - if err := IncrGroupPowerExp(model, groupPowerId, 100); err != nil { + if err := IncrGroupPowerExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil { return err } } diff --git a/domain/service/event_s/event_init.go b/domain/service/event_s/event_init.go index 091ac6af0303859ae92ced5f4538791ccb97e9b5..1285f2c5a8ab3ae6405e02f67b1cae30da249ec4 100644 --- a/domain/service/event_s/event_init.go +++ b/domain/service/event_s/event_init.go @@ -3,6 +3,7 @@ package event_s import ( "encoding/json" "git.hilo.cn/hilo-common/domain" + "git.hilo.cn/hilo-common/resource/mysql" "git.hilo.cn/hilo-common/rpc" "git.hilo.cn/hilo-common/sdk/tencentyun" "hilo-group/_const/enum/group_e" @@ -411,8 +412,8 @@ func SendGift() { return err } if exist { - exp := int64(sendGiftEvent.GiftN) * int64(len(sendGiftEvent.ReceiveUserIds)) * int64(sendGiftEvent.ResGift.DiamondNum) - return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp) + exp := sendGiftEvent.GiftN * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) * sendGiftEvent.ResGift.DiamondNum + return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼") } return nil })