Commit b34a7a8c authored by hujiebin's avatar hujiebin

feat:经验增加明细

parent 9c643008
...@@ -14,20 +14,31 @@ import ( ...@@ -14,20 +14,31 @@ import (
type GroupPowerDayExp struct { type GroupPowerDayExp struct {
Date string Date string
GroupPowerId mysql.ID GroupPowerId mysql.ID
Exp int64 Exp mysql.Num
CreatedTime time.Time `gorm:"->"` CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"` UpdatedTime time.Time `gorm:"->"`
} }
type GroupPowerGrade struct { type GroupPowerGrade struct {
GroupPowerId mysql.ID GroupPowerId mysql.ID
Exp int64 Exp mysql.Num
Grade groupPower_e.GroupPowerGrade Grade groupPower_e.GroupPowerGrade
ExpireAt time.Time ExpireAt time.Time
CreatedTime time.Time `gorm:"->"` CreatedTime time.Time `gorm:"->"`
UpdatedTime 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 { type GroupPowerOnMic struct {
Date string Date string
GroupPowerId mysql.ID GroupPowerId mysql.ID
...@@ -50,7 +61,7 @@ type GroupPowerOnMicDetail struct { ...@@ -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 var err error
defer func() { defer func() {
if err != nil { if err != nil {
...@@ -81,13 +92,27 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp int64) ...@@ -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 { "exp": gorm.Expr("exp + ?", gpg.Exp)})}).Create(gpg).Error; err != nil {
return err return err
} }
// 达到经验值之后升级 // 当前写后读
latestGrade := new(GroupPowerGrade) latestGrade := new(GroupPowerGrade)
if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil { if err = txModel.DB().Model(GroupPowerGrade{}).Where("group_power_id = ?", groupPowerId).First(latestGrade).Error; err != nil {
return err 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-- { 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 { // 积分清零后,等级保持一段时间 if latestGrade.Grade < grade { // 积分清零后,等级保持一段时间
expireAt := now.EndOfMonth() expireAt := now.EndOfMonth()
expireAt = utils.AddDate(expireAt, 0, 1) // 等级有效期到下个月月底 expireAt = utils.AddDate(expireAt, 0, 1) // 等级有效期到下个月月底
...@@ -176,7 +201,7 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID, ...@@ -176,7 +201,7 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
return err return err
} }
// 每10分钟增加100点经验 // 每10分钟增加100点经验
if err := IncrGroupPowerExp(model, groupPowerId, 100); err != nil { if err := IncrGroupPowerExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil {
return err return err
} }
} }
......
...@@ -3,6 +3,7 @@ package event_s ...@@ -3,6 +3,7 @@ package event_s
import ( import (
"encoding/json" "encoding/json"
"git.hilo.cn/hilo-common/domain" "git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/rpc" "git.hilo.cn/hilo-common/rpc"
"git.hilo.cn/hilo-common/sdk/tencentyun" "git.hilo.cn/hilo-common/sdk/tencentyun"
"hilo-group/_const/enum/group_e" "hilo-group/_const/enum/group_e"
...@@ -411,8 +412,8 @@ func SendGift() { ...@@ -411,8 +412,8 @@ func SendGift() {
return err return err
} }
if exist { if exist {
exp := int64(sendGiftEvent.GiftN) * int64(len(sendGiftEvent.ReceiveUserIds)) * int64(sendGiftEvent.ResGift.DiamondNum) exp := sendGiftEvent.GiftN * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) * sendGiftEvent.ResGift.DiamondNum
return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp) return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
} }
return nil return nil
}) })
......
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