From 1ba4668e1cf815045adfe8b48544867a100a2876 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Sun, 10 May 2020 08:13:20 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=97=E8=A1=A8=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= 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/Project.php | 7 ++- application/project/controller/Project.php | 53 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 4 deletions(-) diff --git a/application/common/Model/Project.php b/application/common/Model/Project.php index 6c30693..15ada1d 100644 --- a/application/common/Model/Project.php +++ b/application/common/Model/Project.php @@ -22,7 +22,7 @@ class Project extends CommonModel return self::where(['id' => $id, 'deleted' => 0, 'archive' => 0])->find(); } - public function getMemberProjects($memberCode = '',$organizationCode = '', $deleted = 0, $archive = 0, $page = 1, $pageSize = 10) + public function getMemberProjects($memberCode = '',$organizationCode = '', $deleted = 0, $archive = 0, $collection = -1, $page = 1, $pageSize = 10) { if (!$memberCode) { $memberCode = getCurrentMember()['code']; @@ -36,13 +36,16 @@ class Project extends CommonModel $offset = ($page - 1) * $pageSize; $limit = $pageSize; $prefix = config('database.prefix'); - $sql = "select *,p.id as id,p.name as name,p.code as code,p.create_time as create_time from {$prefix}project as p join {$prefix}project_member as pm on p.code = pm.project_code left join {$prefix}project_collection as pc on p.code = pc.project_code where pm.member_code = '{$memberCode}' and p.organization_code = '$organizationCode'"; + $sql = "select *,p.id as id,p.name as name,p.code as code,p.create_time as create_time from {$prefix}project as p join {$prefix}project_member as pm on p.code = pm.project_code left join {$prefix}project_collection as pc on p.code = pc.project_code where pm.member_code = '{$memberCode}' and p.organization_code = '$organizationCode'"; if ($deleted != -1) { $sql .= " and p.deleted = {$deleted} "; } if ($archive != -1) { $sql .= " and p.archive = {$archive} "; } + if ($collection == 1) { + $sql .= " and pc.project_code is not null and pc.member_code = '{$memberCode}'"; + } $sql .= " order by pc.id desc, p.id desc"; $total = Db::query($sql); $total = count($total); diff --git a/application/project/controller/Project.php b/application/project/controller/Project.php index 1d5115c..2833bda 100644 --- a/application/project/controller/Project.php +++ b/application/project/controller/Project.php @@ -44,7 +44,7 @@ class Project extends BasicApi * @return void * @throws DbException */ - public function index() + public function index11() { $prefix = config('database.prefix'); $type = Request::post('type'); @@ -96,6 +96,55 @@ class Project extends BasicApi $this->success('', ['list' => $newList, 'total' => $list['total']]); } + public function index() + { + $selectBy = Request::post('selectBy', 'all'); + switch ($selectBy) { + case 'my': + $deleted = 0; + $archive = -1; + $collection = -1; + break; + case 'collect': + $deleted = 0; + $archive = -1; + $collection = 1; + break; + case 'archive': + $deleted = 0; + $archive = 1; + $collection = -1; + break; + case 'deleted': + $deleted = 1; + $archive = -1; + $collection = -1; + break; + default: + $deleted = 0; + $archive = -1; + $collection = -1; + + + } + $list = $this->model->getMemberProjects(getCurrentMember()['code'], getCurrentOrganizationCode(), $deleted, $archive, $collection, Request::post('page'), Request::post('pageSize')); + if ($list['list']) { + foreach ($list['list'] as $key => &$item) { + $item['owner_name'] = '-'; + if (isset($item['project_code'])) { + $item['code'] = $item['project_code']; + $item = $this->model->where(['code' => $item['code']])->find(); + } + $collected = ProjectCollection::where(['project_code' => $item['code'], 'member_code' => getCurrentMember()['code']])->field('id')->find(); + $item['collected'] = $collected ? 1 : 0; + $owner = ProjectMember::alias('pm')->leftJoin('member m', 'pm.member_code = m.code')->where(['pm.project_code' => $item['code'], 'is_owner' => 1])->field('member_code,name')->find(); + $item['owner_name'] = $owner['name']; + } + unset($item); + } + $this->success('', $list); + } + public function analysis(Request $request) { $organizationCode = getCurrentOrganizationCode(); @@ -190,7 +239,7 @@ class Project extends BasicApi if (!$type) { $deleted = 0; } - $list = $this->model->getMemberProjects($member['code'], $organizationCode ?? getCurrentOrganizationCode(), $deleted, $archive, Request::post('page'), Request::post('pageSize')); + $list = $this->model->getMemberProjects($member['code'], $organizationCode ?? getCurrentOrganizationCode(), $deleted, $archive, -1, Request::post('page'), Request::post('pageSize')); if ($list['list']) { foreach ($list['list'] as $key => &$item) { $item['owner_name'] = '-';