User.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Carbon\Carbon;
  5. use Illuminate\Database\Eloquent\Model;
  6. class User extends Model
  7. {
  8. //
  9. use ModelHelpers;
  10. protected $table = "users";
  11. // protected $fillable = ['status', 'mobile', 'is_bind_mobile', 'is_card_certified', 'is_match_ride_age', 'card_id', 'remark'];
  12. protected $guarded = [];
  13. // 注册来源
  14. const REGISTER_SOURCE_WEAPP = 'weapp';
  15. public static $registerSourceMaps = [
  16. self::REGISTER_SOURCE_WEAPP => '微信小程序'
  17. ];
  18. //账号状态
  19. const STATUS_OK = 1;
  20. const STATUS_PAUSE = 0;
  21. public static $statusMaps = [
  22. self::STATUS_PAUSE => '暂停使用',
  23. self::STATUS_OK => '正常'
  24. ];
  25. // 认证状态
  26. const CARD_OK = 1;
  27. const CARD_NO = 0;
  28. public static $cardMaps = [
  29. self::CARD_OK => '已实名认证',
  30. self::CARD_NO => '未实名认证'
  31. ];
  32. // 押金状态
  33. const DEPOSIT_OK = 1;
  34. const DEPOSIT_NO = 0;
  35. public static $depositMaps = [
  36. self::DEPOSIT_OK => '已缴纳押金',
  37. self::DEPOSIT_NO => '未缴纳押金'
  38. ];
  39. const DEPOSIT_MONEY = 1;
  40. const DEPOSIT_CARD = 2;
  41. const DEPOSIT_STUDENT = 3;
  42. const DEPOSIT_TYPE_NO = 0;
  43. public static $depositTypeMaps = [
  44. self::DEPOSIT_TYPE_NO => '没有缴纳押金',
  45. self::DEPOSIT_MONEY => '缴纳押金',
  46. self::DEPOSIT_CARD => '免押金卡',
  47. self::DEPOSIT_STUDENT => '师生认证',
  48. ];
  49. // 是否到了骑车年龄的状态
  50. const RIDE_BIKE_AGE_OK = 1;
  51. const RIDE_BIKE_AGE_NO = 0;
  52. public static $rideBikeAgeMaps = [
  53. self::RIDE_BIKE_AGE_OK => '已到骑车的年龄',
  54. self::RIDE_BIKE_AGE_NO => '未到骑车的年龄'
  55. ];
  56. // 手机号绑定状态
  57. const BIND_MOBILE_OK = 1;
  58. const BIND_MOBILE_NO = 0;
  59. public static $bingMobileMaps = [
  60. self::BIND_MOBILE_OK => '已绑定收手机号',
  61. self::BIND_MOBILE_NO => '未绑定手机号'
  62. ];
  63. // 用户授权状态
  64. const REGISTER_OK = 1;
  65. const REGISTER_NO = 0;
  66. public static $registerMaps = [
  67. self::REGISTER_OK => '已授权',
  68. self::REGISTER_NO => '未授权'
  69. ];
  70. // 用户授权状态
  71. const IS_STUDENT_OK = 1;
  72. const IS_STUDENT_NO = 0;
  73. public static $isStudentMaps = [
  74. self::IS_STUDENT_OK => '学生',
  75. self::IS_STUDENT_NO => '不是'
  76. ];
  77. public function areas()
  78. {
  79. return $this->belongsTo(Area::class, 'register_area_id', 'id');
  80. }
  81. public function auth()
  82. {
  83. return $this->hasOne(Auth::class)->where('type', Auth::TYPE_WEAPP);
  84. }
  85. public function userPhone()
  86. {
  87. return $this->hasOne(UserPhoneDetail::class);
  88. }
  89. public function getIsDepositAttribute($value)
  90. {
  91. if ((int)$this->deposit_type === self::DEPOSIT_CARD && (int)$value === self::DEPOSIT_OK) {
  92. $deposit_expire_time = Carbon::parse($this->deposit_expire_time);
  93. if (Carbon::now()->gt($deposit_expire_time)) {
  94. //判断第一个日期是否比第二个日期大
  95. $this->updateDeposit($this->id);
  96. $this->save();
  97. return self::DEPOSIT_NO;
  98. }
  99. }
  100. return $value;
  101. }
  102. public function updateDeposit($user_id)
  103. {
  104. self::query()->where('id', $user_id)->update(['is_deposit' => User::DEPOSIT_NO, 'is_student' => self::IS_STUDENT_NO, 'deposit_type' => User::DEPOSIT_TYPE_NO]);
  105. }
  106. }