User.php 1.5 KB

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