You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.6 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Database\Seeders;
use App\Models\DictItem;
use App\Models\DictType;
use App\Support\News\UniversityNewsCategory;
use Illuminate\Database\Seeder;
/**
* 资讯分类下拉:政策信息 / 行业动态 / 活动通知 / 高校要闻。
*/
class NewsDictionarySeeder extends Seeder
{
public function run(): void
{
$type = DictType::query()->updateOrCreate(
['code' => 'news_category'],
[
'name' => '资讯分类',
'remark' => '资讯管理-分类下拉',
'status' => 1,
'sort' => 51,
]
);
foreach ([
['label' => '政策信息', 'value' => 'policy', 'sort' => 10],
['label' => '行业动态', 'value' => 'industry', 'sort' => 20],
['label' => '活动通知', 'value' => 'activity_notice', 'sort' => 30],
] as $row) {
DictItem::query()->updateOrCreate(
['dict_type_id' => $type->id, 'value' => $row['value']],
['label' => $row['label'], 'sort' => $row['sort'], 'status' => 1]
);
}
// 先合并历史重复项,再按 value 唯一维护「高校要闻」(爬虫地址绑定沿用原 ID
UniversityNewsCategory::consolidateDuplicates();
DictItem::query()->updateOrCreate(
['dict_type_id' => $type->id, 'value' => UniversityNewsCategory::VALUE],
[
'label' => UniversityNewsCategory::LABEL,
'sort' => 40,
'status' => 1,
]
);
UniversityNewsCategory::consolidateDuplicates();
}
}