86 lines
1.9 KiB
PHP
86 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
|
|
class PrintPlugin extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
protected $fillable = [
|
|
'code',
|
|
'name',
|
|
'platform',
|
|
'version',
|
|
'download_url',
|
|
'md5',
|
|
'file_size',
|
|
'changelog',
|
|
'min_erp_version',
|
|
'status',
|
|
'install_type',
|
|
'config',
|
|
'published_at',
|
|
];
|
|
|
|
protected $casts = [
|
|
'config' => 'array',
|
|
'file_size' => 'integer',
|
|
'published_at' => 'datetime',
|
|
];
|
|
|
|
/**
|
|
* 版本历史
|
|
*/
|
|
public function versions(): HasMany
|
|
{
|
|
return $this->hasMany(PrintPluginVersion::class, 'plugin_id');
|
|
}
|
|
|
|
/**
|
|
* 安装记录
|
|
*/
|
|
public function installations(): HasMany
|
|
{
|
|
return $this->hasMany(PrintPluginInstallation::class, 'plugin_id');
|
|
}
|
|
|
|
/**
|
|
* 获取最新版本
|
|
*/
|
|
public function getLatestVersionAttribute(): ?string
|
|
{
|
|
return $this->versions()->max('version');
|
|
}
|
|
|
|
/**
|
|
* 检查是否有新版本
|
|
*/
|
|
public function hasNewVersion(string $currentVersion): bool
|
|
{
|
|
return version_compare($this->version, $currentVersion) > 0;
|
|
}
|
|
|
|
/**
|
|
* 平台名称映射
|
|
*/
|
|
public static function getPlatformName(string $code): string
|
|
{
|
|
$platforms = [
|
|
'cainiao' => '菜鸟打印',
|
|
'pdd' => '拼多多',
|
|
'douyin' => '抖音小店',
|
|
'kuaishou' => '快手小店',
|
|
'kuaimai' => '快麦打印机',
|
|
'feiyun' => '飞鹅打印机',
|
|
'yilianyun' => '易联云',
|
|
'pos' => 'POS小票',
|
|
];
|
|
return $platforms[$code] ?? $code;
|
|
}
|
|
}
|