123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- namespace App\Models;
- use Carbon\Carbon;
- use Illuminate\Auth\Authenticatable;
- use Laravel\Lumen\Auth\Authorizable;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
- use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract;
- use Tymon\JWTAuth\Contracts\JWTSubject;
- class User extends Model implements AuthenticatableContract, AuthorizableContract, JWTSubject
- {
- use Authenticatable, Authorizable;
- /**
- * The attributes that are mass assignable.
- *
- * @var array
- */
- // protected $fillable = [
- // 'name', 'id'
- // ];
- protected $guarded = [];
- /**
- * The attributes excluded from the model's JSON form.
- *
- * @var array
- */
- protected $hidden = [
- 'password',
- ];
- /**
- * Get the identifier that will be stored in the subject claim of the JWT.
- *
- * @return mixed
- */
- public function getJWTIdentifier()
- {
- return $this->getKey();
- }
- /**
- * Return a key value array, containing any custom claims to be added to the JWT.
- *
- * @return array
- */
- public function getJWTCustomClaims()
- {
- return ['role' => 'user'];
- }
- // 注册来源
- const REGISTER_SOURCE_WEAPP = 'weapp';
- const REGISTER_SOURCE_MOBILE = 'mobile';
- public static $registerSourceMaps = [
- self::REGISTER_SOURCE_WEAPP => '微信小程序',
- self::REGISTER_SOURCE_MOBILE => '手机号',
- ];
- //账号状态
- const STATUS_OK = 1;
- const STATUS_PAUSE = 0;
- public static $statusMaps = [
- self::STATUS_PAUSE => '暂停使用',
- self::STATUS_OK => '正常'
- ];
- // 认证状态
- const CARD_OK = 1;
- const CARD_NO = 0;
- public static $cardMaps = [
- self::CARD_OK => '已实名认证',
- self::CARD_NO => '未实名认证'
- ];
- // 押金状态
- const DEPOSIT_OK = 1;
- const DEPOSIT_NO = 0;
- public static $depositMaps = [
- self::DEPOSIT_OK => '已缴纳押金',
- self::DEPOSIT_NO => '未缴纳押金',
- ];
- const DEPOSIT_MONEY = 1;
- const DEPOSIT_CARD = 2;
- const DEPOSIT_TYPE_NO = 0;
- public static $depositTypeMaps = [
- self::DEPOSIT_TYPE_NO => '没有缴纳押金',
- self::DEPOSIT_MONEY => '缴纳押金',
- self::DEPOSIT_CARD => '免押金卡',
- ];
- // 是否到了骑车年龄的状态
- const RIDE_BIKE_AGE_OK = 1;
- const RIDE_BIKE_AGE_NO = 0;
- public static $rideBikeAgeMaps = [
- self::RIDE_BIKE_AGE_OK => '已到骑车的年龄',
- self::RIDE_BIKE_AGE_NO => '未到骑车的年龄'
- ];
- // 手机号绑定状态
- const BIND_MOBILE_OK = 1;
- const BIND_MOBILE_NO = 0;
- public static $bingMobileMaps = [
- self::BIND_MOBILE_OK => '已绑定收手机号',
- self::BIND_MOBILE_NO => '未绑定手机号'
- ];
- // 用户授权状态
- const REGISTER_OK = 1;
- const REGISTER_NO = 0;
- public static $registerMaps = [
- self::REGISTER_OK => '已授权',
- self::REGISTER_NO => '未授权'
- ];
- public function auth()
- {
- return $this->hasOne(Auth::class)->where('type', Auth::TYPE_WEAPP);
- }
- public function userPhoneDetail()
- {
- return $this->hasOne(UserPhoneDetail::class);
- }
- // 定义是否缴纳押金访问器 更新免押金卡过期
- public function getIsDepositAttribute($value)
- {
- if ((int)$this->deposit_type === self::DEPOSIT_CARD && (int)$value === self::DEPOSIT_OK) {
- $deposit_expire_time = Carbon::parse($this->deposit_expire_time);
- if (Carbon::now()->gt($deposit_expire_time)) {
- //判断第一个日期是否比第二个日期大
- $this->updateDeposit($this->id);
- $this->save();
- return self::DEPOSIT_NO;
- }
- }
- return $value;
- }
- public function updateDeposit($user_id)
- {
- self::query()->where('id', $user_id)->update(['is_deposit' => User::DEPOSIT_NO, 'deposit_type' => User::DEPOSIT_TYPE_NO]);
- }
- }
|