114 lines
2.4 KiB
PHP
114 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use AsLong\UserAccount\Traits\UserHasAccount;
|
|
use AsLong\UserRelation\Traits\UserHasRelations;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Overtrue\LaravelFollow\Traits\CanBeFavorited;
|
|
use Overtrue\LaravelFollow\Traits\CanFavorite;
|
|
use RuLong\Identity\Traits\UserHasIdentity;
|
|
use Tymon\JWTAuth\Contracts\JWTSubject;
|
|
|
|
class User extends Authenticatable implements JWTSubject
|
|
{
|
|
use Notifiable, UserHasAccount, UserHasRelations, UserHasIdentity, CanFavorite, CanBeFavorited;
|
|
|
|
protected $guarded = [];
|
|
|
|
protected $hidden = [];
|
|
|
|
/**
|
|
* 应被转换为日期的属性。
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $dates = [
|
|
'created_at',
|
|
'updated_at',
|
|
'vipd_at',
|
|
'vip_end_at',
|
|
];
|
|
|
|
public static function boot()
|
|
{
|
|
parent::boot();
|
|
self::created(function ($model) {
|
|
$model->info()->create();
|
|
});
|
|
}
|
|
|
|
public function getJWTIdentifier()
|
|
{
|
|
return $this->getKey();
|
|
}
|
|
|
|
public function getJWTCustomClaims()
|
|
{
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* 修改支付密码,留空则不修改
|
|
* @param void
|
|
*/
|
|
protected function setPasswordAttribute($password)
|
|
{
|
|
if ($password) {
|
|
$this->attributes['password'] = bcrypt($password);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 我的资料
|
|
* @Author:<C.Jason>
|
|
* @Date:2019-04-26T11:11:45+0800
|
|
* @return [type] [description]
|
|
*/
|
|
public function info()
|
|
{
|
|
return $this->hasOne(UserInfo::class)->withDefault();
|
|
}
|
|
|
|
/**
|
|
* 我的订单
|
|
* @Author:<C.Jason>
|
|
* @Date:2019-04-26T11:11:39+0800
|
|
* @return [type] [description]
|
|
*/
|
|
public function orders()
|
|
{
|
|
return $this->hasMany(Order::class);
|
|
}
|
|
|
|
/**
|
|
* 提现记录
|
|
* @return [type] [description]
|
|
*/
|
|
public function withdraws()
|
|
{
|
|
return $this->hasMany(Withdraw::class);
|
|
}
|
|
|
|
public function needBuy()
|
|
{
|
|
$identity_id = $this->identity->identity_id;
|
|
|
|
if ($identity_id == 0) {
|
|
return true;
|
|
}
|
|
|
|
if ($identity_id == 1 && empty($this->vip_end_at)) {
|
|
return true;
|
|
}
|
|
|
|
if ($identity_id == 1 && $this->vip_end_at->timestamp < time()) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
}
|