diff --git a/business/jxstore/cms/user2.go b/business/jxstore/cms/user2.go index 23ea882df..c1729ec22 100644 --- a/business/jxstore/cms/user2.go +++ b/business/jxstore/cms/user2.go @@ -380,6 +380,19 @@ func GetRoleUserList(ctx *jxcontext.Context, r *authz.RoleInfo) (userIDList []st return api2.RoleMan.GetRoleUserList(r) } +func GetRolesUserList(ctx *jxcontext.Context, rList []*authz.RoleInfo) (userIDMap map[string][]string, err error) { + userIDMap = make(map[string][]string) + for _, r := range rList { + userIDList, err2 := api2.RoleMan.GetRoleUserList(r) + if err = err2; err == nil { + userIDMap[r.GetFullName()] = userIDList + } else { + break + } + } + return userIDMap, err +} + func checkUserType(userID string, userType int8) (err error) { userList, _, err := dao.GetUsers(dao.GetDB(), 0, "", []string{userID}, "", "", 0, 0) if err != nil { diff --git a/controllers/cms_user2.go b/controllers/cms_user2.go index 9c8f21948..f045cac40 100644 --- a/controllers/cms_user2.go +++ b/controllers/cms_user2.go @@ -132,6 +132,37 @@ func (c *User2Controller) GetRoleUserList() { }) } +// @Title 批量得到角色包括的用户列表 +// @Description 批量得到角色包括的用户列表 +// @Param token header string true "认证token" +// @Param roleNames query string true "角色名" +// @Param storeIDs query string false "门店ID(如果是全局角色不用填)" +// @Success 200 {object} controllers.CallResult +// @Failure 200 {object} controllers.CallResult +// @router /GetRolesUserList [get] +func (c *User2Controller) GetRolesUserList() { + c.callGetRolesUserList(func(params *tUser2GetRolesUserListParams) (retVal interface{}, errCode string, err error) { + var roleNames []string + var storeIDs []int + if err = jxutils.Strings2Objs(params.RoleNames, &roleNames, params.StoreIDs, &storeIDs); err == nil { + var roleList []*authz.RoleInfo + for _, roleName := range roleNames { + if len(storeIDs) == 0 { + roleList = append(roleList, autils.NewRole(roleName, 0)) + } else { + if roleName == authz.StoreRoleBoss { + for _, storeID := range storeIDs { + roleList = append(roleList, autils.NewRole(roleName, storeID)) + } + } + } + } + retVal, err = cms.GetRolesUserList(params.Ctx, roleList) + } + return retVal, "", err + }) +} + // @Title 给指定用户添加角色列表 // @Description 给指定用户添加角色列表 // @Param token header string true "认证token"