Commit 3c6346df authored by hujiebin's avatar hujiebin

Merge branch 'feature/sheep' into 'master'

Feature/sheep

See merge request !3
parents a4e2ee30 47ebd317
......@@ -6,6 +6,8 @@ type MGetUserLevelData map[mysql.ID]CvUserLevel
type CvUserLevel struct {
UserId mysql.ID `json:"userId"` // 用户id
WealthUserGrade uint32 `json:"wealthUserGrade"` //财富等级
CharmUserGrade uint32 `json:"charmUserGrade"` //魅力等级
WealthUserGrade uint32 `json:"wealthUserGrade"` // 财富等级
CharmUserGrade uint32 `json:"charmUserGrade"` // 魅力等级
ActiveUserGrade uint32 `json:"activeUserGrade"` // 活跃等级
NobleLevel uint16 `json:"nobleLevel"` // 贵族等级
}
package noble_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"time"
......@@ -78,8 +79,8 @@ func GetNobleLevel(db *gorm.DB, userId uint64) (uint16, error) {
}
}
func BatchGetNobleLevel(db *gorm.DB, userIds []uint64) (map[uint64]uint16, error) {
m, err := BatchGetActiveNoble(db, userIds)
func BatchGetNobleLevel(model *domain.Model, userIds []uint64) (map[uint64]uint16, error) {
m, err := BatchGetActiveNoble(model, userIds)
if err != nil {
return nil, err
}
......@@ -90,10 +91,10 @@ func BatchGetNobleLevel(db *gorm.DB, userIds []uint64) (map[uint64]uint16, error
return result, nil
}
func BatchGetActiveNoble(db *gorm.DB, userIds []uint64) (map[uint64]UserNoble, error) {
func BatchGetActiveNoble(model *domain.Model, userIds []uint64) (map[uint64]UserNoble, error) {
ub := UserNoble{}
records, err := ub.batchGet(db, userIds)
records, err := ub.batchGet(model, userIds)
if err != nil {
return nil, err
}
......@@ -110,9 +111,9 @@ func BatchGetActiveNoble(db *gorm.DB, userIds []uint64) (map[uint64]UserNoble, e
}
// 查询用户未过期的贵族
func (ub *UserNoble) batchGet(db *gorm.DB, userIds []uint64) (map[uint64][]UserNoble, error) {
func (ub *UserNoble) batchGet(model *domain.Model, userIds []uint64) (map[uint64][]UserNoble, error) {
rows := make([]UserNoble, 0)
if err := db.Model(ub).Where("end_time>=NOW() AND user_id IN ?", userIds).Order("level DESC").Find(&rows).Error; err != nil {
if err := model.DB().Model(ub).Where("end_time>=NOW() AND user_id IN ?", userIds).Order("level DESC").Find(&rows).Error; err != nil {
return nil, err
}
result := make(map[uint64][]UserNoble, 0)
......
package user_m
import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
)
/**
* 用户活跃分数
**/
type MatchActityUserScore struct {
mysql.Entity
*domain.Model `gorm:"-"`
UserId mysql.ID
Score mysql.Num
Grade mysql.Num
}
// 获取活跃等级
func MGetActiveGrade(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]mysql.Num, error) {
res := make(map[mysql.ID]mysql.Num)
var rows []MatchActityUserScore
if err := mysql.Db.Model(&MatchActityUserScore{}).Where("user_id in ?", userIds).Find(&rows).Error; err != nil {
model.Log.Errorf("MGetActiveGrade fail:%v", err)
return res, err
}
for _, r := range rows {
res[r.UserId] = r.Grade
}
return res, nil
}
......@@ -7,6 +7,7 @@ import (
"github.com/gin-gonic/gin"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/bag_m"
"hilo-user/domain/model/noble_m"
"hilo-user/domain/model/res_m"
"hilo-user/domain/model/user_m"
"hilo-user/resp"
......@@ -34,12 +35,16 @@ func MGetUserLevels(c *gin.Context) (*mycontext.MyContext, error) {
return myCtx, err
}
charmGrade, err := user_m.MGetCharmGrade(model, req.Ids)
activeGrade, err := user_m.MGetActiveGrade(model, req.Ids)
nobleLevel, err := noble_m.BatchGetNobleLevel(model, req.Ids)
response := user_cv.MGetUserLevelData{}
for _, userId := range req.Ids {
response[userId] = user_cv.CvUserLevel{
UserId: userId,
WealthUserGrade: wealthGrade[userId],
CharmUserGrade: charmGrade[userId],
ActiveUserGrade: activeGrade[userId],
NobleLevel: nobleLevel[userId],
}
}
......
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