Commit bd9ba22a by mushishixian

部门共用申请限制

parent 1f3b8caf
......@@ -51,7 +51,7 @@ class SupplierShareApplyApiController extends Controller
$this->response(-1, '该供应商没有相关的所属人信息,请联系管理员');
}
$departmentService = new DepartmentService();
$department = $departmentService->getTopDepartmentByUserId($request->user->userId);
$department = $departmentService->getUpperDepartmentByUserIdForShareApply($request->user->userId);
$applyService = new SupplierShareApplyService();
$departments = $applyService->getApplyCanUseDepartments($supplier);
//获取当前人的部门id,如果部门列表里面包含自己的部门,则提示该供应商属于自己部门,请找主管分配
......
......@@ -57,43 +57,49 @@ class DepartmentService
return $departmentIds;
}
//根据用户ip获取顶级部门id
public function getTopDepartmentByUserId($userId)
//根据用户id获取上一层部门信息(专门为共用申请设置的方法)
/*
针对共用申请:
不同部门的情况还不同,因为线上的数据错乱了,不同部门的分级有问题
比如运营老大被分在了顶级部门(运营部),联营采购老大和自营采购老大被分在了二级部门
但是联营采购老大的部下,在三级部门,而且自营采购老大的部下,在二级部门,和自己同一个部门
但是目前用这个供应商系统的,只会有这三个部门,所以要找出一个合理的处理方法
所以这边的方法如下 :
运营和联营采购无脑找上一级.
因为运营老大在顶级,找不到上一级,那就取顶级即可
联营采购本来向上找一级就是对的(除了被查找的人是联营采购的老大....那就不要往上找了)
自营采购比较特殊,因为领导和部下都在这一个层级,所以不能往上找,往上找就是顶级的采购部了,顶级采购部是找不到人的(没有用户的部门id是顶级采购部id)
以上所说的情况,都是建立在部门架构不变以及部门老大维持层级不变的前提下进行的
*/
public function getUpperDepartmentByUserIdForShareApply($userId)
{
$userModel = new UserInfoModel();
$departmentId = $userModel->where('userId', $userId)->value('department_id');
if (empty($departmentId)) {
return [];
}
//去department表找到顶级id,也可能本身就是顶级id
$departmentModel = new DepartmentModel();
//先判断是不是自营采购部门id
if ($departmentId == config('field.ZiYingDepartmentId')) {
return $departmentModel->where('department_id', $departmentId)->first()->toArray();
} else {
$department = $departmentModel->where('department_id', $departmentId)->first();
//如果当前的部门id已经是联营采购部门Id
if ($departmentId == config('field.LiangYingDepartmentId')) {
return $department->toArray();
} else {
if (!empty($department)) {
$department = $department->toArray();
//找出自己的parent_id,如果是0代表自己就是顶级部门信息了
if ($department['parent_id'] == 0) {
return $department;
}
$department = $departmentModel->where('department_id', $department['parent_id'])->first()->toArray();
// //还不是顶级的话,继续找
// if ($department['parent_id'] != 0) {
// $department = $departmentModel->where('department_id', $department['parent_id'])->first()->toArray();
// }
$department = $departmentModel->where('department_id',
$department['parent_id'])->first()->toArray();
return $department;
}
return [];
}
public function getDepartmentByUserId($userId)
{
$userModel = new UserInfoModel();
$departmentId = $userModel->where('userId', $userId)->value('department_id');
if (empty($departmentId)) {
return [];
}
//去department表找到顶级id,也可能本身就是顶级id
$departmentModel = new DepartmentModel();
$department = $departmentModel->where('department_id', $departmentId)->first();
return !empty($department) ? $department->toArray() : [];
return [];
}
}
\ No newline at end of file
......@@ -30,6 +30,18 @@ class SupplierShareApplyService
}
//获取申请可以选择的部门
/*
不同部门的情况还不同,因为线上的数据错乱了,不同部门的分级有问题
比如运营老大被分在了顶级部门(运营部),联营采购老大和自营采购老大被分在了二级部门
但是联营采购老大的部下,在三级部门,而且自营采购老大的部下,在二级部门,和自己同一个部门
但是目前用这个供应商系统的,只会有这三个部门,所以要找出一个合理的处理方法
所以这边的方法如下 :
运营和联营采购无脑找上一级.
因为运营老大在顶级,找不到上一级,那就取顶级即可
联营采购本来向上找一级就是对的(除了被查找的人是联营采购的老大....那就不要往上找了)
自营采购比较特殊,因为领导和部下都在这一个层级,所以不能往上找,往上找就是顶级的采购部了,顶级采购部是找不到人的(没有用户的部门id是顶级采购部id)
以上所说的情况,都是建立在部门架构不变以及部门老大维持层级不变的前提下进行的
*/
public function getApplyCanUseDepartments($supplier)
{
$supplier = $supplier->toArray();
......@@ -41,8 +53,8 @@ class SupplierShareApplyService
$adminService = new AdminUserService();
$purchaseUser = $adminService->getAdminUserInfoByCodeId($purchaseUid);
$purchaseDepartment = $departmentService->getTopDepartmentByUserId($purchaseUser['userId']);
$createDepartment = $departmentService->getTopDepartmentByUserId($createUid);
$purchaseDepartment = $departmentService->getUpperDepartmentByUserIdForShareApply($purchaseUser['userId']);
$createDepartment = $departmentService->getUpperDepartmentByUserIdForShareApply($createUid);
$allDepartments = [];
if (!empty($purchaseDepartment)) {
$allDepartments[] = $purchaseDepartment;
......@@ -53,7 +65,7 @@ class SupplierShareApplyService
if (!empty($channelUids)) {
foreach ($channelUids as $channelUid) {
$channelUser = $adminService->getAdminUserInfoByCodeId($channelUid);
$channelDepartment = $departmentService->getTopDepartmentByUserId($channelUser['userId']);
$channelDepartment = $departmentService->getUpperDepartmentByUserIdForShareApply($channelUser['userId']);
//为什么不判断只要有三个部门就跳出,因为以后可能会有其它部门的人当采购
if (!in_array($channelDepartment, $allDepartments) && !empty($channelDepartment)) {
$allDepartments[] = $channelDepartment;
......@@ -74,7 +86,7 @@ class SupplierShareApplyService
$data['create_time'] = time();
$data['create_uid'] = request()->user->userId;
$departmentService = new DepartmentService();
$department = $departmentService->getTopDepartmentByUserId($data['create_uid']);
$department = $departmentService->getUpperDepartmentByUserIdForShareApply($data['create_uid']);
$data['department_id'] = $department['department_id'];
$applyModel = new SupplierShareApplyModel();
return $applyModel->insert($data);
......@@ -94,7 +106,7 @@ class SupplierShareApplyService
{
//1.先获取自己的部门ID
$departmentService = new DepartmentService();
$topDepartment = $departmentService->getTopDepartmentByUserId($userId);
$topDepartment = $departmentService->getUpperDepartmentByUserIdForShareApply($userId);
$departmentId = $topDepartment['department_id'];
$applyModel = new SupplierShareApplyModel();
......
......@@ -85,5 +85,8 @@ return [
0 => '审核中',
1 => '待复审',
2 => '复审通过'
]
],
'ZiYingDepartmentId' => 51,
'LiangYingDepartmentId' => 47,
];
\ No newline at end of file
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