项目列表优化
Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
parent
5cf8c2f490
commit
1ba4668e1c
@ -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);
|
||||
|
@ -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'] = '-';
|
||||
|
Loading…
x
Reference in New Issue
Block a user