matchCharm.go 717 Bytes
Newer Older
chenweijian's avatar
chenweijian committed
1 2 3
package user_m

import (
hujiebin's avatar
hujiebin committed
4 5
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
chenweijian's avatar
chenweijian committed
6 7 8 9 10 11 12 13 14 15 16 17 18
)

/**
 * 用户魅力分数
 **/
type MatchCharmUserScore struct {
	mysql.Entity
	*domain.Model `gorm:"-"`
	UserId        mysql.ID
	Score         mysql.Num
	Grade         mysql.Num
}

hujiebin's avatar
hujiebin committed
19 20 21 22 23 24
// 批量获取魅力等级
func MGetCharmGrade(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]mysql.Num, error) {
	res := make(map[mysql.ID]mysql.Num)
	var charmUserScore []*MatchCharmUserScore
	if err := model.Db.Model(&MatchCharmUserScore{}).Where("user_id in ?", userIds).Find(&charmUserScore).Error; err != nil {
		return res, err
chenweijian's avatar
chenweijian committed
25
	}
hujiebin's avatar
hujiebin committed
26 27
	for _, r := range charmUserScore {
		res[r.UserId] = r.Grade
chenweijian's avatar
chenweijian committed
28
	}
hujiebin's avatar
hujiebin committed
29
	return res, nil
chenweijian's avatar
chenweijian committed
30
}