Browse Source

Merge branch 'master' of http://git.shengws.com/xmg123/scrm

XMLWAN 4 years ago
parent
commit
083d5e6843

+ 1 - 1
conf/app.conf View File

@@ -82,7 +82,7 @@ redisdb = 0
82 82
 
83 83
 [dev]
84 84
 httpdomain = http://api.test1.sgjyun.com
85
-sso_domain = https://testsso.sgjyun.com
85
+sso_domain = http://testsso.sgjyun.com
86 86
 front_end_domain = "http://test1.sgjyun.com/#"
87 87
 
88 88
 openwechattoken = dwqofqon2e12en2o

+ 55 - 40
controllers/login/login_controller.go View File

@@ -3,11 +3,13 @@ package login
3 3
 import (
4 4
 	base_ctl "SCRM/controllers"
5 5
 	"SCRM/enums"
6
+	"SCRM/models"
6 7
 	"SCRM/service/admin_service"
7
-	"SCRM/service/org_service"
8 8
 	"SCRM/utils"
9 9
 	"fmt"
10 10
 	"net/url"
11
+	"strconv"
12
+	"strings"
11 13
 
12 14
 	"github.com/astaxie/beego"
13 15
 )
@@ -72,18 +74,18 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
72 74
 		ip := utils.GetIP(this.Ctx.Request)
73 75
 		sessionID := this.Ctx.GetCookie("s")
74 76
 		utils.TraceLog("cookie session id: %v %v", ip, sessionID)
75
-		adminUserInfo, err, errCode := admin_service.VerifyToken(token, ip, sessionID)
77
+		adminUserInfo, err, _ := admin_service.VerifyToken(token, ip, sessionID)
76 78
 		if err != nil {
77
-			if errCode == 903 { // 未创建应用
78
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNeverCreateTypeApp)
79
-
80
-			} else if errCode == 904 { // 联系超管来开通
81
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeContactSuperAdminCreateTypeApp)
82
-
83
-			} else {
84
-				utils.ErrorLog("令牌验证失败:%v", err)
85
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInvalidToken)
86
-			}
79
+			//if errCode == 903 { // 未创建应用
80
+			//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeNeverCreateTypeApp)
81
+			//
82
+			//} else if errCode == 904 { // 联系超管来开通
83
+			//	this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeContactSuperAdminCreateTypeApp)
84
+			//
85
+			//} else {
86
+			utils.ErrorLog("令牌验证失败:%v", err)
87
+			this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeInvalidToken)
88
+			//}
87 89
 			return
88 90
 
89 91
 		} else {
@@ -112,41 +114,54 @@ func (this *VerifyUserLoginAPIController) VerifyToken() {
112 114
 				"district":       curOrg.District,
113 115
 				"address":        curOrg.Address,
114 116
 			}
115
-			curAppUrlfors := adminUserInfo.AppUrlfors[adminUserInfo.CurrentAppId]
116 117
 
117
-			subscibe := adminUserInfo.Subscibes[adminUserInfo.CurrentOrgId]
118
-			if err := org_service.GetOrgSubscibeState(subscibe); err != nil {
119
-				this.ErrorLog("没有机构订阅信息,数据有误")
120
-				this.ServeFailJSONWithSGJErrorCode(enums.ErrorCodeDataException)
121
-				return
122
-			}
118
+			var pruviews []*models.Purview
119
+			var curAppUrlfors []string
123 120
 
124
-			orgApps := adminUserInfo.OrgApps[curOrg.Id]
125
-			didRegistedForXT := false
126
-			didRegistedForMall := false
127
-			didRegistedForCDM := false
128
-			for _, app := range orgApps {
129
-				if app.AppType == 3 && app.OpenStatus == 1 {
130
-					didRegistedForXT = true
131
-				}
132
-				if app.AppType == 4 && app.OpenStatus == 1 {
133
-					didRegistedForCDM = true
121
+			if len(curAppUrlfors) == 0 {
122
+				if adminUser.Id == curOrg.Creator { //超级管理员
123
+					urlfors, _, _ := admin_service.GetSuperAdminUsersPurviewTreeAndUrlfors(6)
124
+					curAppUrlfors = urlfors
134 125
 				}
135
-				if app.AppType == 5 && app.OpenStatus == 1 {
136
-					didRegistedForMall = true
126
+
127
+			} else {
128
+				appRole, _ := admin_service.FindAdminUserIDA(appRole.Id)
129
+				if appRole.Id > 0 && len(appRole.RoleIds) > 0 {
130
+					role_arr := strings.Split(appRole.RoleIds, ",")
131
+					var ids string
132
+					for _, role_id := range role_arr {
133
+						id, _ := strconv.ParseInt(role_id, 10, 64)
134
+						purview_ids, _ := admin_service.GetRolePurviewIds(id)
135
+						if len(ids) == 0 {
136
+							ids = purview_ids
137
+						} else {
138
+							ids = ids + "," + purview_ids
139
+						}
140
+					}
141
+					if len(ids) != 0 {
142
+						pruviews, _ = admin_service.GetPurviewById(ids)
143
+						for _, item := range pruviews {
144
+							if item.Module == 3 && item.Parentid > 0 {
145
+								fmt.Println(item.Urlfor)
146
+								curAppUrlfors = append(curAppUrlfors, item.Urlfor)
147
+							}
148
+						}
149
+					} else {
150
+						curAppUrlfors = append(curAppUrlfors, "")
151
+					}
152
+				} else {
153
+					curAppUrlfors = append(curAppUrlfors, "")
137 154
 				}
138 155
 			}
139 156
 
157
+			subscibe, _ := admin_service.GetOrgSubscibe(adminUserInfo.CurrentOrgId)
140 158
 			this.ServeSuccessJSON(map[string]interface{}{
141
-				"user":            userInfo,
142
-				"org":             org,
143
-				"urlfors":         curAppUrlfors,
144
-				"current_org_id":  adminUserInfo.CurrentOrgId,
145
-				"current_app_id":  adminUserInfo.CurrentAppId,
146
-				"subscibe":        subscibe,
147
-				"xt_role_exist":   didRegistedForXT,
148
-				"cdm_role_exist":  didRegistedForCDM,
149
-				"mall_role_exist": didRegistedForMall,
159
+				"user":           userInfo,
160
+				"org":            org,
161
+				"urlfors":        curAppUrlfors,
162
+				"current_org_id": adminUserInfo.CurrentOrgId,
163
+				"current_app_id": adminUserInfo.CurrentAppId,
164
+				"subscibe":       subscibe,
150 165
 			})
151 166
 			return
152 167
 		}

+ 4 - 0
models/role_models.go View File

@@ -31,6 +31,10 @@ type App_Role struct {
31 31
 	Status      int8   `json:"status"`                              // 状态 0.无效 1.有效
32 32
 	CreateTime  int64  `gorm:"column:ctime" json:"ctime"`           // 创建时间
33 33
 	ModifyTime  int64  `gorm:"column:mtime" json:"mtime"`           // 修改时间
34
+	RoleIds     string `gorm:"column:role_ids" json:"role_ids" form:"role_ids"`
35
+	Message     string `gorm:"column:message" json:"message" form:"message"`
36
+	Sex         int64  `gorm:"column:sex" json:"sex" form:"sex"`
37
+	Birthday    int64  `gorm:"column:birthday" json:"birthday" form:"birthday"`
34 38
 }
35 39
 
36 40
 func (App_Role) TableName() string {

+ 90 - 5
service/admin_service/verify_login_token_service.go View File

@@ -2,6 +2,8 @@ package admin_service
2 2
 
3 3
 import (
4 4
 	"encoding/json"
5
+	"fmt"
6
+	"github.com/jinzhu/gorm"
5 7
 	"io/ioutil"
6 8
 	"net/http"
7 9
 	"net/url"
@@ -144,9 +146,9 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
144 146
 	currentOrgId, currentAppId := processCurrentOrgIDAndAppID(data)
145 147
 	orgIds := processOrgIds(data)
146 148
 	orgs := processOrgs(data)
147
-	//orgAppIds := processOrgAppIds(data)
149
+	orgAppIds := processOrgAppIds(data)
148 150
 	orgApps := processOrgApps(data)
149
-	app2OrgIds := processApp2OrgIds(data)
151
+	//app2OrgIds := processApp2OrgIds(data)
150 152
 	appRoles := processAppRoles(data)
151 153
 	appPurviews := processPurviews(data)
152 154
 	appUrlfors := processPurviewUrlfors(data)
@@ -157,9 +159,9 @@ func processAdminUserInfo(data map[string]interface{}) *AdminUserInfo {
157 159
 		CurrentAppId: currentAppId,
158 160
 		OrgIds:       orgIds,
159 161
 		Orgs:         orgs,
160
-		//OrgAppIds:    orgAppIds,
161
-		OrgApps:     orgApps,
162
-		App2OrgIds:  app2OrgIds,
162
+		OrgAppIds:    orgAppIds,
163
+		OrgApps:      orgApps,
164
+		//App2OrgIds:   app2OrgIds,
163 165
 		AppRoles:    appRoles,
164 166
 		AppPurviews: appPurviews,
165 167
 		AppUrlfors:  appUrlfors,
@@ -381,3 +383,86 @@ func ModifyPassword(adminID int64, password string) error {
381 383
 	err := service.UserWriteDB().Model(&models.AdminUser{}).Where("id = ? AND status = 1", adminID).Updates(map[string]interface{}{"password": password, "mtime": time.Now().Unix()}).Error
382 384
 	return err
383 385
 }
386
+
387
+func GetPurviewById(ids string) ([]*models.Purview, error) {
388
+	var originPurviews []*models.Purview
389
+	getPurviewErr := service.UserReadDB().Model(&models.Purview{}).Where(fmt.Sprintf("id in (%v) and status = 1", ids)).Order("listorder asc").Order("id asc").Find(&originPurviews).Error
390
+	return originPurviews, getPurviewErr
391
+}
392
+
393
+func FindAdminUserIDA(id int64) (role models.App_Role, err error) {
394
+	err = service.UserReadDB().Model(&models.App_Role{}).Where("id = ?", id).First(&role).Error
395
+	return
396
+}
397
+
398
+func GetSuperAdminUsersPurviewTreeAndUrlfors(appType int) ([]string, []*models.Purview, error) {
399
+	originPurviews, getPurviewErr := getAllOriginPurviews(appType)
400
+	if getPurviewErr != nil {
401
+		return nil, nil, getPurviewErr
402
+	}
403
+	urlfors, processedPurviews := getUrlforsAndProcessPurviews2Tree(originPurviews)
404
+	return urlfors, processedPurviews, nil
405
+}
406
+
407
+// 加工这些规则:树形化;以及从中取出不为空的 urlfor
408
+// 正确结果的前提是 originPurviews 以 parentid asc 排好序了的
409
+func getUrlforsAndProcessPurviews2Tree(originPurviews []*models.Purview) ([]string, []*models.Purview) {
410
+	processedPurviews := make([]*models.Purview, 0)
411
+	pid_childs := make(map[int][]*models.Purview)
412
+	urlfors := make([]string, 0, len(originPurviews))
413
+	for _, purview := range originPurviews {
414
+		if len(purview.Urlfor) != 0 {
415
+			urlfors = append(urlfors, purview.Urlfor)
416
+		}
417
+
418
+		// warning:下面这个算法只适用最多两层树形结构的菜单,对于两层以上的会丢失掉第三层及其以下的节点
419
+		// 因为取出 originPurviews 的时候已经排过序了,所以顶级节点肯定最先处理,不需要担心子节点比父节点先处理
420
+		if purview.Parentid == 0 {
421
+			processedPurviews = append(processedPurviews, purview)
422
+		} else {
423
+			childs := pid_childs[int(purview.Parentid)]
424
+			if pid_childs[int(purview.Parentid)] == nil {
425
+				childs = make([]*models.Purview, 0)
426
+			}
427
+			childs = append(childs, purview)
428
+			pid_childs[int(purview.Parentid)] = childs
429
+		}
430
+	}
431
+
432
+	for _, proPurview := range processedPurviews {
433
+		proPurview.Childs = pid_childs[int(proPurview.Id)]
434
+	}
435
+
436
+	return urlfors, processedPurviews
437
+}
438
+
439
+func getAllOriginPurviews(appType int) ([]*models.Purview, error) {
440
+	var purviews []*models.Purview
441
+	getPurviewErr := service.UserReadDB().Model(models.Purview{}).Where("module = ? AND status = 1", appType).Order("listorder asc").Order("id asc").Find(&purviews).Error
442
+	if getPurviewErr != nil {
443
+		if getPurviewErr == gorm.ErrRecordNotFound {
444
+			return nil, nil
445
+		} else {
446
+			return nil, getPurviewErr
447
+		}
448
+	}
449
+	return purviews, nil
450
+}
451
+
452
+func GetRolePurviewIds(roleID int64) (string, error) {
453
+	var rolePurview models.RolePurview
454
+	err := service.UserReadDB().Where("role_id = ?", roleID).First(&rolePurview).Error
455
+	if err != nil {
456
+		if err == gorm.ErrRecordNotFound {
457
+			return "", nil
458
+		} else {
459
+			return "", err
460
+		}
461
+	}
462
+	return rolePurview.PurviewIds, nil
463
+}
464
+
465
+func GetOrgSubscibe(org_id int64) (subscibe models.ServeSubscibe, err error) {
466
+	err = service.UserReadDB().Model(&models.ServeSubscibe{}).Where("org_id = ? AND status = 1", org_id).First(&subscibe).Error
467
+	return
468
+}