SysUser.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace app\model;
  3. use support\Model;
  4. class SysUser extends Model
  5. {
  6. protected $table = 'sys_user';
  7. protected $primaryKey = 'user_id';
  8. public const UPDATED_AT = null;
  9. protected $keyType = 'string';
  10. public function getUserAddtimesAttribute($value)
  11. {
  12. return date('Y-m-d H:i:s', $value);
  13. }
  14. public function role()
  15. {
  16. return $this->hasOne(SysRole::class, 'role_id', 'join_user_role_id')
  17. ->select('role_id', 'role_name');
  18. }
  19. public function dept()
  20. {
  21. return $this->hasOne(SysDept::class, 'dept_id', 'join_user_dept_id')
  22. ->select('dept_id', 'dept_name');
  23. }
  24. /* 按登录名查找用户 */
  25. public static function findByLoginName($name)
  26. {
  27. return self::where('user_login_name', $name)->first();
  28. }
  29. /**
  30. * @Desc 修改用户状态
  31. * @Author Gorden
  32. * @Date 2024/3/12 13:20
  33. *
  34. * @param $id
  35. * @param $data
  36. * @return int
  37. */
  38. public static function updateStatus($id, $data)
  39. {
  40. return self::where('user_id', $id)->update($data);
  41. }
  42. }