瀏覽代碼

Merge branch 'master' of http://git.shengws.com/csx/XT_New

XMLWAN 5 年之前
父節點
當前提交
504ffccc6c

+ 61 - 58
controllers/base_api_controller.go 查看文件

2
 
2
 
3
 import (
3
 import (
4
 	"XT_New/enums"
4
 	"XT_New/enums"
5
+	"XT_New/models"
6
+	"XT_New/service"
5
 )
7
 )
6
 
8
 
7
 type BaseAPIController struct {
9
 type BaseAPIController struct {
60
 func (this *BaseAuthAPIController) Prepare() {
62
 func (this *BaseAuthAPIController) Prepare() {
61
 	this.BaseAPIController.Prepare()
63
 	this.BaseAPIController.Prepare()
62
 	if this.GetAdminUserInfo() == nil {
64
 	if this.GetAdminUserInfo() == nil {
63
-		//var userAdmin models.AdminUser
64
-		//userAdmin.Id = 380
65
-		//userAdmin.Mobile = "13532250447"
66
-		//userAdmin.IsSuperAdmin = true
67
-		//userAdmin.Status = 1
68
-		//userAdmin.CreateTime = 1530786071
69
-		//userAdmin.ModifyTime = 1530786071
70
-		//var subscibe models.ServeSubscibe
71
-		//subscibe.ID = 1
72
-		//subscibe.OrgId = 4
73
-		//subscibe.PeriodStart = 1538035409
74
-		//subscibe.PeriodEnd = 1569571409
75
-		//subscibe.State = 1
76
-		//subscibe.Status = 1
77
-		//subscibe.CreatedTime = 1538035409
78
-		//subscibe.UpdatedTime = 1538035409
79
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
80
-		//subscibes[4] = &subscibe
81
-		//
82
-		//var template models.GobalTemplate
83
-		//template.TemplateId = 2
84
-		//
85
-		//var adminUserInfo service.AdminUserInfo
86
-		//adminUserInfo.CurrentOrgId = 4
87
-		//adminUserInfo.CurrentAppId = 5
88
-		//adminUserInfo.AdminUser = &userAdmin
89
-		//adminUserInfo.Subscibes = subscibes
90
-		//this.SetSession("admin_user_info", &adminUserInfo)
91
-
92
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
93
-		this.StopRun()
65
+		var userAdmin models.AdminUser
66
+		//userAdmin.Id = 400
67
+		//userAdmin.Mobile = "13535547901"
68
+
69
+		userAdmin.Id = 597
70
+		userAdmin.Mobile = "19874122664"
71
+		userAdmin.IsSuperAdmin = false
72
+		userAdmin.Status = 1
73
+		userAdmin.CreateTime = 1530786071
74
+		userAdmin.ModifyTime = 1530786071
75
+		var subscibe models.ServeSubscibe
76
+		subscibe.ID = 1
77
+		subscibe.OrgId = 12
78
+		subscibe.PeriodStart = 1538035409
79
+		subscibe.PeriodEnd = 1569571409
80
+		subscibe.State = 1
81
+		subscibe.Status = 1
82
+		subscibe.CreatedTime = 1538035409
83
+		subscibe.UpdatedTime = 1538035409
84
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
85
+		subscibes[4] = &subscibe
86
+		var adminUserInfo service.AdminUserInfo
87
+		adminUserInfo.CurrentOrgId = 12
88
+		adminUserInfo.CurrentAppId = 18
89
+		adminUserInfo.AdminUser = &userAdmin
90
+		adminUserInfo.Subscibes = subscibes
91
+		this.SetSession("admin_user_info", &adminUserInfo)
92
+
93
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
94
+		//this.StopRun()
94
 	}
95
 	}
95
 
96
 
96
 	//if this.Ctx.Request.Method != "GET" {
97
 	//if this.Ctx.Request.Method != "GET" {
176
 func (this *BaseServeAPIController) Prepare() {
177
 func (this *BaseServeAPIController) Prepare() {
177
 	this.BaseAPIController.Prepare()
178
 	this.BaseAPIController.Prepare()
178
 	if this.GetAdminUserInfo() == nil {
179
 	if this.GetAdminUserInfo() == nil {
179
-		//var userAdmin models.AdminUser
180
-		//userAdmin.Id = 380
181
-		//userAdmin.Mobile = "13532250447"
182
-		//userAdmin.IsSuperAdmin = true
183
-		//userAdmin.Status = 1
184
-		//userAdmin.CreateTime = 1530786071
185
-		//userAdmin.ModifyTime = 1530786071
186
-		//var subscibe models.ServeSubscibe
187
-		//subscibe.ID = 1
188
-		//subscibe.OrgId = 4
189
-		//subscibe.PeriodStart = 1538035409
190
-		//subscibe.PeriodEnd = 1569571409
191
-		//subscibe.State = 1
192
-		//subscibe.Status = 1
193
-		//subscibe.CreatedTime = 1538035409
194
-		//subscibe.UpdatedTime = 1538035409
195
-		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
196
-		//subscibes[4] = &subscibe
197
-		//var adminUserInfo service.AdminUserInfo
198
-		//adminUserInfo.CurrentOrgId = 4
199
-		//adminUserInfo.CurrentAppId = 5
200
-		//adminUserInfo.AdminUser = &userAdmin
201
-		//adminUserInfo.Subscibes = subscibes
202
-		//this.SetSession("admin_user_info", &adminUserInfo)
203
-
204
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
205
-		this.StopRun()
180
+		var userAdmin models.AdminUser
181
+		//userAdmin.Id = 400
182
+		//userAdmin.Mobile = "13535547901"
183
+		userAdmin.Id = 597
184
+		userAdmin.Mobile = "19874122664"
185
+		userAdmin.IsSuperAdmin = false
186
+		userAdmin.Status = 1
187
+		userAdmin.CreateTime = 1530786071
188
+		userAdmin.ModifyTime = 1530786071
189
+		var subscibe models.ServeSubscibe
190
+		subscibe.ID = 1
191
+		subscibe.OrgId = 12
192
+		subscibe.PeriodStart = 1538035409
193
+		subscibe.PeriodEnd = 1569571409
194
+		subscibe.State = 1
195
+		subscibe.Status = 1
196
+		subscibe.CreatedTime = 1538035409
197
+		subscibe.UpdatedTime = 1538035409
198
+		subscibes := make(map[int64]*models.ServeSubscibe, 0)
199
+		subscibes[4] = &subscibe
200
+		var adminUserInfo service.AdminUserInfo
201
+		adminUserInfo.CurrentOrgId = 12
202
+		adminUserInfo.CurrentAppId = 18
203
+		adminUserInfo.AdminUser = &userAdmin
204
+		adminUserInfo.Subscibes = subscibes
205
+		this.SetSession("admin_user_info", &adminUserInfo)
206
+
207
+		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
208
+		//this.StopRun()
206
 	}
209
 	}
207
 }
210
 }
208
 
211
 

+ 0 - 1
controllers/mobile_api_controllers/login_api_controller.go 查看文件

129
 
129
 
130
 		//service.GetOrgSubscibeState(&subscibe)
130
 		//service.GetOrgSubscibeState(&subscibe)
131
 		templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
131
 		templateInfo, _ := service.GetOrgInfoTemplate(org.Id)
132
-
133
 		mobileAdminUserInfo := &MobileAdminUserInfo{
132
 		mobileAdminUserInfo := &MobileAdminUserInfo{
134
 			AdminUser:    &adminUser,
133
 			AdminUser:    &adminUser,
135
 			Org:          &org,
134
 			Org:          &org,

+ 10 - 0
controllers/mobile_api_controllers/mobile_api_base_controller.go 查看文件

66
 	//		this.StopRun()
66
 	//		this.StopRun()
67
 	//	}
67
 	//	}
68
 	//}
68
 	//}
69
+	if adminUserInfo.AppRole != nil {
70
+		app_role, _ := service.FindAppRoleById(adminUserInfo.AppRole.Id)
71
+		if app_role.Status != 1 {
72
+			this.DelSession("mobile_admin_user_info")
73
+			this.Ctx.SetCookie("token_cookie", "")
74
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeForbidden)
75
+			this.StopRun()
76
+		}
77
+
78
+	}
69
 
79
 
70
 	if this.Ctx.Request.Header.Get("Permission") == "1" {
80
 	if this.Ctx.Request.Header.Get("Permission") == "1" {
71
 		if !adminUserInfo.AdminUser.IsSuperAdmin || adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
81
 		if !adminUserInfo.AdminUser.IsSuperAdmin || adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {

+ 25 - 7
controllers/new_mobile_api_controllers/home_api_controller.go 查看文件

12
 	"net/http"
12
 	"net/http"
13
 	"net/url"
13
 	"net/url"
14
 	"strconv"
14
 	"strconv"
15
+	"strings"
15
 	"time"
16
 	"time"
16
 )
17
 )
17
 
18
 
39
 		}
40
 		}
40
 		orgs = RemoveRepeatedOrgElement(orgs)
41
 		orgs = RemoveRepeatedOrgElement(orgs)
41
 
42
 
43
+		var isSubSuperAdmin bool = false
44
+
45
+		app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
46
+		role_ids := strings.Split(app_role.RoleIds, ",")
47
+
48
+		if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
49
+			for _, item := range role_ids {
50
+				id, _ := strconv.ParseInt(item, 10, 64)
51
+				role, _ := service.GetRoleByRoleID(id)
52
+				if role.IsSystem == 1 && role.RoleName == "子管理员" {
53
+					isSubSuperAdmin = true
54
+				}
55
+			}
56
+		}
57
+
42
 		apps, err := service.GetAllApp(adminUserInfo.Org.Id)
58
 		apps, err := service.GetAllApp(adminUserInfo.Org.Id)
43
 		if err != nil {
59
 		if err != nil {
44
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
60
 			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeSystemError)
52
 		}
68
 		}
53
 
69
 
54
 		this.ServeSuccessJSON(map[string]interface{}{
70
 		this.ServeSuccessJSON(map[string]interface{}{
55
-			"orgs":        orgs,
56
-			"apps":        apps,
57
-			"banners":     banners,
58
-			"isCreateOrg": true,
71
+			"orgs":            orgs,
72
+			"apps":            apps,
73
+			"banners":         banners,
74
+			"isCreateOrg":     true,
75
+			"isSubSuperAdmin": isSubSuperAdmin,
59
 		})
76
 		})
60
 	} else {
77
 	} else {
61
 		apps, err := service.GetAllApp(0)
78
 		apps, err := service.GetAllApp(0)
70
 		}
87
 		}
71
 
88
 
72
 		this.ServeSuccessJSON(map[string]interface{}{
89
 		this.ServeSuccessJSON(map[string]interface{}{
73
-			"isCreateOrg": false,
74
-			"apps":        apps,
75
-			"banners":     banners,
90
+			"isCreateOrg":     false,
91
+			"apps":            apps,
92
+			"banners":         banners,
93
+			"isSubSuperAdmin": false,
76
 		})
94
 		})
77
 	}
95
 	}
78
 
96
 

+ 57 - 6
controllers/new_mobile_api_controllers/new_role_api_controller.go 查看文件

15
 }
15
 }
16
 
16
 
17
 func (this *NewRoleApiController) GetAllOrgUser() {
17
 func (this *NewRoleApiController) GetAllOrgUser() {
18
-
19
 	adminUserInfo := this.GetMobileAdminUserInfo()
18
 	adminUserInfo := this.GetMobileAdminUserInfo()
20
-	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 10)
19
+	var isSubSuperAdmin bool = false
20
+	app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
21
+	role_ids := strings.Split(app_role.RoleIds, ",")
22
+
23
+	if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
24
+		for _, item := range role_ids {
25
+			id, _ := strconv.ParseInt(item, 10, 64)
26
+			role, _ := service.GetRoleByRoleID(id)
27
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
28
+				isSubSuperAdmin = true
29
+			}
30
+		}
31
+	}
32
+	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, 1, 100)
21
 	this.ServeSuccessJSON(map[string]interface{}{
33
 	this.ServeSuccessJSON(map[string]interface{}{
22
-		"admins": viewModels,
34
+		"admins":          viewModels,
35
+		"isSubSuperAdmin": isSubSuperAdmin,
36
+		"org_creator":     adminUserInfo.Org.Creator,
23
 	})
37
 	})
24
 }
38
 }
25
 
39
 
29
 	name := this.GetString("name")
43
 	name := this.GetString("name")
30
 	userTitle := this.GetString("title")
44
 	userTitle := this.GetString("title")
31
 	roleIds := this.GetString("role_ids")
45
 	roleIds := this.GetString("role_ids")
46
+	user_type, _ := this.GetInt64("user_type", 0)
47
+	user_title, _ := this.GetInt64("user_title", 0)
48
+
49
+	//roleIds := this.GetString("role_ids")
50
+
32
 	if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
51
 	if adminUserId <= 0 || len(name) == 0 || len(roleIds) <= 0 {
33
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
52
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
34
 		return
53
 		return
47
 	appRole.UserTitleName = userTitle
66
 	appRole.UserTitleName = userTitle
48
 	appRole.RoleIds = roleIds
67
 	appRole.RoleIds = roleIds
49
 	appRole.ModifyTime = time.Now().Unix()
68
 	appRole.ModifyTime = time.Now().Unix()
69
+	appRole.UserType = int8(user_type)
70
+	appRole.UserTitle = int8(user_title)
50
 	saveErr := service.SaveAppRole(appRole)
71
 	saveErr := service.SaveAppRole(appRole)
51
 	if saveErr != nil {
72
 	if saveErr != nil {
52
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
73
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBUpdate)
57
 
78
 
58
 func (this *NewRoleApiController) GetEditAdminInitData() {
79
 func (this *NewRoleApiController) GetEditAdminInitData() {
59
 	adminUserInfo := this.GetMobileAdminUserInfo()
80
 	adminUserInfo := this.GetMobileAdminUserInfo()
60
-	roles, _ := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
81
+
82
+	roles, _ := service.GetNewAllOrgValidRoles(adminUserInfo.Org.Id)
61
 	this.ServeSuccessJSON(map[string]interface{}{
83
 	this.ServeSuccessJSON(map[string]interface{}{
62
 		"roles": roles,
84
 		"roles": roles,
63
 	})
85
 	})
66
 func (this *NewRoleApiController) GetAdminUserInfo() {
88
 func (this *NewRoleApiController) GetAdminUserInfo() {
67
 	adminUserInfo := this.GetMobileAdminUserInfo()
89
 	adminUserInfo := this.GetMobileAdminUserInfo()
68
 	adminUserId, _ := this.GetInt64("uid")
90
 	adminUserId, _ := this.GetInt64("uid")
91
+
69
 	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
92
 	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.Org.Id, adminUserInfo.App.Id, adminUserId)
70
 	if getAppRoleErr != nil {
93
 	if getAppRoleErr != nil {
71
 		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
94
 		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
120
 	name := this.GetString("name")
143
 	name := this.GetString("name")
121
 	role_ids := this.GetString("role_ids")
144
 	role_ids := this.GetString("role_ids")
122
 	userTitle := this.GetString("title")
145
 	userTitle := this.GetString("title")
146
+	user_type, _ := this.GetInt("user_type", 0)
147
+	user_title, _ := this.GetInt("user_title", 0)
123
 
148
 
124
 	if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
149
 	if len(mobile) == 0 || len(name) == 0 || len(role_ids) <= 0 {
125
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
150
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
133
 		return
158
 		return
134
 	} else {
159
 	} else {
135
 		if adminUser == nil { //新增账号和用户
160
 		if adminUser == nil { //新增账号和用户
136
-			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids)
161
+			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.Org.Id, adminUserInfo.App.Id, mobile, name, userTitle, role_ids, user_type, user_title)
137
 			if createErr != nil {
162
 			if createErr != nil {
138
 				//beego.Error("创建管理员失败:", createErr)
163
 				//beego.Error("创建管理员失败:", createErr)
139
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
164
 				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
160
 					Avatar:        "",
185
 					Avatar:        "",
161
 					UserName:      name,
186
 					UserName:      name,
162
 					UserTitleName: userTitle,
187
 					UserTitleName: userTitle,
188
+					UserTitle:     int8(user_title),
189
+					UserType:      int8(user_type),
163
 					Status:        1,
190
 					Status:        1,
164
 					CreateTime:    time.Now().Unix(),
191
 					CreateTime:    time.Now().Unix(),
165
 					ModifyTime:    time.Now().Unix(),
192
 					ModifyTime:    time.Now().Unix(),
184
 
211
 
185
 func (this *NewRoleApiController) GetAllOrgRole() {
212
 func (this *NewRoleApiController) GetAllOrgRole() {
186
 	adminUserInfo := this.GetMobileAdminUserInfo()
213
 	adminUserInfo := this.GetMobileAdminUserInfo()
187
-	roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id)
214
+
215
+	var isSubSuperAdmin bool = false
216
+
217
+	app_role, _ := service.GetAppRoleById(adminUserInfo.AppRole.Id)
218
+	role_ids := strings.Split(app_role.RoleIds, ",")
219
+
220
+	if adminUserInfo.AdminUser.Id != adminUserInfo.Org.Creator {
221
+		for _, item := range role_ids {
222
+			id, _ := strconv.ParseInt(item, 10, 64)
223
+			role, _ := service.GetRoleByRoleID(id)
224
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
225
+				isSubSuperAdmin = true
226
+			}
227
+		}
228
+	}
229
+	fmt.Println(isSubSuperAdmin)
230
+
231
+	roles, err := service.GetAllOrgValidRoles(adminUserInfo.Org.Id, isSubSuperAdmin)
188
 	if err != nil {
232
 	if err != nil {
189
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
233
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
190
 		return
234
 		return
234
 	role_name := this.GetString("name")
278
 	role_name := this.GetString("name")
235
 	role_desc := this.GetString("desc")
279
 	role_desc := this.GetString("desc")
236
 
280
 
281
+	total := service.FindRoleRecordByRoleName(role_name, adminUserInfo.Org.Id)
282
+	if total > 0 {
283
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
284
+		return
285
+
286
+	}
287
+
237
 	role := &models.Role{
288
 	role := &models.Role{
238
 		RoleName:     role_name,
289
 		RoleName:     role_name,
239
 		RoleIntro:    role_desc,
290
 		RoleIntro:    role_desc,

+ 2 - 2
controllers/new_mobile_api_controllers/role.json 查看文件

15
         "role_introduction": "医生角色能够进行建立患者档案,制定和调整患者透析治疗方案,定期评价病人的透析质量等",
15
         "role_introduction": "医生角色能够进行建立患者档案,制定和调整患者透析治疗方案,定期评价病人的透析质量等",
16
         "is_super_admin": false,
16
         "is_super_admin": false,
17
         "status": 1,
17
         "status": 1,
18
-        "is_system": 1,
18
+        "is_system": 2,
19
         "number": 9998,
19
         "number": 9998,
20
         "purview_ids": "71,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,15571,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,155",
20
         "purview_ids": "71,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,15571,72,70,74,75,73,127,128,48,52,110,93,121,122,124,125,120,101,100,102,156,157,158,159,155",
21
         "func_ids": "1,2,3,4,5,6,7,8,9,10,11,12,24,25,26,27,28,29,30,31,32,33"
21
         "func_ids": "1,2,3,4,5,6,7,8,9,10,11,12,24,25,26,27,28,29,30,31,32,33"
27
         "role_introduction": "护士角色能够进行病人透析管理,以及医院的感染控制与消毒记录等",
27
         "role_introduction": "护士角色能够进行病人透析管理,以及医院的感染控制与消毒记录等",
28
         "is_super_admin": false,
28
         "is_super_admin": false,
29
         "status": 1,
29
         "status": 1,
30
-        "is_system": 1,
30
+        "is_system": 3,
31
         "number": 9997,
31
         "number": 9997,
32
         "purview_ids": "74,75,73,48,52,110,93,121,122,124,125,120",
32
         "purview_ids": "74,75,73,48,52,110,93,121,122,124,125,120",
33
         "func_ids": "7,8,10,11,12,13,14,16,17,19,21,22,24,25,27,28"
33
         "func_ids": "7,8,10,11,12,13,14,16,17,19,21,22,24,25,27,28"

+ 270 - 143
controllers/role_controller.go 查看文件

31
 
31
 
32
 	beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
32
 	beego.Router("/api/admin/specialpermission/initdata", &RoleAPIController{}, "get:SpecialPermissionInitData")
33
 	beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
33
 	beego.Router("/api/admin/specialpermission/dialysisrecord/submit", &RoleAPIController{}, "post:SubmitDialysisRecordPermission")
34
+
35
+	beego.Router("/api/roles/list", &RoleAPIController{}, "get:GetAllOrgRole")
36
+	beego.Router("/api/staff", &RoleAPIController{}, "get:GetAllOrgUser")
37
+	beego.Router("/api/role/addStaff", &RoleAPIController{}, "post:AddRoleStaff")
38
+
39
+	beego.Router("/api/role/staff", &RoleAPIController{}, "get:GetRoleStaff")
40
+
34
 }
41
 }
35
 
42
 
36
 type RoleAPIController struct {
43
 type RoleAPIController struct {
43
 	page, _ := this.GetInt("page")
50
 	page, _ := this.GetInt("page")
44
 	adminUserInfo := this.GetAdminUserInfo()
51
 	adminUserInfo := this.GetAdminUserInfo()
45
 	//beego.Alert(adminUserInfo.AdminUser)
52
 	//beego.Alert(adminUserInfo.AdminUser)
46
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
47
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
48
-		return
49
-	}
50
-
53
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
54
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
55
+	//	return
56
+	//}
51
 	if page <= 0 {
57
 	if page <= 0 {
52
 		page = 1
58
 		page = 1
53
 	}
59
 	}
54
-	roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
60
+	roles, total, getRoleErr := service.GetRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
55
 	if getRoleErr != nil {
61
 	if getRoleErr != nil {
56
 		//beego.Error("获取角色列表失败:", getRoleErr)
62
 		//beego.Error("获取角色列表失败:", getRoleErr)
57
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
63
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
74
 		return
80
 		return
75
 	}
81
 	}
76
 	adminUserInfo := this.GetAdminUserInfo()
82
 	adminUserInfo := this.GetAdminUserInfo()
77
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
78
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
83
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
84
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
85
+	//	return
86
+	//}
87
+
88
+	total := service.FindRoleRecordByRoleName(name, adminUserInfo.CurrentOrgId)
89
+	if total > 0 {
90
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNameIsExist)
79
 		return
91
 		return
80
 	}
92
 	}
81
-
82
 	role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
93
 	role, createErr := service.CreateRole(adminUserInfo.AdminUser.Id, adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, name, intro)
83
 	if createErr != nil {
94
 	if createErr != nil {
84
 		//beego.Error("创建角色失败:", createErr)
95
 		//beego.Error("创建角色失败:", createErr)
105
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
116
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
106
 		return
117
 		return
107
 	}
118
 	}
108
-	adminUserInfo := this.GetAdminUserInfo()
109
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
110
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
111
-		return
112
-	}
119
+	//adminUserInfo := this.GetAdminUserInfo()
120
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
121
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
122
+	//	return
123
+	//}
113
 
124
 
114
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
125
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
115
 	if getRoleErr != nil {
126
 	if getRoleErr != nil {
145
 	}
156
 	}
146
 
157
 
147
 	adminUserInfo := this.GetAdminUserInfo()
158
 	adminUserInfo := this.GetAdminUserInfo()
148
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
149
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
150
-		return
151
-	}
159
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
160
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
161
+	//	return
162
+	//}
152
 
163
 
153
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
164
 	role, getRoleErr := service.GetRoleByRoleID(roleID)
154
 	if getRoleErr != nil {
165
 	if getRoleErr != nil {
185
 // /role/purview/editinit [get]
196
 // /role/purview/editinit [get]
186
 // @param role_id:int
197
 // @param role_id:int
187
 func (this *RoleAPIController) EditPurviewInitData() {
198
 func (this *RoleAPIController) EditPurviewInitData() {
188
-	adminUserInfo := this.GetAdminUserInfo()
189
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
190
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
191
-		return
192
-	}
199
+	//adminUserInfo := this.GetAdminUserInfo()
200
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
201
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
202
+	//	return
203
+	//}
193
 
204
 
194
 	roleId, _ := this.GetInt64("role_id")
205
 	roleId, _ := this.GetInt64("role_id")
195
 	if roleId <= 0 {
206
 	if roleId <= 0 {
220
 // @param purview_ids:string
231
 // @param purview_ids:string
221
 func (this *RoleAPIController) EditPurview() {
232
 func (this *RoleAPIController) EditPurview() {
222
 	adminUserInfo := this.GetAdminUserInfo()
233
 	adminUserInfo := this.GetAdminUserInfo()
223
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
224
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
225
-		return
226
-	}
234
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
235
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
236
+	//	return
237
+	//}
227
 	roleId, _ := this.GetInt64("role_id")
238
 	roleId, _ := this.GetInt64("role_id")
228
 	purviewIds := this.GetString("purview_ids")
239
 	purviewIds := this.GetString("purview_ids")
229
 	if roleId <= 0 {
240
 	if roleId <= 0 {
275
 // /api/adminmain [get]
286
 // /api/adminmain [get]
276
 func (this *RoleAPIController) AdminMainView() {
287
 func (this *RoleAPIController) AdminMainView() {
277
 	adminUserInfo := this.GetAdminUserInfo()
288
 	adminUserInfo := this.GetAdminUserInfo()
278
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
279
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
280
-		return
289
+
290
+	//org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
291
+
292
+	var isSubSuperAdmin bool = false
293
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
294
+
295
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
296
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
297
+
298
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
299
+
300
+	if adminUserInfo.AdminUser.Id != org.Creator {
301
+		for _, item := range role_ids {
302
+			id, _ := strconv.ParseInt(item, 10, 64)
303
+			role, _ := service.GetRoleByRoleID(id)
304
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
305
+				isSubSuperAdmin = true
306
+			}
307
+		}
281
 	}
308
 	}
282
 
309
 
283
-	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 10)
310
+	viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
284
 	if getAdminsErr != nil {
311
 	if getAdminsErr != nil {
285
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
312
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
286
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
313
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
287
 		return
314
 		return
288
 	}
315
 	}
289
 
316
 
290
-	existRoleCount, _ := service.GetValidRoleCount(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
291
-
292
 	this.ServeSuccessJSON(map[string]interface{}{
317
 	this.ServeSuccessJSON(map[string]interface{}{
293
-		"admins":        viewModels,
294
-		"total_count":   total,
295
-		"is_exist_role": existRoleCount > 0,
318
+		"admins":          viewModels,
319
+		"org":             org,
320
+		"isSubSuperAdmin": isSubSuperAdmin,
296
 	})
321
 	})
297
 }
322
 }
298
 
323
 
300
 // @param page?:int
325
 // @param page?:int
301
 func (this *RoleAPIController) Admins() {
326
 func (this *RoleAPIController) Admins() {
302
 	adminUserInfo := this.GetAdminUserInfo()
327
 	adminUserInfo := this.GetAdminUserInfo()
303
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
304
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
305
-		return
306
-	}
328
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
329
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
330
+	//	return
331
+	//}
307
 
332
 
308
 	page, _ := this.GetInt("page")
333
 	page, _ := this.GetInt("page")
309
-	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 10)
334
+	viewModels, total, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, page, 100)
310
 	if getAdminsErr != nil {
335
 	if getAdminsErr != nil {
311
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
336
 		//beego.Error("获取管理员列表失败:", getAdminsErr)
312
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
337
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
321
 // /api/admin/addinit [get]
346
 // /api/admin/addinit [get]
322
 func (this *RoleAPIController) AddAdminInitData() {
347
 func (this *RoleAPIController) AddAdminInitData() {
323
 	adminUserInfo := this.GetAdminUserInfo()
348
 	adminUserInfo := this.GetAdminUserInfo()
324
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
325
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
326
-		return
349
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
350
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
351
+	//	return
352
+	//}
353
+
354
+	var isSubSuperAdmin bool = false
355
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
356
+
357
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
358
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
359
+
360
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
361
+
362
+	if adminUserInfo.AdminUser.Id != org.Creator {
363
+		for _, item := range role_ids {
364
+			id, _ := strconv.ParseInt(item, 10, 64)
365
+			role, _ := service.GetRoleByRoleID(id)
366
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
367
+				isSubSuperAdmin = true
368
+			}
369
+		}
327
 	}
370
 	}
328
 
371
 
329
 	roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
372
 	roles, getRoleErr := service.GetAllValidRoles(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
338
 	qntoken, _ := redisClient.Get("qn_token").Result()
381
 	qntoken, _ := redisClient.Get("qn_token").Result()
339
 
382
 
340
 	this.ServeSuccessJSON(map[string]interface{}{
383
 	this.ServeSuccessJSON(map[string]interface{}{
341
-		"roles":   roles,
342
-		"qntoken": qntoken,
384
+		"roles":           roles,
385
+		"qntoken":         qntoken,
386
+		"isSubSuperAdmin": isSubSuperAdmin,
387
+		"org":             org,
343
 	})
388
 	})
344
 }
389
 }
345
 
390
 
352
 // @param intro?:string
397
 // @param intro?:string
353
 func (this *RoleAPIController) AddAdmin() {
398
 func (this *RoleAPIController) AddAdmin() {
354
 	adminUserInfo := this.GetAdminUserInfo()
399
 	adminUserInfo := this.GetAdminUserInfo()
355
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
356
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
357
-		return
358
-	}
400
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
401
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
402
+	//	return
403
+	//}
359
 
404
 
360
 	mobile := this.GetString("mobile")
405
 	mobile := this.GetString("mobile")
361
 	name := this.GetString("name")
406
 	name := this.GetString("name")
362
 	userType, _ := this.GetInt("type")
407
 	userType, _ := this.GetInt("type")
363
 	userTitle, _ := this.GetInt("title")
408
 	userTitle, _ := this.GetInt("title")
364
-	roleId, _ := this.GetInt64("role")
365
-	//intro := this.GetString("intro")
409
+	roleIds := this.GetString("role")
410
+	user_title_name := this.GetString("user_title_name")
366
 
411
 
367
-	_, titleExist := models.UserTitle[userTitle]
368
-	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
412
+	if len(mobile) == 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || len(roleIds) <= 0 {
369
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
413
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
370
 		return
414
 		return
371
 	}
415
 	}
372
 
416
 
373
-	isRoleExist, getRoleErr := service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
374
-	if getRoleErr != nil {
375
-		//beego.Error("查询角色是否存在时失败:", getRoleErr)
376
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
377
-		return
378
-	}
379
-	if !isRoleExist {
380
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
381
-		return
382
-	}
383
-
384
-	// 判断该应用是否已存在该手机号
385
-	if isMobileDidUsed, err := service.IsMobileDidUsedAtApp(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile); err != nil {
417
+	// 判断是否已存在该手机号
418
+	if adminUser, err := service.GetValidAdminUserByMobileReturnErr(mobile); err != nil {
386
 		//beego.Error("查询用户是否已被添加为管理员时失败:", err)
419
 		//beego.Error("查询用户是否已被添加为管理员时失败:", err)
387
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
420
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
388
 		return
421
 		return
389
 	} else {
422
 	} else {
390
-		if isMobileDidUsed {
391
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileDidUsedInApp)
392
-			return
393
-		}
394
-	}
423
+		if adminUser == nil { //新增账号和用户
424
+			_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, user_title_name, roleIds, userType, userTitle)
425
+			if createErr != nil {
426
+				//beego.Error("创建管理员失败:", createErr)
427
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
428
+				return
429
+
430
+			} else {
431
+				sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
432
+				if sendSMSErr != nil {
433
+				}
434
+
435
+				this.ServeSuccessJSON(nil)
436
+				return
437
+			}
438
+		} else {
439
+
440
+			total, _ := service.FindAdminUserByID(adminUser.Id, adminUserInfo.CurrentOrgId)
441
+
442
+			if total <= 0 {
443
+				//新增用户
444
+				app_role := &models.App_Role{
445
+					AdminUserId:   adminUser.Id,
446
+					OrgId:         adminUserInfo.CurrentOrgId,
447
+					AppId:         adminUserInfo.CurrentAppId,
448
+					Avatar:        "",
449
+					UserName:      name,
450
+					UserTitleName: user_title_name,
451
+					Status:        1,
452
+					UserType:      int8(userType),
453
+					UserTitle:     int8(userTitle),
454
+					CreateTime:    time.Now().Unix(),
455
+					ModifyTime:    time.Now().Unix(),
456
+					RoleIds:       roleIds,
457
+				}
458
+				err := service.CreateUserRole(app_role)
459
+				if err != nil {
460
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
461
+					return
462
+				}
463
+				this.ServeSuccessJSON(nil)
464
+			} else {
465
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRepeatCreateStaffException)
466
+				return
467
+			}
395
 
468
 
396
-	if isSuperAdmin, err := service.IsUserSuperAdminWithMobile(mobile); err != nil {
397
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeMobileNotExit)
398
-		return
399
-	} else {
400
-		if isSuperAdmin {
401
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleMobileIsSuperAdmin)
402
 			return
469
 			return
403
 		}
470
 		}
404
 	}
471
 	}
405
 
472
 
406
-	//TODO
407
-	//_, password, createErr := service.CreateGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, mobile, name, userType, userTitle, intro, roleId)
408
-	//if createErr != nil {
409
-	//	//beego.Error("创建管理员失败:", createErr)
410
-	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDBCreate)
411
-	//	return
412
-	//
413
-	//} else {
414
-	//	//beego.Trace("用户密码:", password)
415
-	//	// 发送短信通知这个手机号
416
-	//	sendSMSErr := service.SMSSendInviteMobileToJoinOrgAdmin(name, mobile, password)
417
-	//	if sendSMSErr != nil {
418
-	//		//beego.Error("发送邀请短信失败:%v", sendSMSErr)
419
-	//	}
420
-	//
421
-	//	this.ServeSuccessJSON(nil)
422
-	//	return
423
-	//}
424
 }
473
 }
425
 
474
 
426
 // /api/admin/editinit [get]
475
 // /api/admin/editinit [get]
427
 // @param uid:int
476
 // @param uid:int
428
 func (this *RoleAPIController) EditAdminInitData() {
477
 func (this *RoleAPIController) EditAdminInitData() {
429
 	adminUserInfo := this.GetAdminUserInfo()
478
 	adminUserInfo := this.GetAdminUserInfo()
430
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
431
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
432
-		return
433
-	}
434
 
479
 
435
 	admin_user_id, _ := this.GetInt64("uid")
480
 	admin_user_id, _ := this.GetInt64("uid")
436
 	if admin_user_id <= 0 {
481
 	if admin_user_id <= 0 {
438
 		return
483
 		return
439
 	}
484
 	}
440
 
485
 
441
-	adminUserViewModel, getInfoErr := service.GetGeneralAdminUser(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
442
-	if getInfoErr != nil {
443
-		//beego.Error("获取管理员信息失败:", getInfoErr)
486
+	appRole, getAppRoleErr := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, admin_user_id)
487
+	if getAppRoleErr != nil {
488
+		//beego.Error("查询管理员信息时失败:", getAppRoleErr)
444
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
489
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
445
 		return
490
 		return
446
 	}
491
 	}
447
-	if adminUserViewModel == nil {
492
+	if appRole == nil {
448
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
493
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeAdminUserNotExist)
449
 		return
494
 		return
450
 	}
495
 	}
456
 		return
501
 		return
457
 	}
502
 	}
458
 
503
 
504
+	var isSubSuperAdmin bool = false
505
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
506
+
507
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
508
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
509
+
510
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
511
+
512
+	if adminUserInfo.AdminUser.Id != org.Creator {
513
+		for _, item := range role_ids {
514
+			id, _ := strconv.ParseInt(item, 10, 64)
515
+			role, _ := service.GetRoleByRoleID(id)
516
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
517
+				isSubSuperAdmin = true
518
+			}
519
+		}
520
+	}
521
+
459
 	redisClient := service.RedisClient()
522
 	redisClient := service.RedisClient()
460
 	defer redisClient.Close()
523
 	defer redisClient.Close()
461
 	qntoken, _ := redisClient.Get("qn_token").Result()
524
 	qntoken, _ := redisClient.Get("qn_token").Result()
462
 
525
 
463
 	this.ServeSuccessJSON(map[string]interface{}{
526
 	this.ServeSuccessJSON(map[string]interface{}{
464
-		"admin":   adminUserViewModel,
465
-		"roles":   roles,
466
-		"qntoken": qntoken,
527
+		"admin":           appRole,
528
+		"roles":           roles,
529
+		"qntoken":         qntoken,
530
+		"isSubSuperAdmin": isSubSuperAdmin,
467
 	})
531
 	})
468
 }
532
 }
469
 
533
 
476
 // @param intro?:string
540
 // @param intro?:string
477
 func (this *RoleAPIController) EditAdmin() {
541
 func (this *RoleAPIController) EditAdmin() {
478
 	adminUserInfo := this.GetAdminUserInfo()
542
 	adminUserInfo := this.GetAdminUserInfo()
479
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
480
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
481
-		return
482
-	}
543
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
544
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
545
+	//	return
546
+	//}
483
 
547
 
484
 	adminUserId, _ := this.GetInt64("uid")
548
 	adminUserId, _ := this.GetInt64("uid")
485
 	name := this.GetString("name")
549
 	name := this.GetString("name")
486
 	userType, _ := this.GetInt("type")
550
 	userType, _ := this.GetInt("type")
487
 	userTitle, _ := this.GetInt("title")
551
 	userTitle, _ := this.GetInt("title")
488
-	roleId, _ := this.GetInt64("role")
552
+	roleIds := this.GetString("role")
489
 	intro := this.GetString("intro")
553
 	intro := this.GetString("intro")
554
+	user_title_name := this.GetString("user_title_name")
490
 
555
 
491
 	_, titleExist := models.UserTitle[userTitle]
556
 	_, titleExist := models.UserTitle[userTitle]
492
-	if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || roleId <= 0 {
557
+	if adminUserId <= 0 || len(name) == 0 || (userType != 2 && userType != 3 && userType != 4) || !titleExist || len(roleIds) <= 0 {
493
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
558
 		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeParamWrong)
494
 		return
559
 		return
495
 	}
560
 	}
505
 		return
570
 		return
506
 	}
571
 	}
507
 
572
 
508
-	isRoleExist, getRoleErr := service.IsRoleExist(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, roleId)
509
-	if getRoleErr != nil {
510
-		//beego.Error("查询角色是否存在时失败:", getRoleErr)
511
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
512
-		return
513
-	}
514
-	if !isRoleExist {
515
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
516
-		return
517
-	}
518
-
519
 	appRole.UserName = name
573
 	appRole.UserName = name
520
 	appRole.UserType = int8(userType)
574
 	appRole.UserType = int8(userType)
521
 	appRole.UserTitle = int8(userTitle)
575
 	appRole.UserTitle = int8(userTitle)
522
-	appRole.RoleId = roleId
576
+	appRole.RoleIds = roleIds
523
 	appRole.Intro = intro
577
 	appRole.Intro = intro
578
+	appRole.UserTitleName = user_title_name
524
 	appRole.ModifyTime = time.Now().Unix()
579
 	appRole.ModifyTime = time.Now().Unix()
525
 	saveErr := service.SaveAppRole(appRole)
580
 	saveErr := service.SaveAppRole(appRole)
526
 	if saveErr != nil {
581
 	if saveErr != nil {
537
 // @param enable:bool
592
 // @param enable:bool
538
 func (this *RoleAPIController) AdminSetStatus() {
593
 func (this *RoleAPIController) AdminSetStatus() {
539
 	adminUserInfo := this.GetAdminUserInfo()
594
 	adminUserInfo := this.GetAdminUserInfo()
540
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
541
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
542
-		return
543
-	}
595
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
596
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
597
+	//	return
598
+	//}
544
 
599
 
545
 	userID, _ := this.GetInt64("uid")
600
 	userID, _ := this.GetInt64("uid")
546
 	if userID <= 0 {
601
 	if userID <= 0 {
558
 	}
613
 	}
559
 
614
 
560
 	enable, _ := this.GetBool("enable")
615
 	enable, _ := this.GetBool("enable")
561
-	if enable == true {
562
-		if roleEnable, _ := service.IsRoleExist(appRole.OrgId, appRole.AppId, appRole.RoleId); roleEnable == false {
563
-			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeRoleNotExist)
564
-			return
565
-		}
566
-	}
567
 
616
 
568
 	if enable {
617
 	if enable {
569
 		appRole.Status = 1
618
 		appRole.Status = 1
584
 // /api/admin/specialpermission/initdata [get]
633
 // /api/admin/specialpermission/initdata [get]
585
 func (this *RoleAPIController) SpecialPermissionInitData() {
634
 func (this *RoleAPIController) SpecialPermissionInitData() {
586
 	adminUserInfo := this.GetAdminUserInfo()
635
 	adminUserInfo := this.GetAdminUserInfo()
587
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
588
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
589
-		return
590
-	}
636
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
637
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
638
+	//	return
639
+	//}
591
 
640
 
592
 	adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
641
 	adminUsers, getAdminUsersErr := service.GetAllGeneralAdminUsers(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId)
593
 	if getAdminUsersErr != nil {
642
 	if getAdminUsersErr != nil {
613
 // @param ids:string ("1,2,5")
662
 // @param ids:string ("1,2,5")
614
 func (this *RoleAPIController) SubmitDialysisRecordPermission() {
663
 func (this *RoleAPIController) SubmitDialysisRecordPermission() {
615
 	adminUserInfo := this.GetAdminUserInfo()
664
 	adminUserInfo := this.GetAdminUserInfo()
616
-	if adminUserInfo.AdminUser.IsSuperAdmin == false {
617
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
618
-		return
619
-	}
665
+	//if adminUserInfo.AdminUser.IsSuperAdmin == false {
666
+	//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodePermissionDenied)
667
+	//	return
668
+	//}
620
 
669
 
621
 	idsString := this.GetString("ids")
670
 	idsString := this.GetString("ids")
622
 	if len(idsString) == 0 {
671
 	if len(idsString) == 0 {
712
 	}
761
 	}
713
 
762
 
714
 }
763
 }
764
+
765
+func (this *RoleAPIController) GetAllOrgRole() {
766
+	adminUserInfo := this.GetAdminUserInfo()
767
+
768
+	var isSubSuperAdmin bool = false
769
+	adminUserRole, _ := service.GetAppRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, adminUserInfo.AdminUser.Id)
770
+
771
+	//app_role, _ := service.GetAppRoleById(adminUserInfo.)
772
+	role_ids := strings.Split(adminUserRole.RoleIds, ",")
773
+
774
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
775
+
776
+	if adminUserInfo.AdminUser.Id != org.Creator {
777
+		for _, item := range role_ids {
778
+			id, _ := strconv.ParseInt(item, 10, 64)
779
+			role, _ := service.GetRoleByRoleID(id)
780
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
781
+				isSubSuperAdmin = true
782
+			}
783
+		}
784
+	}
785
+
786
+	roles, err := service.GetAllOrgValidRoles(adminUserInfo.CurrentOrgId, isSubSuperAdmin)
787
+	if err != nil {
788
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
789
+		return
790
+	} else {
791
+		this.ServeSuccessJSON(map[string]interface{}{
792
+			"roles": roles,
793
+		})
794
+	}
795
+
796
+}
797
+
798
+func (this *RoleAPIController) GetAllOrgUser() {
799
+	adminUserInfo := this.GetAdminUserInfo()
800
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
801
+	viewModels, _, _ := service.GetAllAdminUsersAndRole(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
802
+	this.ServeSuccessJSON(map[string]interface{}{
803
+		"admins": viewModels,
804
+		"org":    org,
805
+	})
806
+}
807
+
808
+func (this *RoleAPIController) AddRoleStaff() {
809
+	//adminUserInfo := this.GetMobileAdminUserInfo()
810
+	role_id, _ := this.GetInt64("id", 0)
811
+	staff_ids := this.GetString("ids")
812
+	ids := strings.Split(staff_ids, ",")
813
+	for _, item := range ids {
814
+		id, _ := strconv.ParseInt(item, 10, 64)
815
+		role, _ := service.FindAdminUserID(id)
816
+		role.RoleIds = role.RoleIds + "," + strconv.FormatInt(role_id, 10)
817
+		service.SaveAdminUser(&role)
818
+	}
819
+	this.ServeSuccessJSON(map[string]interface{}{
820
+		"msg": "添加成功",
821
+	})
822
+
823
+}
824
+
825
+func (this *RoleAPIController) GetRoleStaff() {
826
+	adminUserInfo := this.GetAdminUserInfo()
827
+
828
+	viewModels, _, getAdminsErr := service.GetAdminUsersAndLoginInfo(adminUserInfo.CurrentOrgId, adminUserInfo.CurrentAppId, 1, 100)
829
+	if getAdminsErr != nil {
830
+		//beego.Error("获取管理员列表失败:", getAdminsErr)
831
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
832
+		return
833
+	}
834
+	org, _ := service.GetOrgById(adminUserInfo.CurrentOrgId)
835
+
836
+	this.ServeSuccessJSON(map[string]interface{}{
837
+		"admins": viewModels,
838
+		"org":    org,
839
+	})
840
+
841
+}

+ 7 - 0
enums/error_code.go 查看文件

184
 	ErrorCodeRegisterExist = 20033
184
 	ErrorCodeRegisterExist = 20033
185
 
185
 
186
 	ErrorCodeRepeatCreateStaffException = 20034
186
 	ErrorCodeRepeatCreateStaffException = 20034
187
+
188
+	ErrorCodeForbidden       = 20035
189
+	ErrorCodeRoleNameIsExist = 20036
187
 )
190
 )
188
 
191
 
189
 var ErrCodeMsgs = map[int]string{
192
 var ErrCodeMsgs = map[int]string{
367
 	ErrorCodeRegisterExist: "该账号已经注册,请登录",
370
 	ErrorCodeRegisterExist: "该账号已经注册,请登录",
368
 
371
 
369
 	ErrorCodeRepeatCreateStaffException: "该员工已经存在无法继续添加",
372
 	ErrorCodeRepeatCreateStaffException: "该员工已经存在无法继续添加",
373
+
374
+	ErrorCodeForbidden: "你已经被管理员禁用,无法使用该系统",
375
+
376
+	ErrorCodeRoleNameIsExist: "该角色已经不存在",
370
 }
377
 }
371
 
378
 
372
 type SGJError struct {
379
 type SGJError struct {

+ 5 - 3
models/role_models.go 查看文件

54
 	UserTitleName string    `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
54
 	UserTitleName string    `gorm:"column:user_title_name" json:"user_title_name" form:"user_title_name"`
55
 	RoleIds       string    `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
55
 	RoleIds       string    `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
56
 	AdminUser     AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"admin"`
56
 	AdminUser     AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"admin"`
57
-	Message       string    `gorm:"column:message" json:"message" form:"message"`
58
-	Sex           int64     `gorm:"column:sex" json:"sex" form:"sex"`
59
-	Birthday      int64     `gorm:"column:birthday" json:"birthday" form:"birthday"`
57
+	//AdminUser     AdminUser `gorm:"ForeignKey:ID;AssociationForeignKey:AdminUserId" json:"admin"`
58
+	IsSubSuperAdmin bool   `gorm:"-" json:"is_sub_super_admin" form:"is_sub_super_admin"`
59
+	Message         string `gorm:"column:message" json:"message" form:"message"`
60
+	Sex             int64  `gorm:"column:sex" json:"sex" form:"sex"`
61
+	Birthday        int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
60
 }
62
 }
61
 
63
 
62
 func (App_Role) TableName() string {
64
 func (App_Role) TableName() string {

+ 2 - 2
models/vm_models.go 查看文件

309
 	Ctime            int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
309
 	Ctime            int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
310
 	Mtime            int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
310
 	Mtime            int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
311
 	Number           int64  `gorm:"column:number" json:"number" form:"number"`
311
 	Number           int64  `gorm:"column:number" json:"number" form:"number"`
312
-	PurviewIds       string `gorm:"column:-" json:"purview_ids" form:"purview_ids"`
313
-	FuncIds          string `gorm:"column:-" json:"func_ids" form:"func_ids"`
312
+	PurviewIds       string `gorm:"-" json:"purview_ids" form:"purview_ids"`
313
+	FuncIds          string `gorm:"-" json:"func_ids" form:"func_ids"`
314
 	IsSystem         int64  `gorm:"column:is_system" json:"is_system" form:"is_system"`
314
 	IsSystem         int64  `gorm:"column:is_system" json:"is_system" form:"is_system"`
315
 }
315
 }
316
 
316
 

+ 13 - 0
service/login_service.go 查看文件

231
 	}
231
 	}
232
 	return count > 0
232
 	return count > 0
233
 }
233
 }
234
+
235
+func FindAppRoleById(id int64) (*models.App_Role, error) {
236
+	var model models.App_Role
237
+	err := readUserDb.Model(&models.App_Role{}).Where("id = ? ", id).First(&model).Error
238
+	if err != nil {
239
+		if err == gorm.ErrRecordNotFound {
240
+			return nil, nil
241
+		} else {
242
+			return nil, err
243
+		}
244
+	}
245
+	return &model, nil
246
+}

+ 93 - 9
service/role_service.go 查看文件

2
 
2
 
3
 import (
3
 import (
4
 	"database/sql"
4
 	"database/sql"
5
+	"fmt"
6
+	"strconv"
7
+	"strings"
5
 	"time"
8
 	"time"
6
 
9
 
7
 	"XT_New/models"
10
 	"XT_New/models"
39
 			return nil, err
42
 			return nil, err
40
 		}
43
 		}
41
 	}
44
 	}
45
+
46
+	role_ids := strings.Split(appRole.RoleIds, ",")
47
+
48
+	for _, item := range role_ids {
49
+		id, _ := strconv.ParseInt(item, 10, 64)
50
+		role, _ := GetRoleByRoleID(id)
51
+		if role.IsSystem == 1 && role.RoleName == "子管理员" {
52
+			appRole.IsSubSuperAdmin = true
53
+		}
54
+	}
55
+
42
 	return &appRole, nil
56
 	return &appRole, nil
43
 }
57
 }
44
 
58
 
108
 	Ctime       int64  `gorm:"ctime" json:"last_login_time"`
122
 	Ctime       int64  `gorm:"ctime" json:"last_login_time"`
109
 	Status      int    `gorm:"status" json:"status"`
123
 	Status      int    `gorm:"status" json:"status"`
110
 	Avatar      string `gorm:"avatar" json:"avatar"`
124
 	Avatar      string `gorm:"avatar" json:"avatar"`
111
-
125
+	RoleIds     string `gorm:"role_ids" json:"role_ids"`
112
 	// LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
126
 	// LastLoginTimeStr string `gorm:"-" json:"last_login_time_formatted"`
113
-	TitleName string `gorm:"-" json:"title_name"`
127
+	TitleName       string `gorm:"-" json:"title_name"`
128
+	IsSubSuperAdmin bool   `gorm:"-" json:"is_sub_super_admin"`
129
+	//mobile          string `gorm:"-" json:"mobile"`
114
 }
130
 }
115
 
131
 
116
 func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int, count int) ([]*AdminUserManageViewModel, int, error) {
132
 func GetAdminUsersAndLoginInfo(orgID int64, appID int64, page int, count int) ([]*AdminUserManageViewModel, int, error) {
121
 		page = 1
137
 		page = 1
122
 	}
138
 	}
123
 	var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
139
 	var viewModels []*AdminUserManageViewModel = make([]*AdminUserManageViewModel, 0)
124
-	rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_r.role_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status,u_a_r.avatar FROM sgj_user_admin_role AS u_a_r INNER JOIN sgj_user_role AS u_r ON u_a_r.org_id = u_r.org_id AND u_a_r.app_id = u_r.app_id AND u_r.id = u_a_r.role_id LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, ctime FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ? ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
140
+	rows, err := readUserDb.Raw("SELECT u_a_r.admin_user_id, u_a_r.user_name, u_a_r.user_title, u_l.ip, u_l.ctime, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  LEFT JOIN (SELECT * FROM (SELECT admin_user_id, org_id, app_id, ip, ctime FROM sgj_user_admin_login_log WHERE org_id = ? AND app_id = ?  ORDER BY ctime DESC) AS t GROUP BY admin_user_id) AS u_l ON u_a_r.org_id = u_l.org_id AND u_a_r.app_id = u_l.app_id AND u_a_r.admin_user_id = u_l.admin_user_id WHERE u_a_r.org_id = ? AND u_a_r.app_id = ? AND user_type != 1 GROUP BY u_a_r.admin_user_id LIMIT ? OFFSET ?;", orgID, appID, orgID, appID, count, (page-1)*count).Rows()
125
 	defer rows.Close()
141
 	defer rows.Close()
126
 	if err != nil {
142
 	if err != nil {
127
 		if err == gorm.ErrRecordNotFound {
143
 		if err == gorm.ErrRecordNotFound {
143
 		// }
159
 		// }
144
 		viewModels = append(viewModels, &viewModel)
160
 		viewModels = append(viewModels, &viewModel)
145
 	}
161
 	}
162
+
163
+	for _, item := range viewModels {
164
+		ids := strings.Split(item.RoleIds, ",")
165
+		for _, id := range ids {
166
+			id, _ := strconv.ParseInt(id, 10, 64)
167
+			role, _ := GetRoleByRoleID(id)
168
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
169
+				item.IsSubSuperAdmin = true
170
+			}
171
+
172
+			if len(item.RoleName) == 0 {
173
+				item.RoleName = role.RoleName
174
+			} else {
175
+				item.RoleName = item.RoleName + "," + role.RoleName
176
+			}
177
+		}
178
+
179
+		//admin, _ := GetAdminUserByUserID(int64(item.AdminUserId))
180
+		//item.mobile = admin.Mobile
181
+
182
+	}
183
+
146
 	total := 0
184
 	total := 0
147
-	readUserDb.Table("sgj_user_admin_role as u_a_r").Joins("join sgj_user_role as u_r on u_r.org_id = u_a_r.org_id AND u_r.app_id = u_a_r.app_id AND u_r.id = u_a_r.role_id").Where("u_a_r.org_id = ? AND u_a_r.app_id = ?", orgID, appID).Count(&total)
185
+	//readUserDb.Table("sgj_user_admin_role as u_a_r").Joins("join sgj_user_role as u_r on u_r.org_id = u_a_r.org_id AND u_r.app_id = u_a_r.app_id AND u_r.id = u_a_r.role_id").Where("u_a_r.org_id = ? AND u_a_r.app_id = ?", orgID, appID).Count(&total)
148
 	return viewModels, total, nil
186
 	return viewModels, total, nil
149
 }
187
 }
150
 
188
 
260
 	return user.IsSuperAdmin, nil
298
 	return user.IsSuperAdmin, nil
261
 }
299
 }
262
 
300
 
263
-func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userTitle string, roleIds string) (*models.AdminUser, string, error) {
301
+func CreateGeneralAdminUser(orgID int64, appID int64, mobile string, name string, userTitle string, roleIds string, user_type int, user_title int) (*models.AdminUser, string, error) {
264
 	now := time.Now().Unix()
302
 	now := time.Now().Unix()
265
 	tx := writeUserDb.Begin()
303
 	tx := writeUserDb.Begin()
266
 	var adminUser models.AdminUser
304
 	var adminUser models.AdminUser
290
 		Avatar:        "",
328
 		Avatar:        "",
291
 		UserName:      name,
329
 		UserName:      name,
292
 		UserTitleName: userTitle,
330
 		UserTitleName: userTitle,
331
+		UserTitle:     int8(user_title),
332
+		UserType:      int8(user_type),
293
 		Status:        1,
333
 		Status:        1,
294
 		CreateTime:    now,
334
 		CreateTime:    now,
295
 		ModifyTime:    now,
335
 		ModifyTime:    now,
413
 	return &apps, nil
453
 	return &apps, nil
414
 }
454
 }
415
 
455
 
416
-func GetAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
456
+func GetAllOrgValidRoles(orgID int64, isSubSuperAdmin bool) ([]*models.Role, error) {
417
 	var roles []*models.Role
457
 	var roles []*models.Role
418
-	err := readUserDb.Model(models.Role{}).
419
-		Where("org_id = ? AND status = 1", orgID).
458
+	db := readUserDb.Model(models.Org{})
459
+	if isSubSuperAdmin {
460
+		fmt.Println("1111")
461
+		db = db.Where("role_name != '子管理员' AND is_system  != 1")
462
+	}
463
+	err := db.Where("org_id = ? AND status = 1", orgID).
420
 		Order("number desc,ctime").
464
 		Order("number desc,ctime").
421
 		Find(&roles).
465
 		Find(&roles).
422
 		Error
466
 		Error
490
 	Status      int    `gorm:"status" json:"status"`
534
 	Status      int    `gorm:"status" json:"status"`
491
 	Avatar      string `gorm:"avatar" json:"avatar"`
535
 	Avatar      string `gorm:"avatar" json:"avatar"`
492
 	RoleIds     string `gorm:"role_ids" json:"role_ids"`
536
 	RoleIds     string `gorm:"role_ids" json:"role_ids"`
537
+	IsSubAdmin  bool   `gorm:"-" json:"is_sub_admin"`
493
 }
538
 }
494
 
539
 
495
 func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*NewAdminUserModel, int, error) {
540
 func GetAllAdminUsersAndRole(orgID int64, appID int64, page int, count int) ([]*NewAdminUserModel, int, error) {
496
 	var viewModels []*NewAdminUserModel = make([]*NewAdminUserModel, 0)
541
 	var viewModels []*NewAdminUserModel = make([]*NewAdminUserModel, 0)
497
 	var rows *sql.Rows
542
 	var rows *sql.Rows
498
 	var err error
543
 	var err error
499
-	rows, err = readUserDb.Raw("SELECT u_a_r.id, u_a_r.admin_user_id, u_a_r.user_name,  u_a_r.user_title, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  WHERE org_id = ? AND app_id = ? AND user_type <> 1 ORDER BY ctime DESC", orgID, appID).Rows()
544
+	rows, err = readUserDb.Raw("SELECT u_a_r.id, u_a_r.admin_user_id, u_a_r.user_name,  u_a_r.user_title, u_a_r.status,u_a_r.avatar,u_a_r.role_ids FROM sgj_user_admin_role AS u_a_r  WHERE org_id = ? AND app_id = ? ORDER BY ctime DESC", orgID, appID).Rows()
500
 	defer rows.Close()
545
 	defer rows.Close()
501
 	if err != nil {
546
 	if err != nil {
502
 		if err == gorm.ErrRecordNotFound {
547
 		if err == gorm.ErrRecordNotFound {
510
 		readUserDb.ScanRows(rows, &viewModel)
555
 		readUserDb.ScanRows(rows, &viewModel)
511
 		viewModels = append(viewModels, &viewModel)
556
 		viewModels = append(viewModels, &viewModel)
512
 	}
557
 	}
558
+
559
+	for _, items := range viewModels {
560
+		ids := strings.Split(items.RoleIds, ",")
561
+		for _, ids := range ids {
562
+			id, _ := strconv.ParseInt(ids, 10, 64)
563
+			role, _ := GetRoleByRoleID(id)
564
+			if role.IsSystem == 1 && role.RoleName == "子管理员" {
565
+				items.IsSubAdmin = true
566
+			}
567
+		}
568
+	}
569
+
513
 	total := 0
570
 	total := 0
514
 	return viewModels, total, nil
571
 	return viewModels, total, nil
515
 }
572
 }
598
 	return purview.ErrorMsg, err
655
 	return purview.ErrorMsg, err
599
 
656
 
600
 }
657
 }
658
+
659
+func GetNewAllOrgValidRoles(orgID int64) ([]*models.Role, error) {
660
+	var roles []*models.Role
661
+	db := readUserDb.Model(models.Org{})
662
+	err := db.Where("org_id = ? AND status = 1", orgID).
663
+		Order("number desc,ctime").
664
+		Find(&roles).
665
+		Error
666
+	if err != nil {
667
+		if err == gorm.ErrRecordNotFound {
668
+			return make([]*models.Role, 0), nil
669
+		} else {
670
+			return nil, err
671
+		}
672
+	}
673
+	for _, item := range roles {
674
+		var total int64
675
+		readUserDb.Model(&models.App_Role{}).Where("org_id = ? AND find_in_set(?, role_ids)", orgID, item.Id).Count(&total)
676
+		item.StaffNumber = total
677
+	}
678
+	return roles, nil
679
+}
680
+
681
+func FindRoleRecordByRoleName(name string, org_id int64) (total int64) {
682
+	readUserDb.Model(&models.Role{}).Where("status = 1 AND role_name = ? AND org_id = ?", name, org_id).Count(&total)
683
+	return
684
+}