فهرست منبع

数据结构修改

wangkaiyue 3 سال پیش
والد
کامیت
fffb0ea227
4فایلهای تغییر یافته به همراه34 افزوده شده و 22 حذف شده
  1. 8 9
      core/proxy/middleware/filterFuncs.go
  2. 14 4
      core/proxy/rpc/userCenter.go
  3. 7 5
      core/router/manager.go
  4. 5 4
      core/router/router.go

+ 8 - 9
core/proxy/middleware/filterFuncs.go

@@ -18,8 +18,8 @@ import (
 func filterBefore(r *ghttp.Request) error {
 	ctx := router.GetGContext(r.GetCtx())
 	rule := ctx.RouterRule
-	uCheck, eCheck, pCheck := getPowerCheck(rule.PowerCheck)
-	//校验身份
+	uCheck, eCheck := getPowerCheck(rule.SessCheck)
+	// 校验身份
 	if uCheck && ctx.Sess.UserId == "" {
 		return NewErrorWithCode(GLOBAL_ERR_NOTLOGIN)
 	}
@@ -40,7 +40,7 @@ func filterBefore(r *ghttp.Request) error {
 	}
 
 	//校验权益
-	if pCheck {
+	if rule.PowerCheck == 1 {
 		if err := rpc.CheekResourcePower(ctx.Sess.EntId, -1, rule.FuncCode); err != nil {
 			return err
 		}
@@ -76,12 +76,11 @@ func filterAfter(r *ghttp.Request) error {
 
 // getPowerCheck 是否需要校验
 // 0:否;
-// 其他 xyz: x userId 校验 y entId校验 z权益校验,【1需要 0 不需要】
-// 例如 101 校验用户id 不校验entId 校验是否购买
-func getPowerCheck(c int) (userIdCheck bool, entIdCheck bool, funcCodeCheck bool) {
-	userIdCheck = c/100%10 == 1
-	entIdCheck = c/10%10 == 1
-	funcCodeCheck = c/1%10 == 1
+// 其他 xy: x userId 校验 y entId校验 z权益校验,【1需要 0 不需要】
+// 例如 10 校验用户id 不校验entId
+func getPowerCheck(c int) (userIdCheck bool, entIdCheck bool) {
+	userIdCheck = c/10%10 == 1
+	entIdCheck = c/1%10 == 1
 	return
 }
 

+ 14 - 4
core/proxy/rpc/userCenter.go

@@ -23,21 +23,25 @@ func initUserCenterRpc() {
 }
 
 // CheckAccountStatus 校验企业认证状态及账户状态
-//  authCheck 是否需要认证;0:否 1:需要企业认证 2:需要个人认证',
-//  statusCheck是否需要检查状态(冻结);0:否 1:检查企业 2:检查个人,
+//  authCheck 是否需要认证;xy  x个人 y企业 0:否 1是,
+//  statusCheck是否需要检查状态(冻结);xy  x个人 y企业 0:否 1是,
 func CheckAccountStatus(entId int64, userId string, authCheck, statusCheck int) error {
 	if authCheck == 0 && statusCheck == 0 {
 		return nil
 	}
+
+	authUser, authEnt := getPCheck(authCheck)
+	statusUser, statusEnt := getPCheck(statusCheck)
+
 	//查询个人状态
-	if authCheck == 2 || statusCheck == 2 {
+	if authUser || statusUser {
 		if userErr := checkPersonalStatus(userId, authCheck == 2, statusCheck == 2); userErr != nil {
 			return userErr
 		}
 	}
 
 	//查询企业状态
-	if authCheck == 1 || statusCheck == 1 {
+	if authEnt || statusEnt {
 		if entErr := checkEntStatus(entId, authCheck == 1, statusCheck == 1); entErr != nil {
 			return entErr
 		}
@@ -78,3 +82,9 @@ func checkEntStatus(entId int64, authCheck, statusCheck bool) error {
 func checkPersonalStatus(userId string, authCheck, statusCheck bool) error {
 	return NewErrorWithCode(GLOBAL_ERR_UNFINISH, "checkPersonalStatus")
 }
+
+func getPCheck(c int) (check1 bool, check2 bool) {
+	check1 = c/10%10 == 1
+	check2 = c/1%10 == 1
+	return
+}

+ 7 - 5
core/router/manager.go

@@ -17,7 +17,8 @@ type Manager struct {
 
 // InitRouterManager 初始化系统代理路由
 func InitRouterManager() (*Manager, error) {
-	res := db.GateWatMySql.Query("SELECT status,middleground_code,url,function_code,ischeck,ischeck_auth,ischeck_blacklist,timeout,remark,deduct_source,ischeck_status FROM front_proxy")
+
+	res := db.GateWatMySql.Query("SELECT status,middleground_code,url,function_code,check_sess,check_power,check_auth,check_status,check_blacklist,timeout,remark,deduct_source FROM front_proxy")
 	if res == nil || len(*res) == 0 {
 		return nil, fmt.Errorf("未发现可用路由")
 	}
@@ -30,10 +31,11 @@ func InitRouterManager() (*Manager, error) {
 
 		routerRule := &Router{
 			Status:       gconv.Int(row["status"]),
-			PowerCheck:   gconv.Int(row["ischeck"]),
-			AccountCheck: gconv.Int(row["ischeck_status"]),
-			AuthCheck:    gconv.Int(row["ischeck_auth"]),
-			BlackCheck:   gconv.Int(row["ischeck_blacklist"]) == 1,
+			SessCheck:    gconv.Int(row["check_sess"]),
+			PowerCheck:   gconv.Int(row["check_power"]),
+			AccountCheck: gconv.Int(row["check_status"]),
+			AuthCheck:    gconv.Int(row["check_auth"]),
+			BlackCheck:   gconv.Int(row["check_blacklist"]) == 1,
 			Deduct:       gconv.Int(row["deduct_source"]),
 			FuncCode:     gconv.String(row["function_code"]),
 			MiddleCode:   gconv.String(row["middleground_code"]),

+ 5 - 4
core/router/router.go

@@ -2,10 +2,11 @@ package router
 
 type Router struct {
 	Status       int    //0:冻结不可用 1:正常可用
-	PowerCheck   int    //是否权限校验 【0:否;其他 xyz: x userId 校验 y entId校验 z权益校验,1需要 0 不需要
-	AccountCheck int    //是否需要检查状态(冻结);0:否 1:检查企业 2:检查个人
-	AuthCheck    int    //身份校验 【是否需要认证;0:不需要 1:需要企业认证 2:需要个人认证】
-	Deduct       int    //扣减来源;0:不扣减 1:前置代理(默认:1) 2:后端应用(必须返回后端应用)
+	SessCheck    int    //session校验 xy x校验userId y校验endId 0不需要 1需要
+	PowerCheck   int    //是否权限校验,1需要 0 不需要
+	AccountCheck int    //是否需要检查状态(冻结);xy x校验用户 y校验企业 0不需要 1需要
+	AuthCheck    int    //身份校验;xy x校验用户 y校验企业 0不需要 1需要
+	Deduct       int    //扣减来源;0:不扣减 1:前置代理(默认:1) 2:后端应用(必须返回后端应用)3:后台应用自行扣减
 	TimeOut      int64  //接口超时提醒,单位毫秒;默认500毫秒
 	BlackCheck   bool   //是否校验黑名单 【是否校验黑名单; 0:不需要 1:需要】
 	FuncCode     string //功能代码