Skip to content

Commit

Permalink
Merge pull request #10 from a54552239/dev
Browse files Browse the repository at this point in the history
v2.8.9
  • Loading branch information
a54552239 authored Feb 23, 2020
2 parents 99a16dd + a61566d commit 6739f68
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 3,072 deletions.
45 changes: 38 additions & 7 deletions application/common/Model/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static function login($member)
'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 = [];
Expand All @@ -40,10 +40,6 @@ public static function login($member)
}
}
$item['department'] = $departments ? implode(' - ', $departments) : '';
$organization = Organization::where(['code' => $item['organization_code']])->find();
if ($organization) {
$organizationList[] = $organization;
}
}
}
$member['account_id'] = $list[0]['id'];
Expand All @@ -64,6 +60,41 @@ public static function login($member)
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
Expand Down Expand Up @@ -176,15 +207,15 @@ public static function dingtalkLogin($userInfo)
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', '您想要绑定的手机号码已经被绑定给其他帐号,请先用该手机号码登录后进行重置,再切回当前帐号发起绑定');
}
}
if ($currentMember['email']) {
unset($memberData['email']);
}else{
} else {
$has = self::where(['email' => $memberData['email']])->find();
if ($has) {
return error('1', '您想要绑定的邮箱已经被绑定给其他帐号,请先用该邮箱登录后进行重置,再切回当前帐号发起绑定');
Expand Down
7 changes: 6 additions & 1 deletion application/common/Model/MemberAccount.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public static function inviteMember($memberCode, $organizationCode, $position =
'mobile' => $mobile,
'email' => $memberDate['email'],
];
return MemberAccount::create($data);
$result = MemberAccount::create($data);
$cacheKey = 'member:orgList:' . $memberCode;
cache($cacheKey, null);
return $result;
}

/**
Expand Down Expand Up @@ -126,6 +129,8 @@ public function del($accountCode)
$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();
Expand Down
10 changes: 6 additions & 4 deletions application/common/Model/Notify.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ public function listTypeFormat($where, $size = false)
$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;
}
Expand Down
9 changes: 8 additions & 1 deletion application/common/Model/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,14 @@ public function getMemberProjects($memberCode = '',$organizationCode = '', $dele
$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}";
Expand Down
2 changes: 1 addition & 1 deletion application/project/controller/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function index()
} 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();
Expand Down
9 changes: 8 additions & 1 deletion application/project/controller/Organization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,6 +19,12 @@ public function __construct()
}
}

public function _getOrgList()
{
$list = Member::getOrgList(getCurrentMember()['code']);
$this->success('', $list);
}

/**
* 显示资源列表
*
Expand Down Expand Up @@ -103,7 +110,7 @@ public function edit(Request $request)
/**
* 删除指定资源
*
* @param int $id
* @param int $id
* @return void
*/
public function delete($id = 0)
Expand Down
13 changes: 7 additions & 6 deletions application/project/controller/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ public function analysis(Request $request)
*/
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();
Expand All @@ -192,11 +194,11 @@ public function selfList()
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'] = '-';
Expand All @@ -206,9 +208,8 @@ public function selfList()
}
$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);
}
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
// 应用名称
'app_name' => 'pearProject',
// 应用版本
'app_version' => '2.8.8',
'app_version' => '2.8.9',
// 应用地址
'app_host' => '',
// 应用调试模式
Expand Down
Loading

0 comments on commit 6739f68

Please sign in to comment.