csx 4 years ago
parent
commit
3e651b0c9e

+ 1 - 1
conf/app.conf View File

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

+ 44 - 29
controllers/login/login_controller.go View File

4
 	base_ctl "SCRM/controllers"
4
 	base_ctl "SCRM/controllers"
5
 	"SCRM/enums"
5
 	"SCRM/enums"
6
 	"SCRM/service/admin_service"
6
 	"SCRM/service/admin_service"
7
-	"SCRM/service/org_service"
8
 	"SCRM/utils"
7
 	"SCRM/utils"
9
 	"fmt"
8
 	"fmt"
10
 	"net/url"
9
 	"net/url"
10
+	"scrm/models"
11
+	"strconv"
12
+	"strings"
11
 
13
 
12
 	"github.com/astaxie/beego"
14
 	"github.com/astaxie/beego"
13
 )
15
 )
112
 				"district":       curOrg.District,
114
 				"district":       curOrg.District,
113
 				"address":        curOrg.Address,
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
 			this.ServeSuccessJSON(map[string]interface{}{
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
 			return
166
 			return
152
 		}
167
 		}

+ 4 - 0
models/role_models.go View File

31
 	Status      int8   `json:"status"`                              // 状态 0.无效 1.有效
31
 	Status      int8   `json:"status"`                              // 状态 0.无效 1.有效
32
 	CreateTime  int64  `gorm:"column:ctime" json:"ctime"`           // 创建时间
32
 	CreateTime  int64  `gorm:"column:ctime" json:"ctime"`           // 创建时间
33
 	ModifyTime  int64  `gorm:"column:mtime" json:"mtime"`           // 修改时间
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
 func (App_Role) TableName() string {
40
 func (App_Role) TableName() string {

+ 92 - 7
service/admin_service/verify_login_token_service.go View File

2
 
2
 
3
 import (
3
 import (
4
 	"encoding/json"
4
 	"encoding/json"
5
+	"fmt"
6
+	"github.com/jinzhu/gorm"
5
 	"io/ioutil"
7
 	"io/ioutil"
6
 	"net/http"
8
 	"net/http"
7
 	"net/url"
9
 	"net/url"
146
 	orgs := processOrgs(data)
148
 	orgs := processOrgs(data)
147
 	orgAppIds := processOrgAppIds(data)
149
 	orgAppIds := processOrgAppIds(data)
148
 	orgApps := processOrgApps(data)
150
 	orgApps := processOrgApps(data)
149
-	app2OrgIds := processApp2OrgIds(data)
151
+	//app2OrgIds := processApp2OrgIds(data)
150
 	appRoles := processAppRoles(data)
152
 	appRoles := processAppRoles(data)
151
 	appPurviews := processPurviews(data)
153
 	appPurviews := processPurviews(data)
152
 	appUrlfors := processPurviewUrlfors(data)
154
 	appUrlfors := processPurviewUrlfors(data)
153
-	orgSubscibes := processOrgSubscibes(data)
155
+	//orgSubscibes := processOrgSubscibes(data)
154
 	sessionAdminUserInfo := &AdminUserInfo{
156
 	sessionAdminUserInfo := &AdminUserInfo{
155
 		AdminUser:    adminUser,
157
 		AdminUser:    adminUser,
156
 		CurrentOrgId: currentOrgId,
158
 		CurrentOrgId: currentOrgId,
159
 		Orgs:         orgs,
161
 		Orgs:         orgs,
160
 		OrgAppIds:    orgAppIds,
162
 		OrgAppIds:    orgAppIds,
161
 		OrgApps:      orgApps,
163
 		OrgApps:      orgApps,
162
-		App2OrgIds:   app2OrgIds,
163
-		AppRoles:     appRoles,
164
-		AppPurviews:  appPurviews,
165
-		AppUrlfors:   appUrlfors,
166
-		Subscibes:    orgSubscibes,
164
+		//App2OrgIds:   app2OrgIds,
165
+		AppRoles:    appRoles,
166
+		AppPurviews: appPurviews,
167
+		AppUrlfors:  appUrlfors,
168
+		//Subscibes:    orgSubscibes,
167
 	}
169
 	}
168
 	return sessionAdminUserInfo
170
 	return sessionAdminUserInfo
169
 }
171
 }
381
 	err := service.UserWriteDB().Model(&models.AdminUser{}).Where("id = ? AND status = 1", adminID).Updates(map[string]interface{}{"password": password, "mtime": time.Now().Unix()}).Error
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
 	return err
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
+}