first version
This commit is contained in:
@@ -2,17 +2,31 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
/**
|
||||
* APP 用户模型
|
||||
* APP 用户模型(小程序端:门店 / 供应商用户)
|
||||
*/
|
||||
class UserModel extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
/** 用户类型:待绑定(手机号未匹配到门店/供应商,需后台人工绑定) */
|
||||
public const TYPE_PENDING = 0;
|
||||
/** 用户类型:门店 */
|
||||
public const TYPE_STORE = 1;
|
||||
/** 用户类型:供应商 */
|
||||
public const TYPE_SUPPLIER = 2;
|
||||
|
||||
/** 状态:停用 */
|
||||
public const STATUS_DISABLED = 0;
|
||||
/** 状态:正常 */
|
||||
public const STATUS_NORMAL = 1;
|
||||
|
||||
protected $table = 'user';
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
@@ -23,10 +37,60 @@ class UserModel extends Authenticatable
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'mobile',
|
||||
'username',
|
||||
'email',
|
||||
'password',
|
||||
'nickname',
|
||||
'openid',
|
||||
'unionid',
|
||||
'phone',
|
||||
'avatar',
|
||||
'type',
|
||||
'store_id',
|
||||
'supplier_id',
|
||||
'status',
|
||||
'last_login_at',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
'last_login_at' => 'datetime',
|
||||
'type' => 'integer',
|
||||
'store_id' => 'integer',
|
||||
'supplier_id' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联门店(type=1 时有效)
|
||||
*/
|
||||
public function store(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(StoreModel::class, 'store_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联供应商(type=2 时有效)
|
||||
*/
|
||||
public function supplier(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(SupplierModel::class, 'supplier_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 用户通知
|
||||
*/
|
||||
public function notices(): HasMany
|
||||
{
|
||||
return $this->hasMany(NoticeModel::class, 'user_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否已绑定业务主体(门店或供应商)
|
||||
*/
|
||||
public function isBound(): bool
|
||||
{
|
||||
return $this->type === self::TYPE_STORE && $this->store_id > 0
|
||||
|| $this->type === self::TYPE_SUPPLIER && $this->supplier_id > 0;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user