matchWealth.go 724 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 MatchWealthUserScore 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 MGetWealthGrade(model *domain.Model, userIds []mysql.ID) (map[mysql.ID]mysql.Num, error) {
	res := make(map[mysql.ID]mysql.Num)
	var wealthUserScore []*MatchWealthUserScore
	if err := model.Db.Model(&MatchWealthUserScore{}).Where("user_id in ?", userIds).Find(&wealthUserScore).Error; err != nil {
		return res, err
chenweijian's avatar
chenweijian committed
25
	}
hujiebin's avatar
hujiebin committed
26 27
	for _, r := range wealthUserScore {
		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
}