90 lines
2.1 KiB
PHP
90 lines
2.1 KiB
PHP
<?php
|
||
|
||
namespace App\Models;
|
||
|
||
use Illuminate\Database\Eloquent\Model;
|
||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||
|
||
class Solution extends Model
|
||
{
|
||
use SoftDeletes;
|
||
|
||
protected $fillable = [
|
||
'name',
|
||
'slug',
|
||
'power_segment',
|
||
'application',
|
||
'chip_platform',
|
||
'power',
|
||
'summary',
|
||
'advantages',
|
||
'description',
|
||
'cover',
|
||
'status',
|
||
'sort',
|
||
'seo_title',
|
||
'seo_description',
|
||
];
|
||
|
||
public const POWER_SEGMENTS = [
|
||
'lt30' => '30W 以下',
|
||
'30-65' => '30–65W',
|
||
'65-100' => '65–100W',
|
||
'gt100' => '100W 以上',
|
||
];
|
||
|
||
public const APPLICATIONS = [
|
||
'charger' => '充电器',
|
||
'powerbank' => '移动电源',
|
||
'car' => '车载充电',
|
||
'dock' => '扩展坞 / 多口排插',
|
||
];
|
||
|
||
public const CHIP_PLATFORMS = [
|
||
'protocol' => '协议芯片',
|
||
'soc' => '高集成 SoC',
|
||
'rectifier' => '同步整流',
|
||
];
|
||
|
||
public function scopePublished($query)
|
||
{
|
||
return $query->where('status', 'published')->orderBy('sort')->orderBy('name');
|
||
}
|
||
|
||
public function powerSegmentLabel(): string
|
||
{
|
||
return self::POWER_SEGMENTS[$this->power_segment] ?? $this->power_segment ?? '—';
|
||
}
|
||
|
||
public function applicationLabel(): string
|
||
{
|
||
return self::APPLICATIONS[$this->application] ?? $this->application ?? '—';
|
||
}
|
||
|
||
public function chipPlatformLabel(): string
|
||
{
|
||
return self::CHIP_PLATFORMS[$this->chip_platform] ?? $this->chip_platform ?? '—';
|
||
}
|
||
|
||
public function advantagesList(): array
|
||
{
|
||
if (! $this->advantages) {
|
||
return [];
|
||
}
|
||
return collect(explode("\n", $this->advantages))
|
||
->map(fn ($line) => trim($line))
|
||
->filter()
|
||
->all();
|
||
}
|
||
|
||
public function seoTitle(): string
|
||
{
|
||
return $this->seo_title ?: ($this->name . ' - 深圳市云创芯电子有限公司');
|
||
}
|
||
|
||
public function seoDescription(): string
|
||
{
|
||
return $this->seo_description ?: ($this->summary ?: $this->name);
|
||
}
|
||
}
|