优化组织内项目列表的显示逻辑,划分更清晰
Signed-off-by: vilson <545522390@qq.com>
This commit is contained in:
parent
af98ad13d5
commit
5a1b1e09e6
@ -2,9 +2,9 @@
|
||||
|
||||
namespace app\common\Model;
|
||||
|
||||
use app\shop\Model\ShopGoods;
|
||||
use service\FileService;
|
||||
use service\ToolsService;
|
||||
use think\Db;
|
||||
use think\facade\Request;
|
||||
use think\File;
|
||||
use think\Model;
|
||||
@ -23,6 +23,20 @@ class CommonModel extends Model
|
||||
ToolsService::error($msg, $data, $code);
|
||||
}
|
||||
|
||||
public static function limitByQuery($sql, $page = 1, $pageSize = 10)
|
||||
{
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
$offset = ($page - 1) * $pageSize;
|
||||
$limit = $pageSize;
|
||||
$total = Db::query($sql);
|
||||
$total = count($total);
|
||||
$sql .= " limit {$offset},{$limit}";
|
||||
$list = Db::query($sql);
|
||||
return ['total' => $total, 'list' => $list, 'page' => $page];
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页方法
|
||||
* @param null $where 可以传入查询对象或模型实例
|
||||
@ -88,7 +102,7 @@ class CommonModel extends Model
|
||||
|
||||
public function _edit($data, $where = [])
|
||||
{
|
||||
return $this->isUpdate(true)->save($data,$where);
|
||||
return $this->isUpdate(true)->save($data, $where);
|
||||
}
|
||||
|
||||
public function _add($data)
|
||||
@ -131,21 +145,4 @@ class CommonModel extends Model
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取当前organization id
|
||||
* */
|
||||
public function gecurrentOrganizationCode(){
|
||||
$currentOrganizationCode = session('currentOrganizationCode');
|
||||
return $currentOrganizationCode;
|
||||
}
|
||||
|
||||
/*
|
||||
* 获取当前member session
|
||||
* */
|
||||
public function getMemberSession(){
|
||||
$member_session = session('member');
|
||||
return $member_session;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,10 +3,9 @@
|
||||
namespace app\common\Model;
|
||||
|
||||
use service\FileService;
|
||||
use service\RandomService;
|
||||
use think\Db;
|
||||
use think\facade\Hook;
|
||||
use think\File;
|
||||
use think\File as thinkFile;
|
||||
|
||||
/**
|
||||
* 项目
|
||||
@ -23,18 +22,21 @@ class Project extends CommonModel
|
||||
return self::where(['id' => $id, 'deleted' => 0, 'archive' => 0])->find();
|
||||
}
|
||||
|
||||
public function getMemberProjects($memberCode = '', $deleted = 0, $archive = 0, $page = 1, $pageSize = 10)
|
||||
public function getMemberProjects($memberCode = '',$organizationCode = '', $deleted = 0, $archive = 0, $page = 1, $pageSize = 10)
|
||||
{
|
||||
if (!$memberCode) {
|
||||
$memberCode = getCurrentMember()['code'];
|
||||
}
|
||||
if (!$organizationCode) {
|
||||
$organizationCode = getCurrentOrganizationCode();
|
||||
}
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
}
|
||||
$offset = ($page - 1) * $page;
|
||||
$limit = $pageSize;
|
||||
$prefix = config('database.prefix');
|
||||
$sql = "select *,p.id as id,p.name as name,p.code as code from {$prefix}project as p join {$prefix}project_member as pm on p.code = pm.project_code where pm.member_code = '{$memberCode}' and p.deleted = {$deleted} and p.archive = {$archive} order by p.id desc";
|
||||
$sql = "select *,p.id as id,p.name as name,p.code as code from {$prefix}project as p join {$prefix}project_member as pm on p.code = pm.project_code where pm.member_code = '{$memberCode}' and p.organization_code = '$organizationCode' and p.deleted = {$deleted} and p.archive = {$archive} order by p.id desc";
|
||||
$total = Db::query($sql);
|
||||
$total = count($total);
|
||||
$sql .= " limit {$offset},{$limit}";
|
||||
@ -118,7 +120,7 @@ class Project extends CommonModel
|
||||
* @throws \think\exception\PDOException
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function uploadCover(File $file)
|
||||
public function uploadCover(thinkFile $file)
|
||||
{
|
||||
return $this->_uploadImg($file);
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ class Notify extends BasicApi
|
||||
|
||||
public function noReads()
|
||||
{
|
||||
$projectId = $this->model->gecurrentOrganizationCode();
|
||||
$projectId = getCurrentOrganizationCode();
|
||||
$list = $this->model->listTypeFormat(['is_read' => 0, 'to' => 0], 5);
|
||||
$this->success('', $list);
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ class Notify extends BasicApi
|
||||
if (!$this->model) {
|
||||
$this->model = new \app\common\Model\Notify();
|
||||
}
|
||||
$this->session = $this->model->getMemberSession();
|
||||
$this->session = getCurrentMember();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\project\controller;
|
||||
|
||||
use app\common\Model\CommonModel;
|
||||
use app\common\Model\Member;
|
||||
use app\common\Model\MemberAccount;
|
||||
use app\common\Model\Notify;
|
||||
@ -14,7 +15,10 @@ use service\FileService;
|
||||
use service\NodeService;
|
||||
use service\RandomService;
|
||||
use think\Db;
|
||||
use think\db\exception\DataNotFoundException;
|
||||
use think\db\exception\ModelNotFoundException;
|
||||
use think\Exception;
|
||||
use think\Exception\DbException;
|
||||
use think\exception\PDOException;
|
||||
use think\facade\Request;
|
||||
use think\File;
|
||||
@ -35,53 +39,48 @@ class Project extends BasicApi
|
||||
* 显示资源列表
|
||||
*
|
||||
* @return void
|
||||
* @throws \think\exception\DbException
|
||||
* @throws DbException
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$where = [];
|
||||
$prefix = config('database.prefix');
|
||||
$type = Request::post('type');
|
||||
$page = Request::param('page', 1);
|
||||
$pageSize = Request::param('pageSize', cookie('pageSize'));
|
||||
$data = Request::only('recycle,archive,all');
|
||||
$member = getCurrentMember();
|
||||
$currentMember = getCurrentMember();
|
||||
$memberCode = $currentMember['code'];
|
||||
|
||||
$where[] = ['member_code', '=', $member['code']];
|
||||
$orgCode = getCurrentOrganizationCode();
|
||||
if ($type == 'my' || $type == 'other') {
|
||||
$projectMemberModel = new ProjectMember();
|
||||
$list = $projectMemberModel->_list($where);
|
||||
$sql = "select * from {$prefix}project as pp join {$prefix}project_member as pm on pm.project_code = pp.code where pp.organization_code = '{$orgCode}' and (pm.member_code = '{$memberCode}' or pp.private = 0) group by pp.`code`";
|
||||
$list = CommonModel::limitByQuery($sql, $page, $pageSize);
|
||||
} else {
|
||||
$projectCollectionModel = new ProjectCollection();
|
||||
$where[] = ['member_code', '=', $member['code']];
|
||||
$list = $projectCollectionModel->_list($where);
|
||||
$sql = "select * from {$prefix}project as pp join {$prefix}project_collection as pc on pc.project_code = pp.code where pp.organization_code = '{$orgCode}' and pc.member_code = '{$memberCode}' group by pp.`code`";
|
||||
$list = CommonModel::limitByQuery($sql, $page, $pageSize);
|
||||
}
|
||||
$newList = [];
|
||||
if ($list['list']) {
|
||||
$currentMember = getCurrentMember();
|
||||
foreach ($list['list'] as $key => &$item) {
|
||||
$delete = false;
|
||||
$project = $this->model->where(['code' => $item->project_code])->find();
|
||||
if (!$project) {
|
||||
$delete = true;
|
||||
}
|
||||
if ($type != 'other') {
|
||||
if ($project['deleted']) {
|
||||
if ($item['deleted']) {
|
||||
$delete = true;
|
||||
}
|
||||
}
|
||||
if (isset($data['archive']) && !$project['archive']) {
|
||||
if (isset($data['archive']) && !$item['archive']) {
|
||||
$delete = true;
|
||||
}
|
||||
if (isset($data['recycle']) && !$project['deleted']) {
|
||||
|
||||
if (isset($data['recycle']) && !$item['deleted']) {
|
||||
$delete = true;
|
||||
}
|
||||
if ($delete) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$item['collected'] = false;
|
||||
$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' => $currentMember['code']])->field('id')->find();
|
||||
if ($collected) {
|
||||
$item['collected'] = true;
|
||||
@ -104,9 +103,9 @@ class Project extends BasicApi
|
||||
|
||||
/**
|
||||
* 获取自己的项目
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @throws \think\exception\DbException
|
||||
* @throws DataNotFoundException
|
||||
* @throws ModelNotFoundException
|
||||
* @throws DbException
|
||||
*/
|
||||
public function selfList()
|
||||
{
|
||||
@ -125,7 +124,7 @@ class Project extends BasicApi
|
||||
if (!$type) {
|
||||
$deleted = 0;
|
||||
}
|
||||
$list = $this->model->getMemberProjects($member['code'], $deleted, $archive, Request::post('page'), Request::post('pageSize'));
|
||||
$list = $this->model->getMemberProjects($member['code'], getCurrentOrganizationCode(), $deleted, $archive, Request::post('page'), Request::post('pageSize'));
|
||||
if ($list['list']) {
|
||||
foreach ($list['list'] as $key => &$item) {
|
||||
$item['collected'] = false;
|
||||
@ -178,7 +177,7 @@ class Project extends BasicApi
|
||||
*
|
||||
* @param Request $request
|
||||
* @return void
|
||||
* @throws \think\Exception\DbException
|
||||
* @throws DbException
|
||||
*/
|
||||
public function read(Request $request)
|
||||
{
|
||||
@ -233,7 +232,9 @@ class Project extends BasicApi
|
||||
public function getLogBySelfProject()
|
||||
{
|
||||
$projectCode = Request::param('projectCode', '');
|
||||
$orgCode = getCurrentOrganizationCode();
|
||||
$member = getCurrentMember();
|
||||
$memberCode = $member['code'];
|
||||
if (!$member) {
|
||||
$this->success('', []);
|
||||
}
|
||||
@ -242,10 +243,13 @@ class Project extends BasicApi
|
||||
$where = [];
|
||||
$where[] = ['member_code', '=', $member['code']];
|
||||
$projectCodes = ProjectMember::where($where)->column('project_code');
|
||||
$sql = "select pp.code from {$prefix}project as pp join {$prefix}project_member as pm on pm.project_code = pp.code where pp.organization_code = '{$orgCode}' and (pm.member_code = '{$memberCode}') group by pp.`code`";
|
||||
$projectCodes = Db::query($sql);
|
||||
if (!$projectCodes) {
|
||||
$this->success('', []);
|
||||
}
|
||||
foreach ($projectCodes as &$projectCode) {
|
||||
$projectCode = $projectCode['code'];
|
||||
$projectCode = "'{$projectCode}'";
|
||||
}
|
||||
$projectCodes = implode(',', $projectCodes);
|
||||
|
@ -27,8 +27,7 @@
|
||||
"overtrue/easy-sms": "^1.1",
|
||||
"phpoffice/phpspreadsheet": "^1.5",
|
||||
"firebase/php-jwt": "^5.0",
|
||||
"phpmailer/phpmailer": "^6.0",
|
||||
"weiwei/api-doc": "dev-master"
|
||||
"phpmailer/phpmailer": "^6.0"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user