Admin.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\model\auth;
  15. use app\common\enum\YesNoEnum;
  16. use app\common\model\BaseModel;
  17. use app\common\model\dept\Dept;
  18. use think\model\concern\SoftDelete;
  19. use app\common\service\FileService;
  20. class Admin extends BaseModel
  21. {
  22. use SoftDelete;
  23. protected $deleteTime = 'delete_time';
  24. protected $append = [
  25. 'role_id',
  26. 'dept_id',
  27. 'jobs_id',
  28. ];
  29. /**
  30. * @notes 关联角色id
  31. * @param $value
  32. * @param $data
  33. * @return array
  34. * @author 段誉
  35. * @date 2022/11/25 15:00
  36. */
  37. public function getRoleIdAttr($value, $data)
  38. {
  39. return AdminRole::where('admin_id', $data['id'])->column('role_id');
  40. }
  41. /**
  42. * @notes 关联部门id
  43. * @param $value
  44. * @param $data
  45. * @return array
  46. * @author 段誉
  47. * @date 2022/11/25 15:00
  48. */
  49. public function getDeptIdAttr($value, $data)
  50. {
  51. return AdminDept::where('admin_id', $data['id'])->column('dept_id');
  52. }
  53. /**
  54. * @notes 关联岗位id
  55. * @param $value
  56. * @param $data
  57. * @return array
  58. * @author 段誉
  59. * @date 2022/11/25 15:01\
  60. */
  61. public function getJobsIdAttr($value, $data)
  62. {
  63. return AdminJobs::where('admin_id', $data['id'])->column('jobs_id');
  64. }
  65. /**
  66. * @notes 获取禁用状态
  67. * @param $value
  68. * @param $data
  69. * @return string|string[]
  70. * @author 令狐冲
  71. * @date 2021/7/7 01:25
  72. */
  73. public function getDisableDescAttr($value, $data)
  74. {
  75. return YesNoEnum::getDisableDesc($data['disable']);
  76. }
  77. /**
  78. * @notes 最后登录时间获取器 - 格式化:年-月-日 时:分:秒
  79. * @param $value
  80. * @return string
  81. * @author Tab
  82. * @date 2021/7/13 11:35
  83. */
  84. public function getLoginTimeAttr($value)
  85. {
  86. return empty($value) ? '' : date('Y-m-d H:i:s', $value);
  87. }
  88. /**
  89. * @notes 头像获取器 - 头像路径添加域名
  90. * @param $value
  91. * @return string
  92. * @author Tab
  93. * @date 2021/7/13 11:35
  94. */
  95. public function getAvatarAttr($value)
  96. {
  97. return empty($value) ? FileService::getFileUrl(config('project.default_image.admin_avatar')) : FileService::getFileUrl(trim($value, '/'));
  98. }
  99. }