erp/app/Models/ShopShip.php
2023-07-27 21:28:00 +08:00

40 lines
811 B
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ShopShip extends Model
{
protected $guarded = [];
protected function shop()
{
return $this->belongsTo(Shop::class, 'shop_id', 'id');
}
public function getStatusAttribute($value)
{
$map = [
0 => '未授权',
1 => '已授权',
3 => '停用',
];
if (1 === (int)$value && ($this->attributes['expires_at'] - time()) / 3600 <= 72) {
return '重新授权';
}
return $map[$value];
}
public function getExpiresAtAttribute($value)
{
return $value ? date('Y-m-d H:i:s', $value) : '';
}
public function senders()
{
return $this->hasMany(ShopSender::class, 'shop_ship_id');
}
}