inner.go 2.85 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8
package group_power_r

import (
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/mycontext"
	"git.hilo.cn/hilo-common/resource/mysql"
	"github.com/gin-gonic/gin"
	"hilo-group/_const/enum/groupPower_e"
hujiebin's avatar
hujiebin committed
9
	"hilo-group/_const/enum/msg_e"
hujiebin's avatar
hujiebin committed
10 11
	"hilo-group/cv/group_power_cv"
	"hilo-group/domain/model/groupPower_m"
hujiebin's avatar
hujiebin committed
12 13
	"hilo-group/domain/model/msg_m"
	"hilo-group/domain/model/user_m"
hujiebin's avatar
hujiebin committed
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
	"hilo-group/resp"
)

type MGetGroupPowerReq struct {
	Ids []mysql.ID `form:"ids" binding:"required"`
}

// @Tags 国家势力-内部
// @Summary 批量获取国家势力信息
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Success 200 {object} map[mysql.ID]group_power_cv.CvGroupPowerInfo
// @Router /inner/groupPower/infos [get]
func MGetGroupPowers(c *gin.Context) (*mycontext.MyContext, error) {
	myCtx := mycontext.CreateMyContext(c.Keys)
	var model = domain.CreateModelContext(myCtx)
	var req MGetGroupPowerReq
	if err := c.ShouldBindQuery(&req); err != nil {
		return myCtx, err
	}
	groupPowers, err := groupPower_m.MGetGroupPowerInfoMap(model, req.Ids)
	if err != nil {
		return myCtx, err
	}
	groupPowerUsers, err := groupPower_m.MGetGroupPowerUsers(model, req.Ids)
	if err != nil {
		return myCtx, err
	}
	groupPowerGrade, err := groupPower_m.MGetGroupPowerGrade(model, req.Ids)
	if err != nil {
		return myCtx, err
	}
	response := make(map[mysql.ID]group_power_cv.CvGroupPowerInfo)
	for groupPowerId, info := range groupPowers {
		// 成员上限
48
		var memberMax mysql.Num
hujiebin's avatar
hujiebin committed
49 50
		grade := groupPowerGrade[groupPowerId].Grade
		if grade >= groupPower_e.GroupPowerGrade0 && grade <= groupPower_e.GroupPowerGradeMax {
51
			memberMax = mysql.Num(group_power_cv.GroupPowerGradePrivilegeNum[groupPowerGrade[groupPowerId].Grade][0].Num)
hujiebin's avatar
hujiebin committed
52 53
		}
		memberNum := mysql.Num(len(groupPowerUsers[groupPowerId]))
54 55
		if memberNum > memberMax {
			memberMax = memberNum
hujiebin's avatar
hujiebin committed
56 57 58
		}
		response[groupPowerId] = group_power_cv.CvGroupPowerInfo{
			CvGroupPowerBase: group_power_cv.CvGroupPowerBase{
59 60 61 62
				Id:        groupPowerId,
				Icon:      info.Icon,
				Name:      info.Name,
				Nameplate: info.Nameplate,
hujiebin's avatar
hujiebin committed
63 64
			},
			CvGroupPowerMember: group_power_cv.CvGroupPowerMember{
65 66
				MemberNum: memberNum,
				MemberMax: memberMax,
hujiebin's avatar
hujiebin committed
67
			},
hujiebin's avatar
hujiebin committed
68 69 70 71
			CvGroupPowerGrade: group_power_cv.CvGroupPowerGrade{
				Grade: grade,
				Exp:   groupPowerGrade[groupPowerId].Exp,
			},
hujiebin's avatar
hujiebin committed
72 73 74 75 76
		}
	}
	resp.ResponseOk(c, response)
	return myCtx, nil
}
hujiebin's avatar
hujiebin committed
77 78 79

func Test(c *gin.Context) (*mycontext.MyContext, error) {
	var model = domain.CreateModelNil()
80
	if err := msg_m.NewUserRecord(model, 4549, msg_e.GroupPowerExpireNotice, "", 4549, "", "", "", "", "").Persistent(); err != nil {
hujiebin's avatar
hujiebin committed
81 82
		return nil, err
	}
83
	mgrUser, _ := user_m.GetUser(model, 4549)
hujiebin's avatar
hujiebin committed
84 85 86 87
	err := msg_m.SendEmasMsgAssistant(model, mgrUser.ExternalId, mgrUser.DeviceType)
	if err != nil {
		return nil, err
	}
hujiebin's avatar
hujiebin committed
88 89 90 91
	//err := emas.SendIosMsgAll("全部消息测试")
	//if err != nil {
	//	return nil, err
	//}
hujiebin's avatar
hujiebin committed
92 93
	return nil, nil
}