UserInfo.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. namespace App\Module\User\Models;
  3. use App\Module\User\Enums\PHONE_STATUS;
  4. use App\Module\Merchant\Model\Merchant;
  5. use App\Module\User\Enums\STATUS;
  6. use App\Module\User\Enums\STATUS2;
  7. use App\Module\User\Models\Events\UserInfoSaved;
  8. use App\Module\User\Models\Events\UserInfoUpdate;
  9. use UCore\ModelCore;
  10. use Illuminate\Database\Eloquent\Relations\HasOne;
  11. use Illuminate\Database\Eloquent\SoftDeletes;
  12. /**
  13. * 用户信息
  14. *
  15. * field start
  16. * @property int $user_id 用户ID
  17. * @property \App\Module\User\Enums\STATUS $status 状态
  18. * @property string $google2fa_secret
  19. * @property string $nickname 昵称
  20. * @property string $avatar 头像
  21. * @property \Carbon\Carbon $created_at
  22. * @property \Carbon\Carbon $updated_at
  23. * @property \Carbon\Carbon $deleted_at
  24. * @property string $wx_id 微信号
  25. * @property \Carbon\Carbon $last_login_time 最后登录时间
  26. * @property \Carbon\Carbon $last_activity_time 最后活动时间
  27. * field end
  28. *
  29. * Class UserInfo
  30. * @property UserPhone $user_phone
  31. */
  32. class UserInfo extends \UCore\ModelCore
  33. {
  34. use SoftDeletes;
  35. protected $primaryKey = 'user_id';
  36. protected $casts = [
  37. 'status' => STATUS::class,
  38. 'last_login_time' => 'datetime',
  39. 'last_activity_time' => 'datetime',
  40. ];
  41. protected $dispatchesEvents = [
  42. 'updated' => UserInfoUpdate::class,
  43. 'saved' => UserInfoSaved::class
  44. ];
  45. // attrlist start
  46. protected $fillable = [
  47. 'user_id',
  48. 'status',
  49. 'google2fa_secret',
  50. 'nickname',
  51. 'avatar',
  52. 'wx_id',
  53. 'last_login_time',
  54. 'last_activity_time',
  55. ];
  56. // attrlist end
  57. public function user(): HasOne
  58. {
  59. return $this->hasOne(User::class, 'id', 'user_id');
  60. }
  61. public function user_phone(): HasOne
  62. {
  63. return $this->hasOne(UserPhone::class, 'user_id', 'user_id')->where('status', '=', PHONE_STATUS::BIND);
  64. }
  65. }