From 04d7d73c45690135c08ee6fff73c660a7b2e0778 Mon Sep 17 00:00:00 2001 From: mzl Date: Mon, 13 Oct 2025 13:25:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=B8=9A=E5=8A=A1=E5=BC=BA?= =?UTF-8?q?=E5=88=B6=E7=BB=91=E5=AE=9A=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/common/controller/PresetController.php | 4 +- app/common/logic/UserLogic.php | 37 ++++++++++++-- app/common/model/User.php | 6 +++ app/common/service/UserService.php | 29 ++++++++++- app/common/utils/WsEvents.php | 56 ++++++++++++++++++++-- app/process/CheckWeb.php | 16 +++++++ 6 files changed, 136 insertions(+), 12 deletions(-) diff --git a/app/common/controller/PresetController.php b/app/common/controller/PresetController.php index b1c428e..bd92d2f 100644 --- a/app/common/controller/PresetController.php +++ b/app/common/controller/PresetController.php @@ -65,10 +65,10 @@ class PresetController extends BaseController } - public function users() + public function users(Request $request) { try { - $result = (new UserService())->getList(); + $result = (new UserService())->getList($request); return $this->success($result, '获取用户列表'); } catch (\Throwable $e) { return $this->error($e->getMessage()); diff --git a/app/common/logic/UserLogic.php b/app/common/logic/UserLogic.php index c7d5343..55e9608 100644 --- a/app/common/logic/UserLogic.php +++ b/app/common/logic/UserLogic.php @@ -3,8 +3,11 @@ namespace app\common\logic; use app\common\model\User; +use app\common\model\UserGroupMembers; use app\common\traits\crud\CrudLogicTrait; use support\exception\BusinessException; +use support\Request; +use app\common\model\UserRoles; class UserLogic { @@ -20,7 +23,7 @@ class UserLogic */ public function userInfo(int $uid) { - $user = User::find($uid); + $user = User::with('reportToInfo')->find($uid); if (!$user) { throw new BusinessException('账户不存在', 404); @@ -38,6 +41,7 @@ class UserLogic */ public function edit(int $uid, array $data) { + // $user = User::find($uid); if (!$user) { @@ -47,6 +51,26 @@ class UserLogic $user->fill($data); $user->save(); + // 绑定内勤 10.13 add + if (isset($data['office_clerk_id']) && $data['office_clerk_id'] > 0) { + $ug = UserGroupMembers::where('user_id', $uid)->where('status', 1)->first(); + if ($ug) { + $ug->delete(); + } + + $group = UserGroupMembers::where('user_id', $data['office_clerk_id'])->where('is_leader', 1)->where('status', 1)->first(); + if (!$group) { + throw new BusinessException('该内勤还未创建分组', 404); + } + + UserGroupMembers::create([ + 'user_id' => $uid, + 'group_id' => $group->group_id, + 'is_leader' => 0, + 'status' => 1 + ]); + } + return $user; } @@ -64,9 +88,16 @@ class UserLogic /** * 获取用户列表 */ - public function getList() + public function getList(Request $request) { - $list = User::where('status', 1)->orderBy('id', 'desc')->get(); + $p = $request->all(); + + $user = User::where('status', 1); + if (isset($p['role_id']) && $p['role_id'] > 0) { + $userIds = UserRoles::where('role_id', $p['role_id'])->pluck('user_id'); + $user->whereIn('id', $userIds); + } + $list = $user->orderBy('id', 'desc')->get(); $arr = []; foreach ($list->toArray() as $item) { $arr[] = [ diff --git a/app/common/model/User.php b/app/common/model/User.php index 88c670d..9a9a4fa 100644 --- a/app/common/model/User.php +++ b/app/common/model/User.php @@ -98,4 +98,10 @@ class User extends Model ->orWhere('phone', $account) ->orWhere('email', $account); } + + + public function reportToInfo() + { + return $this->hasOne(User::class, 'id', 'report_to'); + } } \ No newline at end of file diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index 74c12c4..32a7d43 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -5,6 +5,8 @@ namespace app\common\service; use app\common\logic\UserLogic; use app\common\model\Corp; use app\common\model\User; +use app\common\model\UserGroup; +use app\common\model\UserGroupMembers; use app\common\traits\crud\CrudLogicTrait; use app\common\traits\crud\CrudServiceTrait; use app\common\utils\CrudUtil; @@ -68,6 +70,27 @@ class UserService public function getUser(int $uid, $corp_abbr) { $user = $this->logic->userInfo($uid); + + // 查找直属上级 10.13 add + $reportToInfo = []; + if ($user->reportToInfo) { + $reportToInfo = [ + 'id' => $user->reportToInfo->id, + 'name' => $user->reportToInfo->name + ]; + } + + // 查找绑定内勤 10.13 add + $officeClerkInfo = []; + $ugm = UserGroupMembers::where('user_id', $uid)->where('status', 1)->first(); + if ($ugm) { + $lugm = UserGroupMembers::where('group_id', $ugm->group_id)->where('is_leader', 1)->first(); + if ($lugm) { + $officeClerkInfo['id'] = $lugm->user_id; + $officeClerkInfo['name'] = User::where('id', $lugm->user_id)->value('name'); + } + } + $corp_name = Corp::where('abbr', $corp_abbr)->value('name'); $ossservice = new OssService(); return [ @@ -90,6 +113,8 @@ class UserService 'roles' => $user->roles->pluck('name'), 'sign_img' => $user->sign_img, 'sign_img_url' => (!empty($user->sign_img))?$ossservice->generatePrivateUrl($user->sign_img):'', + 'report_to_info' => $reportToInfo, + 'office_clerk_info' => $officeClerkInfo ]; } @@ -126,9 +151,9 @@ class UserService /** * 获取用户列表 */ - public function getList() + public function getList(Request $request) { - return $this->logic->getList(); + return $this->logic->getList($request); } /** 分页列表 */ diff --git a/app/common/utils/WsEvents.php b/app/common/utils/WsEvents.php index e539831..12f1a2c 100644 --- a/app/common/utils/WsEvents.php +++ b/app/common/utils/WsEvents.php @@ -5,6 +5,7 @@ namespace app\common\utils; use GatewayWorker\Lib\Gateway; use app\common\utils\WsResponse; use app\common\service\MessageNotificationsService; +use support\Redis; class WsEvents { @@ -158,14 +159,24 @@ class WsEvents public function systemConnect(?string $traceId) { - $num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($_SESSION['uid']); - $this->todoCounts($_SESSION['uid'], $num); - + // 响应 Gateway::sendToClient($this->clientId, WsResponse::success( 'system.connect.receive', ['time' => time()], $traceId )); + + // 获取审批待办数量 + $num = (new \app\common\utils\approval\service\ApprovalFlowService())->getInitTodoCount($_SESSION['uid']); + $this->todoCounts($_SESSION['uid'], $num); + + // 绑定检查 + $initData = $this->initCheck($_SESSION['uid']); + Gateway::sendToClient($this->clientId, WsResponse::success( + 'system.init.check', + $initData, + $traceId + )); } // ================= 消息通知事件 ================= @@ -259,7 +270,6 @@ class WsEvents /* - init.pull approval.todo.counts 审批待办数量 */ @@ -285,8 +295,44 @@ class WsEvents - // ================= 临时业务处理 ================= + // ================= 业务处理 ================= + /** + * 初始化检查 + */ + public function initCheck(int $userId) + { + $data = [ + 'is_report_to' => false, + 'is_office_clerk' => false, + 'is_sign' => false + ]; + + $user = \app\common\model\User::find($userId); + + if ($user->report_to > 0) { + $data['is_report_to'] = true; + } + + if ($user->sign_img !== null || $user->is_sign !== '') { + $data['is_sign'] = true; + } + + $ug = \app\common\model\UserGroupMembers::with(['group' => function($query) { + $query->where('scenario_code', 'stock_orders'); + }])->where('user_id', $userId)->first(); + if ($ug !== null) { + $data['is_office_clerk'] = true; + } + + if ($data['is_report_to'] && $data['is_office_clerk'] && $data['is_sign']) { + Redis::hSet('user:init:check:'.$userId, 'status', 1); + } + + return $data; + } + + // 审批待办数量 public function todoCounts(int $userId, int $num = 0) { $ly = [ diff --git a/app/process/CheckWeb.php b/app/process/CheckWeb.php index 8baf5b8..31c67b5 100644 --- a/app/process/CheckWeb.php +++ b/app/process/CheckWeb.php @@ -2,6 +2,10 @@ namespace app\process; +use app\common\model\User; +use app\common\model\UserRoles; +use app\common\utils\WsEvents; +use support\Redis; use Workerman\Crontab\Crontab; class CheckWeb @@ -18,6 +22,18 @@ class CheckWeb return true; }); } + + new Crontab('*/3 * * * * *', function(){ + $userIds = UserRoles::where('role_id', 1)->pluck('user_id')->toArray(); + foreach ($userIds as $userId) { + $status = Redis::hGet('user:init:check:'.$userId, 'status'); + if ($status) { + continue; + } + $ws = new WsEvents(); + $ws->pushWebsocket('system.init.check', $userId, $ws->initCheck($userId)); + } + }); }