From 582a0d858cf0e7ff9a6670e09ce5baae51876bb5 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Mon, 2 Mar 2020 08:58:49 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=80=E5=87=BA=E7=BB=84=E7=BB=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: vilson <545522390@qq.com> --- application/common/Model/Organization.php | 44 +++++++++++++++++++ .../project/controller/Organization.php | 10 +++++ application/project/middleware/Auth.php | 3 +- 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/application/common/Model/Organization.php b/application/common/Model/Organization.php index a8f054e..564b267 100644 --- a/application/common/Model/Organization.php +++ b/application/common/Model/Organization.php @@ -2,6 +2,8 @@ namespace app\common\Model; +use think\Db; + /** * 组织 * Class Organization @@ -84,4 +86,46 @@ class Organization extends CommonModel $result = self::update($data, ['code' => $code]); return $result; } + + public static function quitOrganization($memberCode, $orgCode) + { + if (!$orgCode) { + return error(201, '请选择组织'); + } + $org = self::where(['code' => $orgCode])->field('id', true)->find(); + if (!$org) { + return error(202, '该组织不存在'); + } + $hasJoined = MemberAccount::where(['member_code' => $memberCode, 'organization_code' => $orgCode])->find(); + if (!$hasJoined) { + return error(203, '尚未加入该组织'); + } + Db::startTrans(); + try { + $accountCode = $hasJoined['code']; + $hasJoined->delete(); + //退出部门 + $list = DepartmentMember::where(['account_code' => $accountCode])->select(); + if ($list) { + $departmentMemberModel = new DepartmentMember(); + foreach ($list as $item) { + $departmentMemberModel->removeMember($accountCode, $item['department_code']); + } + unset($item); + } + //退出项目 + $projectMemberList = ProjectMember::alias('pm')->leftJoin('project p', 'p.code = pm.project_code')->where(['pm.member_code' => $memberCode, 'p.organization_code' => $orgCode])->select(); + if ($projectMemberList) { + $projectMemberModel = new ProjectMember(); + foreach ($projectMemberList as $item) { + $projectMemberModel->removeMember($memberCode, $item['project_code']); + } + } + } catch (\Exception $exception) { + Db::rollback(); + return error($exception->getCode(), $exception->getMessage()); + } + Db::commit(); + return true; + } } diff --git a/application/project/controller/Organization.php b/application/project/controller/Organization.php index 7054f90..5030c36 100644 --- a/application/project/controller/Organization.php +++ b/application/project/controller/Organization.php @@ -118,4 +118,14 @@ class Organization extends BasicApi $this->model->destroy(Request::post('id')); $this->success(''); } + + public function _quitOrganization(Request $request) + { + $organizationCode = $request::param('organizationCode'); + $res = $this->model->quitOrganization(getCurrentMember()['code'], $organizationCode); + if (isError($res)) { + $this->error($res['msg']); + } + $this->success(''); + } } diff --git a/application/project/middleware/Auth.php b/application/project/middleware/Auth.php index 06b1717..2abf939 100644 --- a/application/project/middleware/Auth.php +++ b/application/project/middleware/Auth.php @@ -69,7 +69,8 @@ class Auth } // 访问权限检查 if (!empty($access['is_auth']) && !auth($node, 'project')) { - return json(['code' => 403, 'msg' => '无权限操作资源,访问被拒绝']); + $nodeInfo = ProjectNode::where('node', $node)->find(); + return json(['code' => 403, 'msg' => '无权限操作资源['. $nodeInfo['title'] . '],访问被拒绝']); } //第三资源初始化 $storageConfig = config('storage.');