Commit ff14d728 by 朱继来

调整

parent e55d5ca5
Showing with 35 additions and 44 deletions
......@@ -397,42 +397,42 @@
// 获取部门人员
public function getUserByDepartmentId($department_id, $status='', $filter='')
{
$department_ids = [];
$department_ids = [];
$this->getSubDepartmentId($department_id, $department_ids);
$data = DB::table('user_info')->whereIn('department_id', $department_ids)
->where(function($query) use($status) {
if ($status !== '') {
$query->where('status', '=', $status);
}
})
->where(function($query) use($filter) {
if ($filter) {
$query->whereRaw($filter);
}
})
->select('userId', 'name', 'status')
->get();
$this->getSubDepartmentId($department_id, $department_ids);
return $data;
$data = DB::table('user_info')->whereIn('department_id', $department_ids)
->where(function($query) use($status, $filter) {
if ($status !== '') {
$query->where('status', '=', $status);
}
if ($filter) {
$query->whereRaw($filter);
}
})
->select('userId', 'name', 'status')
->get();
return $data;
}
// 获取下级部门ID
public function getSubDepartmentId($department_id, &$department_ids)
{
// 获取下级部门
$sub_department = DB::table('user_department')->where('parent_id', $department_id)->select('department_id', 'department_name')->get();
{
// 获取下级部门
$sub_department = DB::table('user_department')->where('parent_id', $department_id)->select('department_id', 'department_name')->get();
if ($sub_department) {
foreach ($sub_department as $v) {
$this->getSubDepartmentId($v->department_id, $department_ids);
}
}
if ($sub_department) {
foreach ($sub_department as $v) {
$this->getSubDepartmentId($v->department_id, $department_ids);
}
}
$department_ids[] = $department_id;
$department_ids[] = $department_id;
return $department_ids;
return $department_ids;
}
/**
......@@ -463,35 +463,26 @@
return DB::table('user_info')->where($map)->select('userId', 'name', 'position_id', 'position_name', 'department_id', 'department_name', 'status')->get();
}
// 获取指定用户下级所有人员
// 获取指定用户下级所有人员
public function getSubSaleId($userId)
{
$sale_ids = [];
array_unshift($sale_ids, $userId); // 将当前用户添加到数组
$department_id = DB::table('user_info')->where('userId', $userId)->value('department_id'); // 用户信息
$user_info = DB::table('user_info')->where('userId', $userId)->select('department_id')->first(); // 用户信息
if (!$department_id) return $sale_ids;
if (!$user_info->department_id) return $sale_ids;
$department_ids = [];
// 获取当前用户下级部门
$department = DB::table('user_department')
->where('parent_id', $user_info->department_id)
->select('department_id', 'department_name')
->get();
$this->getSubDepartmentId($department_id, $department_ids); // 获取下级部门ID
if (!$department) {
$tmp = DB::table('user_info')->where('department_id', $user_info->department_id)->lists('userId');
// 获取下级部门的人员
foreach ($department_ids as $v) {
$tmp = DB::table('user_info')->where('department_id', $v)->lists('userId');
$sale_ids = array_merge($sale_ids, $tmp);
} else {
// 获取下级部门的人员
foreach ($department as $v) {
$tmp = DB::table('user_info')->where('department_id', $v->department_id)->lists('userId');
$sale_ids = array_merge($sale_ids, $tmp);
}
}
return array_unique($sale_ids); // 去重返回
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment