From ed3303297f6d0e675e74043525b4982c80387ee4 Mon Sep 17 00:00:00 2001 From: vilson <545522390@qq.com> Date: Sun, 23 Feb 2020 16:06:09 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=86=E8=8A=82=E4=BC=98=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/Member.php | 45 ++++++++++++++++--- application/common/Model/MemberAccount.php | 7 ++- application/common/Model/Notify.php | 10 +++-- application/common/Model/Project.php | 9 +++- application/project/controller/Login.php | 2 +- .../project/controller/Organization.php | 9 +++- application/project/controller/Project.php | 13 +++--- extend/service/NodeService.php | 5 ++- 8 files changed, 77 insertions(+), 23 deletions(-) diff --git a/application/common/Model/Member.php b/application/common/Model/Member.php index 0cdd7ac..f0a064f 100644 --- a/application/common/Model/Member.php +++ b/application/common/Model/Member.php @@ -27,7 +27,7 @@ class Member extends CommonModel 'last_login_time' => Db::raw('now()'), ]); $list = MemberAccount::where(['member_code' => $member['code']])->order('id asc')->select()->toArray(); - $organizationList = []; + $organizationList = self::getOrgList($member['code'], true); if ($list) { foreach ($list as &$item) { $departments = []; @@ -40,10 +40,6 @@ class Member extends CommonModel } } $item['department'] = $departments ? implode(' - ', $departments) : ''; - $organization = Organization::where(['code' => $item['organization_code']])->find(); - if ($organization) { - $organizationList[] = $organization; - } } } $member['account_id'] = $list[0]['id']; @@ -64,6 +60,41 @@ class Member extends CommonModel return $loginInfo; } + /** + * 获取当前用户所在的组织 + * @param string $memberCode + * @param bool $newest 是否取最新的值 + * @return array + * @throws DataNotFoundException + * @throws DbException + * @throws ModelNotFoundException + */ + public static function getOrgList(string $memberCode, $newest = false) + { + $organizationList = []; + if (!$memberCode) { + return $organizationList; + } + $cacheKey = 'member:orgList:' . $memberCode; + if (!$newest) { + $organizationList = cache($cacheKey); + if ($organizationList) { + return $organizationList; + } + } + $list = MemberAccount::where(['member_code' => $memberCode])->order('id asc')->select()->toArray(); + if ($list) { + foreach ($list as $item) { + $organization = Organization::where(['code' => $item['organization_code']])->find(); + if ($organization) { + $organizationList[] = $organization; + } + } + } + cache($cacheKey, $organizationList, 3600 * 24); + return $organizationList; + } + /** * @param $memberData * @return Member @@ -176,7 +207,7 @@ class Member extends CommonModel if (!$currentMember['dingtalk_unionid'] || !$currentMember['dingtalk_userid']) { if ($currentMember['mobile']) { unset($memberData['mobile']); - }else{ + } else { $has = self::where(['mobile' => $memberData['mobile']])->find(); if ($has) { return error('1', '您想要绑定的手机号码已经被绑定给其他帐号,请先用该手机号码登录后进行重置,再切回当前帐号发起绑定'); @@ -184,7 +215,7 @@ class Member extends CommonModel } if ($currentMember['email']) { unset($memberData['email']); - }else{ + } else { $has = self::where(['email' => $memberData['email']])->find(); if ($has) { return error('1', '您想要绑定的邮箱已经被绑定给其他帐号,请先用该邮箱登录后进行重置,再切回当前帐号发起绑定'); diff --git a/application/common/Model/MemberAccount.php b/application/common/Model/MemberAccount.php index 642e140..0456a5c 100644 --- a/application/common/Model/MemberAccount.php +++ b/application/common/Model/MemberAccount.php @@ -73,7 +73,10 @@ class MemberAccount extends CommonModel 'mobile' => $mobile, 'email' => $memberDate['email'], ]; - return MemberAccount::create($data); + $result = MemberAccount::create($data); + $cacheKey = 'member:orgList:' . $memberCode; + cache($cacheKey, null); + return $result; } /** @@ -126,6 +129,8 @@ class MemberAccount extends CommonModel $orgCode = getCurrentOrganizationCode(); DepartmentMember::where(['account_code' => $accountCode, 'organization_code' => $orgCode])->delete(); } + $cacheKey = 'member:orgList:' . $memberAccount['member_code']; + cache($cacheKey, null); Db::commit(); } catch (Exception $e) { Db::rollback(); diff --git a/application/common/Model/Notify.php b/application/common/Model/Notify.php index 841fe01..d4b0029 100644 --- a/application/common/Model/Notify.php +++ b/application/common/Model/Notify.php @@ -22,12 +22,14 @@ class Notify extends CommonModel $formatList = []; $total = $this->where($where)->count('id'); if ($list) { + foreach ($types as $type) { + !isset($formatList[$type]) and $formatList[$type] = []; + !isset($totalSum[$type]) and $totalSum[$type] = 0; + $sum = $this->where($where)->where(['type' => $type])->count('id'); + $totalSum[$type] = $sum; + } foreach ($list as &$item) { foreach ($types as $type) { - !isset($formatList[$type]) and $formatList[$type] = []; - !isset($totalSum[$type]) and $totalSum[$type] = 0; - $sum = $this->where($where)->where(['type' => $type])->count('id'); - $totalSum[$type] = $sum; if ($size and count($formatList[$type]) >= $size) { continue; } diff --git a/application/common/Model/Project.php b/application/common/Model/Project.php index 843054c..1cf5470 100644 --- a/application/common/Model/Project.php +++ b/application/common/Model/Project.php @@ -36,7 +36,14 @@ class Project extends CommonModel $offset = ($page - 1) * $page; $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' and p.deleted = {$deleted} and p.archive = {$archive} order by pc.id desc, p.id desc"; + $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} "; + } + $sql .= " order by pc.id desc, p.id desc"; $total = Db::query($sql); $total = count($total); $sql .= " limit {$offset},{$limit}"; diff --git a/application/project/controller/Login.php b/application/project/controller/Login.php index e041474..1f9034b 100644 --- a/application/project/controller/Login.php +++ b/application/project/controller/Login.php @@ -86,7 +86,7 @@ class Login extends BasicApi } else { !$data['password'] && $this->error('登录密码不能为空!'); !$data['account'] && $this->error('登录账号不能为空!'); - $member = Member::where(['account' => $data['account']])->whereOr(['email' => $data['account']])->order('id asc')->find(); + $member = Member::where(['account' => $data['account']])->whereOr(['email' => $data['account']])->whereOr(['mobile' => $data['account']])->order('id asc')->find(); } empty($member) && $this->error('账号或密码错误', 201); $member = $member->toArray(); diff --git a/application/project/controller/Organization.php b/application/project/controller/Organization.php index 1364b65..7054f90 100644 --- a/application/project/controller/Organization.php +++ b/application/project/controller/Organization.php @@ -2,6 +2,7 @@ namespace app\project\controller; +use app\common\Model\Member; use controller\BasicApi; use think\db\exception\DataNotFoundException; use think\db\exception\ModelNotFoundException; @@ -18,6 +19,12 @@ class Organization extends BasicApi } } + public function _getOrgList() + { + $list = Member::getOrgList(getCurrentMember()['code']); + $this->success('', $list); + } + /** * 显示资源列表 * @@ -103,7 +110,7 @@ class Organization extends BasicApi /** * 删除指定资源 * - * @param int $id + * @param int $id * @return void */ public function delete($id = 0) diff --git a/application/project/controller/Project.php b/application/project/controller/Project.php index b4cf413..75ad8ab 100644 --- a/application/project/controller/Project.php +++ b/application/project/controller/Project.php @@ -181,8 +181,10 @@ class Project extends BasicApi */ public function selfList() { - $type = Request::post('type'); + $type = Request::post('type', 0); $archive = Request::param('archive', 0); + $delete = Request::param('delete'); + $organizationCode = Request::param('organizationCode', ''); $memberCode = Request::post('memberCode', ''); if (!$memberCode) { $member = getCurrentMember(); @@ -192,11 +194,11 @@ class Project extends BasicApi if (!$member) { $this->error("参数有误"); } - $deleted = 1; + $deleted = $delete === null ? 1 : $delete; if (!$type) { $deleted = 0; } - $list = $this->model->getMemberProjects($member['code'], getCurrentOrganizationCode(), $deleted, $archive, Request::post('page'), Request::post('pageSize')); + $list = $this->model->getMemberProjects($member['code'], $organizationCode ?? getCurrentOrganizationCode(), $deleted, $archive, Request::post('page'), Request::post('pageSize')); if ($list['list']) { foreach ($list['list'] as $key => &$item) { $item['owner_name'] = '-'; @@ -206,9 +208,8 @@ class Project extends BasicApi } $collected = ProjectCollection::where(['project_code' => $item['code'], 'member_code' => getCurrentMember()['code']])->field('id')->find(); $item['collected'] = $collected ? 1 : 0; - $owner = ProjectMember::where(['project_code' => $item['code'], 'is_owner' => 1])->field('member_code')->find(); - $member = Member::where(['code' => $owner['member_code']])->field('name')->find(); - $item['owner_name'] = $member['name']; + $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); } diff --git a/extend/service/NodeService.php b/extend/service/NodeService.php index 34431ee..57b5204 100644 --- a/extend/service/NodeService.php +++ b/extend/service/NodeService.php @@ -21,6 +21,7 @@ class NodeService { cache('member_need_access_node', null); $member = getCurrentMember(); + $member['nodes'] = []; if (($authorize = $member['authorize'])) { $where = ['status' => '1']; $authorizeIds = Db::name('ProjectAuth')->whereIn('id', explode(',', $authorize))->where($where)->column('id'); @@ -32,7 +33,7 @@ class NodeService $member['nodes'] = $nodes; return setCurrentMember($member); } - return false; + return setCurrentMember($member); } /** @@ -68,7 +69,7 @@ class NodeService if (!in_array($currentNode, self::getProjectAuthNode())) { return true; } - return in_array($currentNode, (array)$member['nodes']); + return in_array($currentNode, !empty($member['nodes']) ? (array)$member['nodes'] : []); } return false; }