wyyl/database/seeders/CategoriesSeeder.php

439 lines
15 KiB
PHP

<?php
/**
* CategoriesSeeder.php
*
* @copyright 2022 opencart.cn - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author Edward Yang <yangjin@opencart.cn>
* @created 2022-09-05 19:42:42
* @modified 2022-09-05 19:42:42
*/
namespace Database\Seeders;
use Beike\Models\Category;
use Beike\Models\CategoryPath;
use Illuminate\Database\Seeder;
use Beike\Models\CategoryDescription;
class CategoriesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$categories = $this->getCategories();
if ($categories) {
Category::query()->truncate();
foreach ($categories as $item) {
Category::query()->create($item);
}
}
$descriptions = $this->getCategoryDescriptions();
if ($descriptions) {
CategoryDescription::query()->truncate();
foreach ($descriptions as $item) {
CategoryDescription::query()->create($item);
}
}
$paths = $this->getCategoryPaths();
if ($paths) {
CategoryPath::query()->truncate();
foreach ($paths as $item) {
CategoryPath::query()->create($item);
}
}
// (new CategoryService())->repairCategories(0);
}
public function getCategories()
{
return [
["id" => 100001, "parent_id" => 0, "position" => 2, "active" => 1],
["id" => 100002, "parent_id" => 100001, "position" => 0, "active" => 1],
["id" => 100003, "parent_id" => 0, "position" => 1, "active" => 1],
["id" => 100004, "parent_id" => 100007, "position" => 0, "active" => 1],
["id" => 100005, "parent_id" => 0, "position" => 0, "active" => 1],
["id" => 100006, "parent_id" => 0, "position" => 0, "active" => 1],
["id" => 100007, "parent_id" => 0, "position" => 9, "active" => 1],
["id" => 100008, "parent_id" => 100006, "position" => 0, "active" => 1],
["id" => 100009, "parent_id" => 0, "position" => 0, "active" => 0],
["id" => 100010, "parent_id" => 0, "position" => 0, "active" => 1],
["id" => 100011, "parent_id" => 100010, "position" => 0, "active" => 1],
["id" => 100012, "parent_id" => 0, "position" => 0, "active" => 1],
["id" => 100013, "parent_id" => 100010, "position" => 0, "active" => 1],
["id" => 100014, "parent_id" => 100010, "position" => 0, "active" => 1],
["id" => 100015, "parent_id" => 100013, "position" => 0, "active" => 1],
["id" => 100016, "parent_id" => 100014, "position" => 0, "active" => 1],
["id" => 100017, "parent_id" => 100018, "position" => 0, "active" => 1],
["id" => 100018, "parent_id" => 0, "position" => 0, "active" => 1]
];
}
public function getCategoryDescriptions()
{
return [
[
"id" => 1,
"category_id" => 100002,
"locale" => "zh_cn",
"name" => "平板耳机",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 2,
"category_id" => 100002,
"locale" => "en",
"name" => "Pad",
"content" => "Pad",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 3,
"category_id" => 100003,
"locale" => "zh_cn",
"name" => "时尚潮流",
"content" => "时尚潮流",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 4,
"category_id" => 100003,
"locale" => "en",
"name" => "Fashion",
"content" => "Fashion",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 5,
"category_id" => 100004,
"locale" => "zh_cn",
"name" => "相机",
"content" => "相机",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 6,
"category_id" => 100004,
"locale" => "en",
"name" => "Camera",
"content" => "Camera",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 7,
"category_id" => 100005,
"locale" => "zh_cn",
"name" => "特价购买",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 8,
"category_id" => 100005,
"locale" => "en",
"name" => "Special",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 9,
"category_id" => 100006,
"locale" => "zh_cn",
"name" => "运动户外",
"content" => "运动户外",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 10,
"category_id" => 100006,
"locale" => "en",
"name" => "Sports",
"content" => "Sports",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 11,
"category_id" => 100007,
"locale" => "zh_cn",
"name" => "电子数码",
"content" => "电子数码",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 12,
"category_id" => 100007,
"locale" => "en",
"name" => "Electron",
"content" => "Electron",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 13,
"category_id" => 100008,
"locale" => "zh_cn",
"name" => "帐篷",
"content" => "帐篷",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 14,
"category_id" => 100008,
"locale" => "en",
"name" => "Tent",
"content" => "Tent",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 15,
"category_id" => 100010,
"locale" => "zh_cn",
"name" => "男装女装",
"content" => "男装女装",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 16,
"category_id" => 100010,
"locale" => "en",
"name" => "Clothes",
"content" => "Fashion",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 17,
"category_id" => 100011,
"locale" => "zh_cn",
"name" => "男装",
"content" => "男装",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 18,
"category_id" => 100011,
"locale" => "en",
"name" => "Men",
"content" => "Men",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 19,
"category_id" => 100012,
"locale" => "zh_cn",
"name" => "夏季促销",
"content" => "夏季促销",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 20,
"category_id" => 100012,
"locale" => "en",
"name" => "Summer Promotion",
"content" => "Summer promotion",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 21,
"category_id" => 100013,
"locale" => "zh_cn",
"name" => "上装",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 22,
"category_id" => 100013,
"locale" => "en",
"name" => "Top",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 23,
"category_id" => 100014,
"locale" => "zh_cn",
"name" => "下装",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 24,
"category_id" => 100014,
"locale" => "en",
"name" => "Bottom",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 25,
"category_id" => 100015,
"locale" => "zh_cn",
"name" => "棉衣",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 26,
"category_id" => 100015,
"locale" => "en",
"name" => "Cotton",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 27,
"category_id" => 100016,
"locale" => "zh_cn",
"name" => "棉毛裤",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 28,
"category_id" => 100016,
"locale" => "en",
"name" => "Cotton Pants",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 29,
"category_id" => 100017,
"locale" => "zh_cn",
"name" => "智能冰箱",
"content" => "智能冰箱",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 30,
"category_id" => 100017,
"locale" => "en",
"name" => "IceBox",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 31,
"category_id" => 100018,
"locale" => "zh_cn",
"name" => "家用电器",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
],
[
"id" => 32,
"category_id" => 100018,
"locale" => "en",
"name" => "Electric",
"content" => "",
"meta_title" => "",
"meta_description" => "",
"meta_keyword" => ""
]
];
}
public function getCategoryPaths()
{
return [
["id" => 183, "category_id" => 100003, "path_id" => 100003, "level" => 0],
["id" => 184, "category_id" => 100013, "path_id" => 100003, "level" => 0],
["id" => 185, "category_id" => 100013, "path_id" => 100013, "level" => 1],
["id" => 186, "category_id" => 100015, "path_id" => 100003, "level" => 0],
["id" => 187, "category_id" => 100015, "path_id" => 100013, "level" => 1],
["id" => 188, "category_id" => 100015, "path_id" => 100015, "level" => 2],
["id" => 189, "category_id" => 100014, "path_id" => 100003, "level" => 0],
["id" => 190, "category_id" => 100014, "path_id" => 100014, "level" => 1],
["id" => 191, "category_id" => 100016, "path_id" => 100003, "level" => 0],
["id" => 192, "category_id" => 100016, "path_id" => 100014, "level" => 1],
["id" => 193, "category_id" => 100016, "path_id" => 100016, "level" => 2],
["id" => 194, "category_id" => 100005, "path_id" => 100005, "level" => 0],
["id" => 195, "category_id" => 100006, "path_id" => 100006, "level" => 0],
["id" => 196, "category_id" => 100008, "path_id" => 100006, "level" => 0],
["id" => 197, "category_id" => 100008, "path_id" => 100008, "level" => 1],
["id" => 198, "category_id" => 100007, "path_id" => 100007, "level" => 0],
["id" => 199, "category_id" => 100002, "path_id" => 100007, "level" => 0],
["id" => 200, "category_id" => 100002, "path_id" => 100002, "level" => 1],
["id" => 201, "category_id" => 100004, "path_id" => 100007, "level" => 0],
["id" => 202, "category_id" => 100004, "path_id" => 100004, "level" => 1],
["id" => 204, "category_id" => 100010, "path_id" => 100010, "level" => 0],
["id" => 205, "category_id" => 100011, "path_id" => 100010, "level" => 0],
["id" => 206, "category_id" => 100011, "path_id" => 100011, "level" => 1],
["id" => 207, "category_id" => 100012, "path_id" => 100012, "level" => 0],
["id" => 208, "category_id" => 100018, "path_id" => 100018, "level" => 0],
["id" => 209, "category_id" => 100017, "path_id" => 100018, "level" => 0],
["id" => 210, "category_id" => 100017, "path_id" => 100017, "level" => 1]
];
}
}