Selaa lähdekoodia

feat:优化修改

duxin 2 vuotta sitten
vanhempi
commit
8e40ffe8b6
1 muutettua tiedostoa jossa 14 lisäystä ja 15 poistoa
  1. 14 15
      jyBXSubscribe/rpc/model/distributor.go

+ 14 - 15
jyBXSubscribe/rpc/model/distributor.go

@@ -54,38 +54,37 @@ func Distributor(region []string, entId, entUserId int) []*User {
 				continue
 			}
 			var rule_id string
-			var deptNo bool
 			//有区域限制 过滤筛选
 			rules := IC.MainMysql.Find("entniche_user_rule", map[string]interface{}{"user_id": v.Id}, "rule_id,dept_id", "", -1, -1)
 			if rules != nil && len(*rules) > 0 {
 				if len(*rules) > 1 { //多条规则 查询优先级最高的规则
+					ruleIds := make(map[int]string)
+					for _, v2 := range *rules {
+						ruleIds[common.IntAll(v2["dept_id"])] = common.InterfaceToStr(v2["rule_id"])
+					}
 					//获取部门优先级
 					var ids []int
 					departSort(&ids, v.Dept_id)
 					ids = append(ids, v.Dept_id)
 					//Reverse(&ids)
 					for _, v1 := range ids {
-						for _, v2 := range *rules {
-							if v1 == common.IntAll(v2["dept_id"]) {
-								deptNo = true
-								rule_id = common.InterfaceToStr(v2["rule_id"])
-								break
-							}
-						}
-						if deptNo {
+						if v2, ok := ruleIds[v1]; ok && v2 != "" {
+							rule_id = v2
 							break
 						}
 					}
 				} else {
 					rule_id = common.InterfaceToStr((*rules)[0]["rule_id"])
 				}
-				data, ok := IC.Mgo.FindById("entniche_distribute", 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)
+				if rule_id != "" {
+					data, ok := IC.Mgo.FindById("entniche_distribute", 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 //企业设置分发区域
 					}
-					continue //企业设置分发区域
 				}
 			}
 			if isEnt && v.Power == 1 { // 企业未分配规则 商机管理用户查询个人