diff --git a/app/common/controller/UserController.php b/app/common/controller/UserController.php index 2a55181..fc8413d 100644 --- a/app/common/controller/UserController.php +++ b/app/common/controller/UserController.php @@ -22,6 +22,20 @@ class UserController extends BaseController } } + /** + * 用户信息 + */ + public function getUser(Request $request) + { + try { + $uid = $request->user->uid; + $result = (new UserService())->getUser($uid); + return $this->success($result, '获取用户信息'); + } catch (\Throwable $e) { + return $this->error($e->getMessage()); + } + } + /** * 编辑用户 */ diff --git a/app/common/service/UserService.php b/app/common/service/UserService.php index b927c52..f5daf14 100644 --- a/app/common/service/UserService.php +++ b/app/common/service/UserService.php @@ -3,6 +3,7 @@ namespace app\common\service; use app\common\logic\UserLogic; +use app\crm\model\Country; class UserService { @@ -38,6 +39,29 @@ class UserService ]; } + + /** + * 获取用户信息(包括菜单和权限) + */ + public function getUser(int $uid) + { + $user = $this->logic->userInfo($uid); + return [ + 'id' => $user->id, + 'name' => $user->name, + 'position' => $user->position, + 'socialize' => $user->socialize, + 'socialize_pic' => $user->socialize_pic, + 'country_id' => $user->country_id, + 'country_txt' => Country::where('id',$user->country_id)->value('cn_addr'), + 'avatar' => $user->avatar, + 'phone' => $user->phone, + 'email' => $user->email, + 'status' => $user->status, + 'roles' => $user->roles->pluck('name') + ]; + } + /** * 获取用户信息(包括菜单和权限) */ diff --git a/config/route.php b/config/route.php index 3563589..737ce1b 100644 --- a/config/route.php +++ b/config/route.php @@ -40,6 +40,7 @@ Route::group('/common', function () { Route::group('/user', function () { Route::any('/info', [app\common\controller\UserController::class, 'info']); + Route::any('/get', [app\common\controller\UserController::class, 'getUser']); }); Route::group('/preset', function () {