UserModel.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Laravel框架 [ Laravel ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2017~2021 Laravel研发中心
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://www.laravel.cn
  8. // +----------------------------------------------------------------------
  9. // | Author: wesmiler <12345678@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace App\Models;
  12. use App\Services\UserRoleService;
  13. use phpDocumentor\Reflection\Types\Parent_;
  14. /**
  15. * 人员管理-模型
  16. * @author wesmiler
  17. * @since 2020/11/10
  18. * Class AdminModel
  19. * @package App\Models
  20. */
  21. class UserModel extends BaseModel
  22. {
  23. // 设置数据表
  24. protected $table = 'user';
  25. /**
  26. * 获取数据信息
  27. * @param int $id 用户ID
  28. * @return array|string
  29. * @author wesmiler
  30. * @since 2020/11/10
  31. */
  32. public function getInfo($id)
  33. {
  34. $info = parent::getInfo($id); // TODO: Change the autogenerated stub
  35. if ($info) {
  36. // 头像
  37. if ($info['avatar']) {
  38. $info['avatar'] = get_image_url($info['avatar']);
  39. }
  40. // 性别
  41. if ($info['gender']) {
  42. $info['gender_name'] = config('admin.gender_list')[$info['gender']];
  43. }
  44. // 岗位
  45. if ($info['position_id']) {
  46. $positionModel = new PositionModel();
  47. $positionInfo = $positionModel->getInfo($info['position_id']);
  48. $info['position_name'] = $positionInfo['name'];
  49. }
  50. // 职级
  51. if ($info['level_id']) {
  52. $levelMod = new LevelModel();
  53. $levelInfo = $levelMod->getInfo($info['level_id']);
  54. $info['level_name'] = $levelInfo['name'];
  55. }
  56. // 获取用户角色列表
  57. $userRoleService = new UserRoleService();
  58. $roleList = $userRoleService->getUserRoleList($id);
  59. $info['roles'] = $roleList;
  60. }
  61. return $info;
  62. }
  63. }