退出组织

Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
vilson 2020-03-02 08:58:49 +08:00
parent 5339f965c8
commit 582a0d858c
3 changed files with 56 additions and 1 deletions

View File

@ -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;
}
}

View File

@ -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('');
}
}

View File

@ -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.');