logic = (new UserLogic()); } /** * 获取用户信息(包括菜单和权限) */ public function getUserInfo(int $uid, string $systemCode) { $user = $this->logic->userInfo($uid); // $permService = new PermService(); // $menuTree = $permService->getMenuTree($uid, $systemCode); // $permissionCodes = $permService->getPermissionCodes($uid, $systemCode); $corp_name = Corp::where('abbr', $user->corp_id)->value('name'); return [ 'user' => [ 'id' => $user->id, 'name' => $user->name, 'avatar' => $user->avatar, 'phone' => $user->phone, 'email' => $user->email, 'status' => $user->status, 'roles' => $user->roles->pluck('name'), 'roles_id' => $user->roles->pluck('id'), 'sex' => $user->sex, 'sn' => $user->sn, 'corp_id' => $user->corp_id, 'corp_name' => $corp_name, 'report_to' => $user->report_to, 'sign_img' => $user->sign_img, 'sign_img_url' => (!empty($user->sign_img))?(new \app\common\service\OssService)->generatePrivateUrl($user->sign_img):'', ], // 'menu' => $menuTree, // 'permissions' => $permissionCodes ]; } /** * 获取用户信息(包括菜单和权限) */ 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 [ 'id' => $user->id, 'sn' => $user->sn, 'name' => $user->name, 'position' => $user->position, 'socialize' => $user->socialize, 'socialize_pic' => $user->socialize_pic, 'socialize_pic_full' => (!empty($user->socialize_pic))?$ossservice->generatePrivateUrl($user->socialize_pic):'', 'country_id' => $user->country_id, 'country_txt' => Country::where('id',$user->country_id)->value('cn_addr'), 'avatar' => $user->avatar, 'avatar_full' => $user->avatar, 'phone' => $user->phone, 'corp_name' => $corp_name, 'email' => $user->email, 'sex' => $user->sex, 'status' => $user->status, '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 ]; } /** * 编辑用户信息 */ public function edit(int $uid, array $data) { unset($data['password']); unset($data['phone']); unset($data['email']); unset($data['sn']); $user = $this->logic->edit($uid,$data); return $user; } /** * 修改用户密码 */ public function savePassword(int $uid, array $data) { // 对密码进行哈希处理 $password = $data['password']; $user = User::find($uid); if (!password_verify($password, $user->password)) { throw new BusinessException('密码错误'); } $user = $this->logic->savePassword($uid,$data); return $user; } /** * 获取用户列表 */ public function getList(Request $request) { return $this->logic->getList($request); } /** 分页列表 */ public function serviceTeam(Request $request) { $config = $this->buildQueryConfig($request, 'team'); $limit = (int)$request->get('size', 15); $page = (int)$request->get('current', 1); $result = $this->logicList($config, $limit, $page); foreach ($result as &$data){ $data['customer_count'] = Customer::where('user_id', $data['id'])->count(); unset($data['password']); unset($data['open_id']); unset($data['tenant_key']); unset($data['union_id']); } return $this->postProcess('List', $result); } /** 分页列表 */ public function resignMember(Request $request) { $uid = $request->user->uid; $userId = $request->get('user_id'); $user = User::find($userId); if ($user->report_to != $uid) { throw new BusinessException('禁止操作非组员'); } $data = [ 'status' => 2, ]; $user = $this->logic->edit($userId,$data); $user = $user->toArray(); unset($user['password']); unset($user['open_id']); unset($user['tenant_key']); unset($user['union_id']); return $user; } /** * 构造 CrudUtil 查询配置 */ protected function buildQueryConfig(Request $request, string $scene = 'default'): array { $p = $request->all(); $config = []; $config['model'] = $this->modelClass; switch ($scene) { case 'team': // $config['where']['status'] = 1; // 关键字 $config['order']['id'] = 'desc'; if (isset($p['status']) && $p['status']) { $config['where']['status'] = $p['status']; } $config['with']= ['reportToInfo']; if (!in_array(1, $request->user->role_ids)) { $config['where']['reportToInfo.id'] = $request->user->uid; } // $config['dataLimit']['type'] = 'relation'; // $config['dataLimit']['userId'] = $request->user->uid; // $config['dataLimit']['userField'] = 'report_to'; break; } return $config; } public function checkBind($userId) { $user = \app\common\model\User::find($userId); if (!$user->report_to) { throw new BusinessException('请先前往个人中心-绑定直属上级'); } if ($user->sign_img === null || $user->sign_img === '') { throw new BusinessException('请先前往个人中心-操作签名'); } $ug = \app\common\model\UserGroupMembers::with(['group' => function($query) { $query->where('scenario_code', 'stock_orders'); }])->where('user_id', $userId)->first(); if (!$ug) { throw new BusinessException('请先前往个人中心-绑定内勤'); } return true; } }