From e091fd72cc4b0d8761363e5e1cefa99a7051256e Mon Sep 17 00:00:00 2001
From: vilson <545522390@qq.com>
Date: Thu, 20 Jun 2019 21:21:52 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=80=9A=E8=BF=87=E9=82=80?=
 =?UTF-8?q?=E8=AF=B7=E9=93=BE=E6=8E=A5=E9=82=80=E8=AF=B7=E6=88=90=E5=91=98?=
 =?UTF-8?q?=E9=80=BB=E8=BE=91?=
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/MemberAccount.php    |  4 ++--
 application/common/Model/ProjectMember.php    |  1 +
 application/project/controller/Account.php    | 21 ++++++++++++++-----
 .../project/controller/ProjectMember.php      | 15 ++++++++++++-
 4 files changed, 33 insertions(+), 8 deletions(-)

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]);
     }
 
     /**