53 lines
1.0 KiB
PHP
53 lines
1.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class ShopAuth extends Model
|
|
{
|
|
protected $table = 'shop_auths';
|
|
|
|
protected $fillable = [
|
|
'shop_name',
|
|
'platform',
|
|
'account',
|
|
'access_token',
|
|
'refresh_token',
|
|
'expires_at',
|
|
'status',
|
|
'remark',
|
|
];
|
|
|
|
protected $casts = [
|
|
'expires_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 获取该店铺的平台订单
|
|
*/
|
|
public function platformOrders()
|
|
{
|
|
return $this->hasMany(PlatformOrder::class, 'platform_shop_id', 'id');
|
|
}
|
|
|
|
/**
|
|
* 判断授权是否过期
|
|
*/
|
|
public function isExpired(): bool
|
|
{
|
|
return $this->expires_at && $this->expires_at->isPast();
|
|
}
|
|
|
|
/**
|
|
* 获取有效的 access token
|
|
*/
|
|
public function getValidToken(): ?string
|
|
{
|
|
if ($this->isExpired()) {
|
|
// 可以在这里添加刷新 token 的逻辑
|
|
return null;
|
|
}
|
|
return $this->access_token;
|
|
}
|
|
} |