User.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Models\User;
  3. use App\Base\BaseModel;
  4. use App\Models\Auth\AdminGroup;
  5. use App\Modules\Mini\Services\AuthService;
  6. use Illuminate\Auth\Authenticatable;
  7. use Illuminate\Support\Arr;
  8. /**
  9. * App\Models\User
  10. *
  11. * @property int $id
  12. * @property string $phone
  13. * @property string $password
  14. * @property string $email
  15. * @property int $status 0 禁用 1启用
  16. * @property int $group_id
  17. * @property array $extra 糊屎字段
  18. * @property \Illuminate\Support\Carbon|null $created_at
  19. * @property \Illuminate\Support\Carbon|null $updated_at
  20. * @property-read AdminGroup|null $group
  21. * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
  22. * @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
  23. * @method static \Illuminate\Database\Eloquent\Builder|User query()
  24. * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|User whereExtra($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|User whereGroupId($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|User wherePhone($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|User whereStatus($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
  33. * @mixin \Eloquent
  34. * @property-read \App\Models\User\UserCompany|null $company
  35. * @property string $openid 微信openid
  36. * @method static \Illuminate\Database\Eloquent\Builder|User whereOpenid($value)
  37. * @property string $name 用户昵称
  38. * @method static \Illuminate\Database\Eloquent\Builder|User whereName($value)
  39. * @property-read mixed $avatar
  40. */
  41. class User extends BaseModel implements \Illuminate\Contracts\Auth\Authenticatable
  42. {
  43. use Authenticatable;
  44. protected $table = "user";
  45. const STATUS_OK = 1;
  46. const STATUS_STOP = 2;
  47. protected $casts = [
  48. "extra" => "array",
  49. ];
  50. public function checkPassword($password): bool
  51. {
  52. return \Hash::check($password, $this->password);
  53. }
  54. public function hashPassword($password)
  55. {
  56. return \Hash::make($password);
  57. }
  58. public function group()
  59. {
  60. return $this->belongsTo(AdminGroup::class, "group_id", "id");
  61. }
  62. public function company()
  63. {
  64. return $this->hasOne(UserCompany::class, "user_id", "id");
  65. }
  66. public function getAvatarAttribute()
  67. {
  68. return Arr::get($this->extra, "wechat.avatar", "");
  69. }
  70. public function format()
  71. {
  72. return [
  73. "token" => app(AuthService::class)->encryptToken($this->id),
  74. "name" => $this->name,
  75. "phone" => $this->phone,
  76. "email" => $this->email,
  77. ];
  78. }
  79. }