Commit 561c371d authored by hujiebin's avatar hujiebin

feat:多加一个家族之星的日统计

parent 446fdf5a
......@@ -255,7 +255,9 @@ func IncrGroupPowerStarOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
curTs = month0Ts
}
score := nowTs - curTs
return IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
err = IncrGroupPowerMonthStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
err = IncrGroupPowerDayStarScore(model, groupPowerId, userId, groupPower_e.GroupPowerStarTypeActive, mysql.Num(score), nowTs)
return err
})
}
......
......@@ -9,7 +9,7 @@ import (
"time"
)
// 家族之星
// 家族之星-月
type GroupPowerMonthStar struct {
Month string
GroupPowerId mysql.ID
......@@ -21,6 +21,18 @@ type GroupPowerMonthStar struct {
UpdatedTime time.Time `gorm:"->"`
}
// 家族之星-日
type GroupPowerDayStar struct {
Date time.Time
GroupPowerId mysql.ID
UserId mysql.ID
Type groupPower_e.GroupPowerStarType
Score mysql.Num
LastCalTs int64
CreatedTime time.Time `gorm:"->"`
UpdatedTime time.Time `gorm:"->"`
}
// 增加家族之星分数
func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
month := time.Now().Format("200601")
......@@ -45,6 +57,29 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
return nil
}
// 增加家族之星分数
func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType, score mysql.Num, lastCalTs int64) error {
star := &GroupPowerDayStar{
Date: time.Now(),
GroupPowerId: groupPowerId,
UserId: userId,
Type: _type,
Score: score,
LastCalTs: lastCalTs,
}
if err := model.DB().Model(GroupPowerDayStar{}).Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "date"}, {Name: "group_power_id"}, {Name: "user_id"}, {Name: "type"}},
DoUpdates: clause.Assignments(map[string]interface{}{
"score": gorm.Expr("score + ?", star.Score),
"last_cal_ts": lastCalTs,
}),
}).Create(star).Error; err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore fail:%v", err)
return err
}
return nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func GetGroupPowerMonthStar(model *domain.Model, groupPowerId, userId mysql.ID, _type groupPower_e.GroupPowerStarType) (*GroupPowerMonthStar, error) {
......
......@@ -493,6 +493,9 @@ func SendGift() {
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerMonthStarScore famous fail:%v", err)
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeFamous, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore famous fail:%v", err)
}
}
// 收礼加分
for _, userId := range sendGiftEvent.ReceiveUserIds {
......@@ -501,6 +504,9 @@ func SendGift() {
if err := groupPower_m.IncrGroupPowerMonthStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerMonthStarScore charm fail:%v", err)
}
if err := groupPower_m.IncrGroupPowerDayStarScore(model, data.GroupPowerId, data.UserId, groupPower_e.GroupPowerStarTypeCharm, diamonds, 0); err != nil {
model.Log.Errorf("IncrGroupPowerDayStarScore charm fail:%v", err)
}
}
}
return nil
......
......@@ -139,6 +139,7 @@ func InitRouter() *gin.Engine {
groupPower.GET("/rank/:period", wrapper(group_power_r.GroupPowerRank))
groupPower.GET("/rankTop", wrapper(group_power_r.GroupPowerRankTop))
groupPower.GET("/star", wrapper(group_power_r.GroupPowerStar))
groupPower.GET("/star/:period", wrapper(group_power_r.GroupPowerStar))
groupPower.POST("/info/set", wrapper(group_power_r.GroupPowerSetInfo))
}
h5GroupPower := v1.Group("/h5/groupPower")
......
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