Selaa lähdekoodia

feat:区域限制修改

duxin 2 vuotta sitten
vanhempi
commit
c241fc19ad
1 muutettua tiedostoa jossa 39 lisäystä ja 43 poistoa
  1. 39 43
      jyBXSubscribe/rpc/model/distributor.go

+ 39 - 43
jyBXSubscribe/rpc/model/distributor.go

@@ -40,42 +40,48 @@ func Distributor(region []string, entId, entUserId int) []*User {
 		}
 		regions = append(regions, v)
 	}
-	if len(regions) > 0 { //判断区域
-		for _, v := range users {
-			if isEnt && v.Power == 1 { //商机管理用户 同时有商机管理权益
-				rules := IC.MainMysql.FindOne("entniche_user_rule", map[string]interface{}{"user_id": v.Id, "dept_id": v.Dept_id}, "rule_id", "")
-				if rules != nil && len(*rules) > 0 {
-					data, ok := IC.Mgo.FindById("entniche_distribute", common.InterfaceToStr((*rules)["rule_id"]), "")
-					if ok && data != nil && len(*data) > 0 {
-						o_area, _ := (*data)["o_area"].(map[string]interface{})
-						if regionCheck(o_area, regions) {
-							ss = append(ss, v)
-							continue
-						}
+
+	for _, v := range users {
+		var _n namePower
+		_n.entUserId = common.InterfaceToStr(v.Id)
+		_n.power = 1
+		n1 := powerUser[_n]
+		_n.power = 2
+		n2 := powerUser[_n]
+		if (isEnt && v.Power == 1) || n1 != 0 || n2 != 0 { //有权益用户 判断是否被设置分配区域
+			if len(regions) == 0 { //判断区域
+				ss = append(ss, v)
+				continue
+			}
+			//有区域限制 过滤筛选
+			rules := IC.MainMysql.FindOne("entniche_user_rule", map[string]interface{}{"user_id": v.Id, "dept_id": v.Dept_id}, "rule_id", "")
+			if rules != nil && len(*rules) > 0 {
+				data, ok := IC.Mgo.FindById("entniche_distribute", common.InterfaceToStr((*rules)["rule_id"]), "")
+				if ok && data != nil && len(*data) > 0 {
+					o_area, _ := (*data)["o_area"].(map[string]interface{})
+					if regionCheck(o_area, regions) {
+						ss = append(ss, v)
 					}
-				} else { // 企业未分配规则 查询个人
-					data, ok := IC.Mgo.FindOne("entniche_rule", map[string]interface{}{
-						"i_userid": v.Id,
-						"i_entid":  entId,
-					})
-					if ok && data != nil && len(*data) > 0 {
-						o_entniche, _ := (*data)["o_entniche"].(map[string]interface{})
-						o_area, _ := o_entniche["o_area"].(map[string]interface{})
-						if regionCheck(o_area, regions) {
-							ss = append(ss, v)
-							continue
-						}
+					continue //企业设置分发区域
+				}
+			}
+			if isEnt && v.Power == 1 { // 企业未分配规则 商机管理用户查询个人
+				data, ok := IC.Mgo.FindOne("entniche_rule", map[string]interface{}{
+					"i_userid": v.Id,
+					"i_entid":  entId,
+				})
+				if ok && data != nil && len(*data) > 0 {
+					o_entniche, _ := (*data)["o_entniche"].(map[string]interface{})
+					o_area, _ := o_entniche["o_area"].(map[string]interface{})
+					if regionCheck(o_area, regions) {
+						ss = append(ss, v)
+						continue //商机管理
 					}
 				}
 			}
-			//非商机管理企业或商机管理区域不满足 判断是否分配大会员或超级订阅
+
+			// 企业未分配规则 非商机管理用户  判断是否分配大会员或超级订阅
 			//user表 判断区域是否符合
-			var _n namePower
-			_n.entUserId = common.InterfaceToStr(v.Id)
-			_n.power = 1
-			n1 := powerUser[_n]
-			_n.power = 2
-			n2 := powerUser[_n]
 			if (n1 != 0 || n2 != 0) && v.Phone != "" {
 				//查询user表订阅区域
 				data, ok := IC.Mgo.FindOne("user", map[string]interface{}{
@@ -104,19 +110,9 @@ func Distributor(region []string, entId, entUserId int) []*User {
 				}
 			}
 		}
-	} else {
-		for _, v := range users {
-			var _n namePower
-			_n.entUserId = common.InterfaceToStr(v.Id)
-			_n.power = 1
-			n1 := powerUser[_n]
-			_n.power = 2
-			n2 := powerUser[_n]
-			if (isEnt && v.Power == 1) || n1 != 0 || n2 != 0 {
-				ss = append(ss, v)
-			}
-		}
+
 	}
+
 	return ss
 }