jingcai-php/app/Model/Seller/Seller.php

115 lines
2.4 KiB
PHP
Executable File

<?php
namespace App\Model\Seller;
use App\Enums\BoolEnum;
use App\Enums\SellerLevel;
use App\Model\Customer\Customer;
use App\Model\Traits\PasswordTrait;
use App\Model\Traits\TableFieldTrait;
use App\Model\Traits\TableTrait;
use App\Model\WechatUser;
use App\Utils\Helps;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class Seller extends Authenticatable implements JWTSubject
{
use Notifiable;
use TableTrait;
use TableFieldTrait;
use PasswordTrait;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token','password_pay',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected $appends = [
'avatar_url'
];
// Rest omitted for brevity
/**
* 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 [];
}
public function shop()
{
return $this->hasOne(Shop::class, 'id', 'shop_id');
}
public function wechatUser()
{
return $this->hasOne(WechatUser::class, 'id', 'wechat_user_id');
}
public function agentNum()
{
return Customer::where('agent', BoolEnum::YES)->where('shop_id', $this->shop_id)->count();
}
//修改日期时间格式
protected function serializeDate(\DateTimeInterface $date)
{
return $date->format('Y-m-d H:i:s');
}
public function getAvatarUrlAttribute()
{
$avatar = $this->avatar;
if (!$avatar) {
return '';
}
return Helps::fullUrl($avatar);
}
public function enablePlatformAgent()
{
return $this->platform_agent == BoolEnum::YES;
}
public function isAdmin()
{
return $this->level == SellerLevel::MASTER;
}
}