更新代码
This commit is contained in:
241
app/User.php
Normal file
241
app/User.php
Normal file
@@ -0,0 +1,241 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use App\Models\Agency;
|
||||
use App\Models\Cart;
|
||||
use App\Models\Cdkey;
|
||||
use App\Models\Favorite;
|
||||
use App\Models\KeysApply;
|
||||
use App\Models\Seller;
|
||||
use App\Models\UserBaby;
|
||||
use App\Models\UserInfo;
|
||||
use App\Models\UserLogin;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use RuLong\Area\Traits\UserHasAddress;
|
||||
use RuLong\Coupon\Models\CouponUserLog;
|
||||
use RuLong\Identity\Traits\UserHasIdentity;
|
||||
use RuLong\Order\Models\Order;
|
||||
use RuLong\UserAccount\Traits\UserHasAccount;
|
||||
use RuLong\UserRelation\Traits\UserHasRelations;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use Notifiable, SoftDeletes, UserHasAccount, UserHasRelations, UserHasIdentity, UserHasAddress;
|
||||
|
||||
protected $guarded = [];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected $dates = [
|
||||
'deleted_at',
|
||||
];
|
||||
|
||||
protected $info = [];
|
||||
|
||||
public static function boot()
|
||||
{
|
||||
parent::boot();
|
||||
|
||||
self::saved(function ($model) {
|
||||
if (is_array($model->info) && !empty($model->info)) {
|
||||
$model->info()->updateOrCreate(['user_id' => $model->id], $model->info);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 管理的商户/或者组织
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-10T15:30:46+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function seller()
|
||||
{
|
||||
return $this->hasOne(Seller::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是代理
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-10T15:30:46+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function agency()
|
||||
{
|
||||
return $this->hasOne(Agency::class);
|
||||
}
|
||||
|
||||
/**
|
||||
*所属组织
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-10T15:30:46+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function organ()
|
||||
{
|
||||
return $this->belongsTo(Seller::class, 'seller_id', 'id')->where('type', 'organ')->withDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改用户资料
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-11-07T13:30:14+0800
|
||||
* @param array $info UserInfo fields
|
||||
*/
|
||||
protected function setInfoAttribute($info)
|
||||
{
|
||||
$this->info = $info;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码,留空则不修改
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-31T15:04:59+0800
|
||||
* @param void
|
||||
*/
|
||||
protected function setPasswordAttribute($password)
|
||||
{
|
||||
if ($password) {
|
||||
$this->attributes['password'] = bcrypt($password);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改支付密码,留空则不修改
|
||||
* @Author:<C.Jason>
|
||||
* @Date:2018-10-31T15:04:59+0800
|
||||
* @param void
|
||||
*/
|
||||
protected function setPayPassAttribute($password)
|
||||
{
|
||||
if ($password) {
|
||||
$this->attributes['paypass'] = md5($password);
|
||||
}
|
||||
}
|
||||
|
||||
public function info()
|
||||
{
|
||||
return $this->hasOne(UserInfo::class)->withDefault();
|
||||
}
|
||||
|
||||
public function logins()
|
||||
{
|
||||
return $this->hasMany(UserLogin::class);
|
||||
}
|
||||
|
||||
public function lastLogin()
|
||||
{
|
||||
return $this->hasOne(UserLogin::class)->orderBy('id', 'desc')->withDefault();
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否已经领取了会员赠品
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-26T13:17:44+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function getGiftOrderAttribute()
|
||||
{
|
||||
$vipOrder = Order::where('user_id', $this->id)->where('item_type', 'VIP_GIFT')->whereIn('state', ['PAID', 'DELIVER', 'DELIVERED', 'SIGNED', 'COMPLETED'])->count();
|
||||
return $vipOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* 以生成的激活码数量
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-27T12:06:25+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function keys()
|
||||
{
|
||||
return $this->hasMany(Cdkey::class, 'belong_uid', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 总裁申请的数量
|
||||
* @Author:<Leady>
|
||||
* @Date:2018-12-27T12:06:25+0800
|
||||
* @return [type] [description]
|
||||
*/
|
||||
public function keyapplies()
|
||||
{
|
||||
return $this->hasMany(KeysApply::class);
|
||||
}
|
||||
|
||||
//报名数量
|
||||
public function getCartNumAttribute()
|
||||
{
|
||||
return Cart::where('user_id', $this->id)->count() ?? 0;
|
||||
}
|
||||
|
||||
//是否是业务员
|
||||
public function getSalesmanTextAttribute()
|
||||
{
|
||||
return $this->is_salesman == 1 ? '是' : '否';
|
||||
}
|
||||
|
||||
public function cart()
|
||||
{
|
||||
return $this->hasMany(Cart::class);
|
||||
}
|
||||
|
||||
public function couponlog()
|
||||
{
|
||||
return $this->hasMany(CouponUserLog::class);
|
||||
}
|
||||
|
||||
//关联课程收藏
|
||||
public function lessonFavorite()
|
||||
{
|
||||
return $this->hasMany(Favorite::class)->where('item_type', 'App\Models\SellerLesson');
|
||||
}
|
||||
|
||||
//关联机构收藏
|
||||
public function sellerFavorite()
|
||||
{
|
||||
return $this->hasMany(Favorite::class)->where('item_type', 'App\Models\Seller');
|
||||
}
|
||||
|
||||
//关联机构收藏
|
||||
public function activityFavorite()
|
||||
{
|
||||
return $this->hasMany(Favorite::class)->where('item_type', 'App\Models\Activity');
|
||||
}
|
||||
|
||||
//报名数量
|
||||
public function getFavoriteNumAttribute()
|
||||
{
|
||||
return ($this->lessonFavorite()->count() + $this->sellerFavorite()->count() + $this->activityFavorite()->count()) ?? 0;
|
||||
}
|
||||
|
||||
public function babys()
|
||||
{
|
||||
return $this->hasOne(UserBaby::class, 'user_id');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user