diff --git a/application/common/Model/MemberAccount.php b/application/common/Model/MemberAccount.php index dec5147..5fc93de 100644 --- a/application/common/Model/MemberAccount.php +++ b/application/common/Model/MemberAccount.php @@ -38,11 +38,11 @@ class MemberAccount extends CommonModel { $hasJoined = MemberAccount::where(['member_code' => $memberCode, 'organization_code' => $organizationCode])->find(); if ($hasJoined) { - throw new \Exception('已加入该组织', 3); + return error(3, '已加入该组织'); } $memberDate = Member::where(['code' => $memberCode])->find(); if (!$memberDate) { - throw new \Exception('该用户不存在', 4); + return error(4, '该用户不存在'); } $auth = ProjectAuth::where(['organization_code' => $organizationCode, 'is_default' => 1])->field('id')->find(); $authId = ''; diff --git a/application/common/Model/ProjectMember.php b/application/common/Model/ProjectMember.php index bfb1116..3af3995 100644 --- a/application/common/Model/ProjectMember.php +++ b/application/common/Model/ProjectMember.php @@ -39,6 +39,7 @@ class ProjectMember extends CommonModel 'join_time' => nowTime() ]; $result = self::create($data); + MemberAccount::inviteMember(getCurrentMember()['code'], $project['organization_code']); Project::projectHook(getCurrentMember()['code'], $projectCode, 'inviteMember', $memberCode); return $result; } diff --git a/application/project/controller/Account.php b/application/project/controller/Account.php index cafed23..c857a8b 100644 --- a/application/project/controller/Account.php +++ b/application/project/controller/Account.php @@ -4,6 +4,7 @@ namespace app\project\controller; use app\common\Model\Member; use app\common\Model\MemberAccount; +use app\common\Model\Organization; use app\common\Model\SystemConfig; use controller\BasicApi; use service\FileService; @@ -153,13 +154,23 @@ class Account extends BasicApi if (!$organization) { $this->error('该组织不存在'); } - try { - MemberAccount::inviteMember(getCurrentMember()['code'], $organization['code']); - } catch (\Exception $e) { - $this->error($e->getMessage()); + $result = MemberAccount::inviteMember(getCurrentMember()['code'], $organization['code']); + if (isError($result)) { + $this->error($result['msg'], $result['errno']); } } - $this->success(''); + $currentOrganization = null; + $list = MemberAccount::where(['member_code' => getCurrentMember()['code']])->order('id asc')->select()->toArray(); + $organizationList = []; + if ($list) { + foreach ($list as $item) { + $organizationInfo = Organization::where(['code' => $item['organization_code']])->find(); + if ($organizationInfo) { + $organizationList[] = $organizationInfo; + } + } + } + $this->success('', ['organizationList' => $organizationList, 'currentOrganization' => $organization]); } /** diff --git a/application/project/controller/ProjectMember.php b/application/project/controller/ProjectMember.php index 1c951db..c5d66ad 100644 --- a/application/project/controller/ProjectMember.php +++ b/application/project/controller/ProjectMember.php @@ -5,6 +5,7 @@ namespace app\project\controller; use app\common\Model\InviteLink; use app\common\Model\Member; use app\common\Model\MemberAccount; +use app\common\Model\Organization; use controller\BasicApi; use think\facade\Request; @@ -122,7 +123,19 @@ class ProjectMember extends BasicApi $this->error($e->getMessage(), $e->getCode()); } } - $this->success(''); + $currentOrganization = null; + $list = MemberAccount::where(['member_code' => getCurrentMember()['code']])->order('id asc')->select()->toArray(); + $organizationList = []; + if ($list) { + foreach ($list as $item) { + $organization = Organization::where(['code' => $item['organization_code']])->find(); + if ($organization) { + $organizationList[] = $organization; + } + $item['organization_code'] == $project['organization_code'] && $currentOrganization = $organization; + } + } + $this->success('', ['organizationList' => $organizationList, 'currentOrganization' => $currentOrganization]); } /**