User.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 系统员工表
  7. */
  8. class User extends Model
  9. {
  10. /**
  11. * The table associated with the model.
  12. *
  13. * @var string
  14. */
  15. protected $table = 'users';
  16. /**
  17. * The primary key associated with the table.
  18. *
  19. * @var string
  20. */
  21. protected $primaryKey = 'id';
  22. /**
  23. * Indicates if the model should be timestamped.
  24. *
  25. * @var bool
  26. */
  27. public $timestamps = true;
  28. /**
  29. * 可以被批量赋值的属性。
  30. *
  31. * @var array
  32. */
  33. protected $fillable = ['id','name','phone','password','encrypt','api_token','roles_id','status','is_del'];
  34. private $statusEnum=[
  35. 1=>'正常',
  36. 2=>'关闭',
  37. ];
  38. /**
  39. * 为数组 / JSON 序列化准备日期。
  40. *
  41. * @param DateTimeInterface $date
  42. * @return string
  43. */
  44. protected function serializeDate(DateTimeInterface $date)
  45. {
  46. return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
  47. }
  48. /**
  49. * 序列化数据字典
  50. */
  51. function initializeModel(){
  52. if($this->{'status'}!==null){
  53. $this->{'status_str'}=empty($this->statusEnum[$this->{'status'}])?'无':$this->statusEnum[$this->{'status'}];
  54. }
  55. }
  56. }