|
@@ -24,25 +24,28 @@ func (this *CustomerAction) DistributePersons() {
|
|
|
distributeUsers := VarCustomer.GetDistributeUser(ent_id, customer_id) //获取已分发人员id
|
|
|
//获取人员列表
|
|
|
var users []*User
|
|
|
- var dept_id int
|
|
|
curUser := VarCurrentUser.EntInfo(ent_id, entUserId)
|
|
|
if curUser.Role_admin_department { //获取当前部门id
|
|
|
- dept_id = curUser.Dept.Id
|
|
|
+ users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, curUser.Dept.Id)
|
|
|
} else if curUser.Role_admin_system { //查询客户所属的部门id
|
|
|
res := Mysql.FindOne(Entniche_customer, M{"id": customer_id, "ent_id": ent_id}, "dept_id", "")
|
|
|
- if len(*res) == 0 {
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
return "未找到客户", nil
|
|
|
}
|
|
|
- dept_id = qutil.IntAll((*res)["dept_id"])
|
|
|
+ dept_id := qutil.IntAll((*res)["dept_id"])
|
|
|
+ if dept_id == curUser.Dept.Id { //当前客户是否所属于最顶级部门
|
|
|
+ users = *VarEntInfo.GetDisUsersDeptDetail(ent_id)
|
|
|
+ } else {
|
|
|
+ users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, dept_id)
|
|
|
+ }
|
|
|
} else {
|
|
|
return "没有权限", nil
|
|
|
}
|
|
|
- users = *VarDepartment.GetDisUsersDeptDetail(curUser.Ent.Id, dept_id)
|
|
|
|
|
|
persons := map[string][]map[string]interface{}{}
|
|
|
if len(users) > 0 {
|
|
|
for _, v := range users {
|
|
|
- distribute := 0
|
|
|
+ distribute := 2
|
|
|
for _, uid := range distributeUsers {
|
|
|
if v.Id == uid {
|
|
|
distribute = 1
|
|
@@ -52,6 +55,7 @@ func (this *CustomerAction) DistributePersons() {
|
|
|
"id": qutil.SE.Encode2HexByCheck(fmt.Sprint(v.Id)),
|
|
|
"name": v.Name,
|
|
|
"phone": v.Phone,
|
|
|
+ "role": v.Role,
|
|
|
"distribute": distribute,
|
|
|
}
|
|
|
if persons[v.Dept_name] == nil {
|
|
@@ -88,19 +92,24 @@ func (this *CustomerAction) DistributeSubmit() {
|
|
|
curUser := VarCurrentUser.EntInfo(ent_id, entUserId)
|
|
|
//获取人员列表
|
|
|
var users []*User
|
|
|
- var dept_id int
|
|
|
if curUser.Role_admin_department { //获取当前部门id
|
|
|
- dept_id = curUser.Dept.Id
|
|
|
+ users = *VarDepartment.GetDisUsers(curUser.Ent.Id, curUser.Dept.Id)
|
|
|
} else if curUser.Role_admin_system { //查询客户所属的部门id
|
|
|
res := Mysql.FindOne(Entniche_customer, M{"id": customer_id, "ent_id": ent_id}, "dept_id", "")
|
|
|
- if len(*res) == 0 {
|
|
|
+ if res == nil || len(*res) == 0 {
|
|
|
return "未找到客户", nil
|
|
|
}
|
|
|
- dept_id = qutil.IntAll((*res)["dept_id"])
|
|
|
+ dept_id := qutil.IntAll((*res)["dept_id"])
|
|
|
+ if dept_id == curUser.Dept.Id { //当前客户是否所属于最顶级部门
|
|
|
+ users = *VarEntInfo.GetDisUsers(ent_id)
|
|
|
+ } else {
|
|
|
+ users = *VarDepartment.GetDisUsers(curUser.Ent.Id, dept_id)
|
|
|
+ }
|
|
|
} else {
|
|
|
return "没有权限", nil
|
|
|
}
|
|
|
- users = *VarDepartment.GetDisUsers(curUser.Ent.Id, dept_id)
|
|
|
+
|
|
|
+ log.Println("users", users)
|
|
|
ok := Mysql.ExecTx("客户分发", func(tx *sql.Tx) bool {
|
|
|
//清除之前选择
|
|
|
if !VarCustomer.ClearDistributeUser(tx, customer_id, users) {
|
|
@@ -116,7 +125,7 @@ func (this *CustomerAction) DistributeSubmit() {
|
|
|
}
|
|
|
for _, u := range users { //校验用户是否在管理范围内
|
|
|
if fmt.Sprint(u.Id) == qutil.SE.Decode4HexByCheck(id) {
|
|
|
- final_checked_userIds = append(final_checked_userIds, id)
|
|
|
+ final_checked_userIds = append(final_checked_userIds, fmt.Sprint(u.Id))
|
|
|
break
|
|
|
}
|
|
|
}
|