Przeglądaj źródła

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

csx 4 lat temu
rodzic
commit
6a0e075c63

+ 39 - 32
controllers/base_api_controller.go Wyświetl plik

@@ -62,37 +62,37 @@ type BaseAuthAPIController struct {
62 62
 func (this *BaseAuthAPIController) Prepare() {
63 63
 	this.BaseAPIController.Prepare()
64 64
 	if this.GetAdminUserInfo() == nil {
65
-		var userAdmin models.AdminUser
66
-		userAdmin.Id = 380
67
-		userAdmin.Mobile = "13532250447"
68
-		userAdmin.IsSuperAdmin = true
69
-		userAdmin.Status = 1
70
-		userAdmin.CreateTime = 1530786071
71
-		userAdmin.ModifyTime = 1530786071
72
-		var subscibe models.ServeSubscibe
73
-		subscibe.ID = 1
74
-		subscibe.OrgId = 4
75
-		subscibe.PeriodStart = 1538035409
76
-		subscibe.PeriodEnd = 1569571409
77
-		subscibe.State = 1
78
-		subscibe.Status = 1
79
-		subscibe.CreatedTime = 1538035409
80
-		subscibe.UpdatedTime = 1538035409
81
-		subscibes := make(map[int64]*models.ServeSubscibe, 0)
82
-		subscibes[4] = &subscibe
83
-
84
-		var template models.GobalTemplate
85
-		template.TemplateId = 2
86
-
87
-		var adminUserInfo service.AdminUserInfo
88
-		adminUserInfo.CurrentOrgId = 4
89
-		adminUserInfo.CurrentAppId = 5
90
-		adminUserInfo.AdminUser = &userAdmin
91
-		adminUserInfo.Subscibes = subscibes
92
-		this.SetSession("admin_user_info", &adminUserInfo)
93
-
94
-		//this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
95
-		//this.StopRun()
65
+		//var userAdmin models.AdminUser
66
+		//userAdmin.Id = 380
67
+		//userAdmin.Mobile = "13532250447"
68
+		//userAdmin.IsSuperAdmin = true
69
+		//userAdmin.Status = 1
70
+		//userAdmin.CreateTime = 1530786071
71
+		//userAdmin.ModifyTime = 1530786071
72
+		//var subscibe models.ServeSubscibe
73
+		//subscibe.ID = 1
74
+		//subscibe.OrgId = 4
75
+		//subscibe.PeriodStart = 1538035409
76
+		//subscibe.PeriodEnd = 1569571409
77
+		//subscibe.State = 1
78
+		//subscibe.Status = 1
79
+		//subscibe.CreatedTime = 1538035409
80
+		//subscibe.UpdatedTime = 1538035409
81
+		//subscibes := make(map[int64]*models.ServeSubscibe, 0)
82
+		//subscibes[4] = &subscibe
83
+		//
84
+		//var template models.GobalTemplate
85
+		//template.TemplateId = 2
86
+		//
87
+		//var adminUserInfo service.AdminUserInfo
88
+		//adminUserInfo.CurrentOrgId = 4
89
+		//adminUserInfo.CurrentAppId = 5
90
+		//adminUserInfo.AdminUser = &userAdmin
91
+		//adminUserInfo.Subscibes = subscibes
92
+		//this.SetSession("admin_user_info", &adminUserInfo)
93
+
94
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNotLogin)
95
+		this.StopRun()
96 96
 	}
97 97
 
98 98
 	//if this.Ctx.Request.Method != "GET" {
@@ -106,8 +106,15 @@ func (this *BaseAuthAPIController) Prepare() {
106 106
 	//}
107 107
 
108 108
 	//if this.Ctx.Request.Header.Get("Permission") == "1" {
109
-	//
110 109
 	//	isPermission := false
110
+	//
111
+	//	//adminUserInfo := this.GetAdminUserInfo()
112
+	//
113
+	//	//service.GetUserAllRole(adminUserInfo.CurrentOrgId)
114
+	//
115
+	//
116
+	//
117
+	//
111 118
 	//	roles := []int64{1,2}		//模拟该用户有多少角色
112 119
 	//	var targetRole models.RolePurview
113 120
 	//	var userRolePurview []string

+ 72 - 0
controllers/mobile_api_controllers/mobile_api_base_controller.go Wyświetl plik

@@ -4,7 +4,10 @@ import (
4 4
 	"XT_New/controllers"
5 5
 	"XT_New/enums"
6 6
 	"XT_New/models"
7
+	"XT_New/service"
7 8
 	"fmt"
9
+	"strconv"
10
+	"strings"
8 11
 )
9 12
 
10 13
 type MobileBaseAPIController struct {
@@ -60,4 +63,73 @@ func (this *MobileBaseAPIAuthController) Prepare() {
60 63
 	//		this.StopRun()
61 64
 	//	}
62 65
 	//}
66
+
67
+	if this.Ctx.Request.Header.Get("Permission") == "1" {
68
+		isPermission := false
69
+		adminUserInfo := this.GetMobileAdminUserInfo()
70
+		//该机构下该用户有多少个
71
+		role, _ := service.GetUserAllRole(adminUserInfo.Org.Id, adminUserInfo.AdminUser.Id)
72
+		var roles []string
73
+		if len(role.RoleIds) <= 0 { //该用户没有设置角色
74
+
75
+		} else {
76
+			roles = strings.Split(role.RoleIds, ",")
77
+		}
78
+
79
+		//获取该用户下所有角色的权限总集
80
+		var userRolePurviews string
81
+		var userRolePurviewsArr []string
82
+		for _, item := range roles {
83
+			role_id, _ := strconv.ParseInt(item, 10, 64)
84
+			purviews, _ := service.GetRoleFuncPurviewIds(role_id)
85
+			userRolePurviews = userRolePurviews + purviews
86
+		}
87
+		//该用户所拥有角色的权限的总集
88
+		userRolePurviewsArr = RemoveRepeatedPurviewElement(strings.Split(userRolePurviews, ","))
89
+		//系统所记录的权限列表
90
+		allPermission, _ := service.GetAllFunctionPurview()
91
+
92
+		//fmt.Println(this.Ctx.Request.RequestURI[1])
93
+
94
+		for _, item := range allPermission {
95
+			//判断当前路由是否在权限路由列表里面
96
+			if strings.Split(item.Urlfor, ",")[0] == strings.Split(this.Ctx.Request.RequestURI, "?")[0]+"?"+"mode="+this.GetString("mode") {
97
+				//获取该角色的所有权限
98
+				for _, items := range userRolePurviewsArr {
99
+					id, _ := strconv.ParseInt(items, 10, 64)
100
+					if id == item.ID {
101
+						isPermission = true
102
+					}
103
+				}
104
+				if !isPermission {
105
+					msg, _ := service.FindErrorMsgByStr(strings.Split(this.Ctx.Request.RequestURI, "?")[0] + "?" + "mode=" + this.GetString("mode"))
106
+					json := make(map[string]interface{})
107
+					json["msg"] = msg
108
+					json["code"] = 0
109
+					json["state"] = 0
110
+					this.Data["json"] = json
111
+					this.ServeJSON()
112
+					this.StopRun()
113
+				}
114
+			}
115
+		}
116
+	}
117
+
118
+}
119
+
120
+func RemoveRepeatedPurviewElement(arr []string) (newArr []string) {
121
+	newArr = make([]string, 0)
122
+	for i := 0; i < len(arr); i++ {
123
+		repeat := false
124
+		for j := i + 1; j < len(arr); j++ {
125
+			if arr[i] == arr[j] {
126
+				repeat = true
127
+				break
128
+			}
129
+		}
130
+		if !repeat {
131
+			newArr = append(newArr, arr[i])
132
+		}
133
+	}
134
+	return
63 135
 }

+ 17 - 0
controllers/new_mobile_api_controllers/home_api_controller.go Wyświetl plik

@@ -158,6 +158,23 @@ func (this *HomeController) ChangeOrg() {
158 158
 			TemplateInfo: &templateInfo,
159 159
 		}
160 160
 
161
+		if org != nil && appRole != nil {
162
+			// 插入一条登录记录
163
+			ip := this.GetString("ip")
164
+			loginLog := &models.AdminUserLoginLog{
165
+				AdminUserId: adminUser.Id,
166
+				OrgId:       org.Id,
167
+				AppId:       appRole.AppId,
168
+				IP:          ip,
169
+				OperateType: 3,
170
+				AppType:     3,
171
+				CreateTime:  time.Now().Unix(),
172
+			}
173
+			if insertErr := service.InsertLoginLog(loginLog); insertErr != nil {
174
+				utils.ErrorLog("为手机号为%v的用户插入一条登录记录失败:%v", mobile, insertErr)
175
+			}
176
+		}
177
+
161 178
 		//删除session和cookie
162 179
 		this.DelSession("mobile_admin_user_info")
163 180
 		this.Ctx.SetCookie("token_cookie", "")

+ 4 - 0
controllers/new_mobile_api_controllers/new_mobile_api_router_register.go Wyświetl plik

@@ -50,10 +50,14 @@ func NewMobileAPIControllersRegisterRouters() {
50 50
 	beego.Router("/m/api/role/create", &NewRoleApiController{}, "post:CreateRole")
51 51
 
52 52
 	beego.Router("/m/api/permission/post", &NewRoleApiController{}, "post:EditRolePermission")
53
+	beego.Router("/m/api/functionpermission/post", &NewRoleApiController{}, "post:EditFunctionPermission")
54
+
53 55
 	beego.Router("/m/api/permission", &NewRoleApiController{}, "get:GetAllPermission")
54 56
 	beego.Router("/m/api/rolepurview", &NewRoleApiController{}, "get:GetRolePurviews")
55 57
 	beego.Router("/m/api/role/funtionpurview", &NewRoleApiController{}, "get:GetFuntionPurviews")
56 58
 
59
+	beego.Router("/m/api/func_role/get", &NewRoleApiController{}, "get:GetFuncRolePurviews")
60
+
57 61
 	beego.Router("/m/api/patient/getbloodpatientinfo", &NewDialysisApiController{}, "Get:GetBloodPatientInfo")
58 62
 	beego.Router("/m/api/patient/getslowpatientinfo", &NewDialysisApiController{}, "Get:GetSlowPatientInfo")
59 63
 	beego.Router("/m/api/patient/getmemberpatientinfo", &NewDialysisApiController{}, "Get:GetMemberpatientInfo")

+ 205 - 53
controllers/new_mobile_api_controllers/new_role_api_controller.go Wyświetl plik

@@ -4,6 +4,7 @@ import (
4 4
 	"XT_New/enums"
5 5
 	"XT_New/models"
6 6
 	"XT_New/service"
7
+	"fmt"
7 8
 	"strconv"
8 9
 	"strings"
9 10
 	"time"
@@ -257,59 +258,6 @@ func (this *NewRoleApiController) CreateRole() {
257 258
 
258 259
 }
259 260
 
260
-func (this *NewRoleApiController) EditRolePermission() {
261
-	role_id, _ := this.GetInt64("id", 0)
262
-	purview_id := this.GetString("purview_id")
263
-	is_open, _ := this.GetInt64("type", 0)
264
-
265
-	permissions, err := service.GetRolePurviewIds(role_id)
266
-	if err != nil {
267
-		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
268
-		return
269
-	} else {
270
-
271
-		if is_open == 1 { //打开
272
-			permission_arr := strings.Split(permissions, ",")
273
-			permission_arr = append(permission_arr, purview_id)
274
-			permissions = strings.Join(permission_arr, ",")
275
-			//插入数据库
276
-			purview, _ := service.GetRolePurview(role_id)
277
-			purview.PurviewIds = permissions
278
-			err := service.SaveRolePurview(purview)
279
-			if err != nil {
280
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
281
-				return
282
-			}
283
-
284
-			this.ServeSuccessJSON(map[string]interface{}{
285
-				"is_open": 1,
286
-			})
287
-
288
-		} else { //关闭
289
-
290
-			permission_arr := strings.Split(permissions, ",")
291
-			for index, id := range permission_arr {
292
-				if id == purview_id {
293
-					permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
294
-				}
295
-			}
296
-			purview, _ := service.GetRolePurview(role_id)
297
-			purview.PurviewIds = strings.Join(permission_arr, ",")
298
-
299
-			err := service.SaveRolePurview(purview)
300
-			if err != nil {
301
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
302
-				return
303
-			}
304
-
305
-			this.ServeSuccessJSON(map[string]interface{}{
306
-				"is_open": 0,
307
-			})
308
-
309
-		}
310
-	}
311
-}
312
-
313 261
 func (this *NewRoleApiController) GetAllPermission() {
314 262
 	module, _ := this.GetInt64("module")
315 263
 	parent_id, _ := this.GetInt64("id")
@@ -396,3 +344,207 @@ func (this *NewRoleApiController) GetFuntionPurviews() {
396 344
 		"funtion_purview": functionPurview,
397 345
 	})
398 346
 }
347
+
348
+func RemoveRepeatedIDSElement(arr []string) (newArr []string) {
349
+	newArr = make([]string, 0)
350
+	for i := 0; i < len(arr); i++ {
351
+		repeat := false
352
+		for j := i + 1; j < len(arr); j++ {
353
+			if arr[i] == arr[j] {
354
+				repeat = true
355
+				break
356
+			}
357
+		}
358
+		if !repeat {
359
+			newArr = append(newArr, arr[i])
360
+		}
361
+	}
362
+	return
363
+}
364
+
365
+func (this *NewRoleApiController) EditRolePermission() {
366
+	adminUser := this.GetMobileAdminUserInfo()
367
+	role_id, _ := this.GetInt64("id", 0)
368
+	purview_id := this.GetString("purview_id")
369
+	is_open, _ := this.GetInt64("type", 0)
370
+
371
+	permissions, err := service.GetRolePurviewIds(role_id)
372
+	if err != nil {
373
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
374
+		return
375
+	} else {
376
+
377
+		if is_open == 1 { //打开
378
+			purview, _ := service.GetRolePurview(role_id)
379
+			if purview.Id == 0 { // 新建
380
+
381
+				purview.PurviewIds = purview_id
382
+				purview.CreateTime = time.Now().Unix()
383
+				purview.ModifyTime = time.Now().Unix()
384
+				purview.Status = 1
385
+				purview.RoleId = role_id
386
+				purview.OrgId = adminUser.Org.Id
387
+				purview.AppId = adminUser.App.Id
388
+				err := service.CreateRolePurview(&purview)
389
+				if err != nil {
390
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
391
+					return
392
+				}
393
+
394
+				this.ServeSuccessJSON(map[string]interface{}{
395
+					"is_open": 1,
396
+				})
397
+
398
+			} else { //修改
399
+				var permission_arr []string
400
+				purview, _ := service.GetRolePurview(role_id)
401
+				if len(permissions) > 0 {
402
+					permission_arr = strings.Split(permissions, ",")
403
+					if len(purview_id) > 0 {
404
+						permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
405
+					}
406
+				} else {
407
+					if len(purview_id) > 0 {
408
+						permission_arr = strings.Split(purview_id, ",")
409
+					}
410
+				}
411
+
412
+				permission_arr = RemoveRepeatedIDSElement(permission_arr)
413
+				permissions = strings.Join(permission_arr, ",")
414
+				purview.PurviewIds = permissions
415
+				err := service.SaveRolePurview(&purview)
416
+				if err != nil {
417
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
418
+					return
419
+				}
420
+
421
+				this.ServeSuccessJSON(map[string]interface{}{
422
+					"is_open": 1,
423
+				})
424
+
425
+			}
426
+
427
+		} else { //关闭
428
+			permission_arr := strings.Split(permissions, ",")
429
+			purview_arr := strings.Split(purview_id, ",")
430
+
431
+			for _, pur_id := range purview_arr {
432
+				for index, id := range permission_arr {
433
+					if id == pur_id {
434
+						permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
435
+					}
436
+				}
437
+			}
438
+			purview, _ := service.GetRolePurview(role_id)
439
+			fmt.Println(purview.CreateTime)
440
+			purview.PurviewIds = strings.Join(permission_arr, ",")
441
+
442
+			err := service.SaveRolePurview(&purview)
443
+			if err != nil {
444
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
445
+				return
446
+			}
447
+			this.ServeSuccessJSON(map[string]interface{}{
448
+				"is_open": 0,
449
+			})
450
+
451
+		}
452
+	}
453
+
454
+}
455
+
456
+func (this *NewRoleApiController) EditFunctionPermission() {
457
+	adminUser := this.GetMobileAdminUserInfo()
458
+	role_id, _ := this.GetInt64("id", 0)
459
+	purview_id := this.GetString("purview_id")
460
+	is_open, _ := this.GetInt64("type", 0)
461
+
462
+	permissions, err := service.GetRoleFuncPurviewIds(role_id)
463
+
464
+	if err != nil {
465
+		this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
466
+		return
467
+	} else {
468
+
469
+		if is_open == 1 { //打开
470
+			purview, _ := service.GetFuncRolePurview(role_id)
471
+			if purview.ID == 0 { // 新建
472
+
473
+				purview.PurviewIds = purview_id
474
+				purview.Ctime = time.Now().Unix()
475
+				purview.Mtime = time.Now().Unix()
476
+				purview.Status = 1
477
+				purview.RoleId = role_id
478
+				purview.OrgId = adminUser.Org.Id
479
+				purview.AppId = adminUser.App.Id
480
+				err := service.CreateFuncRolePurview(&purview)
481
+				if err != nil {
482
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
483
+					return
484
+				}
485
+
486
+				this.ServeSuccessJSON(map[string]interface{}{
487
+					"is_open": 1,
488
+				})
489
+			} else { //修改
490
+				var permission_arr []string
491
+				purview, _ := service.GetRoleFuncPurview(role_id)
492
+				if len(permissions) > 0 {
493
+					permission_arr = strings.Split(permissions, ",")
494
+					if len(purview_id) > 0 {
495
+						permission_arr = append(permission_arr, strings.Split(purview_id, ",")...)
496
+					}
497
+				} else {
498
+					if len(purview_id) > 0 {
499
+						permission_arr = strings.Split(purview_id, ",")
500
+					}
501
+				}
502
+				permission_arr = RemoveRepeatedIDSElement(permission_arr)
503
+				permissions = strings.Join(permission_arr, ",")
504
+				purview.PurviewIds = permissions
505
+
506
+				err := service.SaveRoleFuncPurview(&purview)
507
+				if err != nil {
508
+					this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
509
+					return
510
+				}
511
+				this.ServeSuccessJSON(map[string]interface{}{
512
+					"is_open": 1,
513
+				})
514
+			}
515
+		} else { //关闭
516
+			permission_arr := strings.Split(permissions, ",")
517
+			purview_arr := strings.Split(purview_id, ",")
518
+
519
+			for index, id := range permission_arr {
520
+				for _, pur_id := range purview_arr {
521
+					if id == pur_id {
522
+						permission_arr = append(permission_arr[:index], permission_arr[index+1:]...)
523
+					}
524
+				}
525
+			}
526
+			purview, _ := service.GetRoleFuncPurview(role_id)
527
+			purview.PurviewIds = strings.Join(permission_arr, ",")
528
+
529
+			err := service.SaveRoleFuncPurview(&purview)
530
+			if err != nil {
531
+				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
532
+				return
533
+			}
534
+			this.ServeSuccessJSON(map[string]interface{}{
535
+				"is_open": 0,
536
+			})
537
+
538
+		}
539
+	}
540
+
541
+}
542
+
543
+func (this *NewRoleApiController) GetFuncRolePurviews() {
544
+	//adminUserInfo := this.GetMobileAdminUserInfo()
545
+	role_id, _ := this.GetInt64("id", 0)
546
+	purview, _ := service.GetRoleFuncPurview(role_id)
547
+	this.ServeSuccessJSON(map[string]interface{}{
548
+		"role_purview": purview,
549
+	})
550
+}

+ 40 - 40
controllers/verify_login_controller.go Wyświetl plik

@@ -118,7 +118,6 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
118 118
 
119 119
 		} else {
120 120
 			adminUser := adminUserInfo.AdminUser
121
-			fmt.Println("adminUser", adminUser)
122 121
 			appRole := adminUserInfo.AppRoles[adminUserInfo.CurrentAppId]
123 122
 			userInfo := map[string]interface{}{
124 123
 				"id":         adminUser.Id,
@@ -161,52 +160,53 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
161 160
 					utils.ErrorLog("字段批量插入失败:%v", err)
162 161
 				}
163 162
 			}
164
-			curApp := adminUserInfo.OrgApps[adminUserInfo.CurrentOrgId][adminUserInfo.CurrentAppId]
165
-			if curApp.OpenStatus != 1 {
166
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNeverCreateTypeApp)
167
-				return
168
-			}
163
+			//curApp := adminUserInfo.OrgApps[adminUserInfo.CurrentOrgId][adminUserInfo.CurrentAppId]
164
+			//if curApp.OpenStatus != 1 {
165
+			//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNeverCreateTypeApp)
166
+			//	return
167
+			//}
169 168
 
170 169
 			curAppUrlfors := adminUserInfo.AppUrlfors[adminUserInfo.CurrentAppId]
171 170
 
172
-			subscibe := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
173
-			fmt.Println("subscibe", subscibe)
174
-			if err := service.GetOrgSubscibeState(subscibe); err != nil {
175
-				this.ErrorLog("没有机构订阅信息,数据有误")
176
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
177
-				return
178
-			}
179
-
180
-			orgApps := adminUserInfo.OrgApps[curOrg.Id]
181
-			didRegistedForSCRM := false
182
-			didRegistedForMall := false
183
-			didRegistedForCDM := false
184
-			for _, app := range orgApps {
185
-				if app.AppType == 1 && app.OpenStatus == 1 {
186
-					didRegistedForSCRM = true
187
-				}
188
-				if app.AppType == 4 && app.OpenStatus == 1 {
189
-					didRegistedForCDM = true
190
-				}
191
-				if app.AppType == 5 && app.OpenStatus == 1 {
192
-					didRegistedForMall = true
193
-				}
194
-			}
171
+			//subscibe := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
172
+			//fmt.Println("subscibe", subscibe)
173
+			//if err := service.GetOrgSubscibeState(subscibe); err != nil {
174
+			//	this.ErrorLog("没有机构订阅信息,数据有误")
175
+			//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
176
+			//	return
177
+			//}
178
+
179
+			//orgApps := adminUserInfo.OrgApps[curOrg.Id]
180
+			//didRegistedForSCRM := false
181
+			//didRegistedForMall := false
182
+			//didRegistedForCDM := false
183
+			//for _, app := range orgApps {
184
+			//	if app.AppType == 1 && app.OpenStatus == 1 {
185
+			//		didRegistedForSCRM = true
186
+			//	}
187
+			//	if app.AppType == 4 && app.OpenStatus == 1 {
188
+			//		didRegistedForCDM = true
189
+			//	}
190
+			//	if app.AppType == 5 && app.OpenStatus == 1 {
191
+			//		didRegistedForMall = true
192
+			//	}
193
+			//}
194
+			//service.GetOrgSub
195 195
 
196 196
 			this.SetSession("admin_user_info", adminUserInfo)
197 197
 
198 198
 			this.ServeSuccessJSON(map[string]interface{}{
199
-				"user":            userInfo,
200
-				"org":             org,
201
-				"urlfors":         curAppUrlfors,
202
-				"current_org_id":  adminUserInfo.CurrentOrgId,
203
-				"current_app_id":  adminUserInfo.CurrentAppId,
204
-				"subscibe":        subscibe,
205
-				"scrm_role_exist": didRegistedForSCRM,
206
-				"cdm_role_exist":  didRegistedForCDM,
207
-				"mall_role_exist": didRegistedForMall,
208
-				"template_info":   template_info,
209
-				"fileds":          FiledList,
199
+				"user":           userInfo,
200
+				"org":            org,
201
+				"urlfors":        curAppUrlfors,
202
+				"current_org_id": adminUserInfo.CurrentOrgId,
203
+				"current_app_id": adminUserInfo.CurrentAppId,
204
+				//"subscibe":        subscibe,
205
+				//"scrm_role_exist": didRegistedForSCRM,
206
+				//"cdm_role_exist":  didRegistedForCDM,
207
+				//"mall_role_exist": didRegistedForMall,
208
+				"template_info": template_info,
209
+				"fileds":        FiledList,
210 210
 			})
211 211
 			return
212 212
 		}

+ 4 - 4
models/purview_models.go Wyświetl plik

@@ -28,10 +28,10 @@ type RolePurview struct {
28 28
 	RoleId     int64
29 29
 	OrgId      int64
30 30
 	AppId      int64
31
-	PurviewIds string
32
-	Status     int8  // 状态 0.无效 1.有效 2.禁用
33
-	CreateTime int64 `gorm:"column:ctime"` // 创建时间
34
-	ModifyTime int64 `gorm:"column:mtime"` // 修改时间
31
+	PurviewIds string `gorm:"column:purview_ids"`
32
+	Status     int8   // 状态 0.无效 1.有效 2.禁用
33
+	CreateTime int64  `gorm:"column:ctime"` // 创建时间
34
+	ModifyTime int64  `gorm:"column:mtime"` // 修改时间
35 35
 
36 36
 	Role Role `gorm:"ForeignKey:RoleId;AssociationForeignKey:ID" json:"role_info"`
37 37
 }

+ 15 - 0
models/role_models.go Wyświetl plik

@@ -80,3 +80,18 @@ var UserTitle = map[int]string{
80 80
 	12: "运营专员",
81 81
 	13: "运营主管",
82 82
 }
83
+
84
+type SgjUserRoleFuncPurview struct {
85
+	ID         int64  `gorm:"column:id" json:"id" form:"id"`
86
+	OrgId      int64  `gorm:"column:org_id" json:"org_id" form:"org_id"`
87
+	AppId      int64  `gorm:"column:app_id" json:"app_id" form:"app_id"`
88
+	RoleId     int64  `gorm:"column:role_id" json:"role_id" form:"role_id"`
89
+	PurviewIds string `gorm:"column:purview_ids" json:"purview_ids" form:"purview_ids"`
90
+	Status     int64  `gorm:"column:status" json:"status" form:"status"`
91
+	Ctime      int64  `gorm:"column:ctime" json:"ctime" form:"ctime"`
92
+	Mtime      int64  `gorm:"column:mtime" json:"mtime" form:"mtime"`
93
+}
94
+
95
+func (SgjUserRoleFuncPurview) TableName() string {
96
+	return "sgj_user_role_func_purview"
97
+}

+ 64 - 10
service/role_service.go Wyświetl plik

@@ -445,19 +445,32 @@ func CreateOrgRole(role *models.Role) (err error) {
445 445
 	return
446 446
 }
447 447
 
448
-func GetRolePurview(roleID int64) (*models.RolePurview, error) {
449
-	var rolePurviews *models.RolePurview
450
-	err := readUserDb.Where("role_id = ?", roleID).First(&rolePurviews).Error
451
-	if err != nil {
452
-		if err == gorm.ErrRecordNotFound {
453
-			return nil, nil
454
-		}
455
-	}
456
-	return rolePurviews, nil
448
+func GetRolePurview(roleID int64) (models.RolePurview, error) {
449
+	var rolePurviews models.RolePurview
450
+	var err error
451
+	err = readUserDb.Where("role_id = ?", roleID).First(&rolePurviews).Error
452
+	return rolePurviews, err
453
+}
454
+
455
+func GetFuncRolePurview(roleID int64) (models.SgjUserRoleFuncPurview, error) {
456
+	var rolePurviews models.SgjUserRoleFuncPurview
457
+	var err error
458
+	err = readUserDb.Where("role_id = ?", roleID).First(&rolePurviews).Error
459
+	return rolePurviews, err
457 460
 }
458 461
 
459 462
 func SaveRolePurview(purview *models.RolePurview) (err error) {
460
-	err = writeUserDb.Save(purview).Error
463
+	err = writeUserDb.Save(&purview).Error
464
+	return
465
+}
466
+
467
+func CreateRolePurview(purview *models.RolePurview) (err error) {
468
+	err = writeUserDb.Create(&purview).Error
469
+	return
470
+}
471
+
472
+func CreateFuncRolePurview(purview *models.SgjUserRoleFuncPurview) (err error) {
473
+	err = writeUserDb.Create(&purview).Error
461 474
 	return
462 475
 }
463 476
 
@@ -544,3 +557,44 @@ func GetFunctionPurview() (purview []*models.SgjUserOperatePurview, err error) {
544 557
 	err = readUserDb.Model(&models.SgjUserOperatePurview{}).Where("status = 1 ").Find(&purview).Error
545 558
 	return
546 559
 }
560
+
561
+func GetRoleFuncPurviewIds(roleID int64) (string, error) {
562
+	var rolePurview models.SgjUserRoleFuncPurview
563
+	err := readUserDb.Where("role_id = ?", roleID).First(&rolePurview).Error
564
+	if err != nil {
565
+		if err == gorm.ErrRecordNotFound {
566
+			return "", nil
567
+		} else {
568
+			return "", err
569
+		}
570
+	}
571
+	return rolePurview.PurviewIds, nil
572
+}
573
+
574
+func GetRoleFuncPurview(roleID int64) (rolePurviews models.SgjUserRoleFuncPurview, err error) {
575
+	err = readUserDb.Where("role_id = ?", roleID).First(&rolePurviews).Error
576
+	return
577
+}
578
+
579
+func SaveRoleFuncPurview(purview *models.SgjUserRoleFuncPurview) (err error) {
580
+	err = writeUserDb.Save(purview).Error
581
+	return
582
+}
583
+
584
+func GetUserAllRole(org_id int64, admin_user_id int64) (role models.App_Role, err error) {
585
+	err = readUserDb.Model(&models.App_Role{}).Where("status = 1 AND org_id = ? AND admin_user_id = ?", org_id, admin_user_id).First(&role).Error
586
+	return
587
+}
588
+
589
+func GetAllFunctionPurview() (purview []models.SgjUserOperatePurview, err error) {
590
+	err = readUserDb.Model(&models.SgjUserOperatePurview{}).Where("status = 1 ").Find(&purview).Error
591
+	return
592
+}
593
+
594
+func FindErrorMsgByStr(str string) (string, error) {
595
+	var purview models.SgjUserOperatePurview
596
+	var err error
597
+	err = readUserDb.Model(&models.SgjUserOperatePurview{}).Where("find_in_set(?, urlfor)", str).First(&purview).Error
598
+	return purview.ErrorMsg, err
599
+
600
+}

+ 7 - 7
service/verify_login_token_service.go Wyświetl plik

@@ -148,11 +148,11 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
148 148
 	orgs := processOrgs(data)
149 149
 	orgAppIds := processOrgAppIds(data)
150 150
 	orgApps := processOrgApps(data)
151
-	app2OrgIds := processApp2OrgIds(data)
151
+	//app2OrgIds := processApp2OrgIds(data)
152 152
 	appRoles := processAppRoles(data)
153 153
 	appPurviews := processPurviews(data)
154 154
 	appUrlfors := processPurviewUrlfors(data)
155
-	orgSubscibes := processOrgSubscibes(data)
155
+	//orgSubscibes := processOrgSubscibes(data)
156 156
 	sessionAdminUserInfo := &AdminUserInfo{
157 157
 		AdminUser:    adminUser,
158 158
 		CurrentOrgId: currentOrgId,
@@ -161,11 +161,11 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
161 161
 		Orgs:         orgs,
162 162
 		OrgAppIds:    orgAppIds,
163 163
 		OrgApps:      orgApps,
164
-		App2OrgIds:   app2OrgIds,
165
-		AppRoles:     appRoles,
166
-		AppPurviews:  appPurviews,
167
-		AppUrlfors:   appUrlfors,
168
-		Subscibes:    orgSubscibes,
164
+		//App2OrgIds:   app2OrgIds,
165
+		AppRoles:    appRoles,
166
+		AppPurviews: appPurviews,
167
+		AppUrlfors:  appUrlfors,
168
+		//Subscibes:    orgSubscibes,
169 169
 	}
170 170
 	return sessionAdminUserInfo
171 171
 }