'score_cate', 'name' => '考核指标', 'children' => [ ['key' => 'score_cate_1', 'name' => '政治忠诚'], ['key' => 'score_cate_2', 'name' => '政治定力'], ['key' => 'score_cate_3', 'name' => '政治担当'], ['key' => 'score_cate_4', 'name' => '政治能力'], ['key' => 'score_cate_5', 'name' => '政治自律'], ]], ['key' => 'banner', 'name' => '广告位', 'children' => [ ['key' => 'banner_1', 'name' => '首页广告'], ['key' => 'banner_2', 'name' => '考核填报'], ['key' => 'banner_3', 'name' => '首页导航'], ]], ['key' => 'category', 'name' => '文章分类', 'children' => [ ['key' => 'category_1', 'name' => '共性指标'], ['key' => 'category_2', 'name' => '进阶指标'], ]] ]; $this->createByTree($list); $this->createBanner(); } protected function createByTree($list, $parent = null) { foreach ($list as $index => $item) { $params = Arr::except($item, ['children']); $params['sort'] = $index + 1; $params['parent_id'] = $parent ? $parent->id : 0; $params['key'] = data_get($item, 'key', data_get($parent, 'key') . '_' . $params['sort']); $model = Keyword::create(KeywordService::make()->resloveData($params)); if ($children = data_get($item, 'children')) { $this->createByTree($children, $model); } } } protected function createBanner() { $now = now(); Banner::truncate(); $banners = [ 'banner_1' => [ ['picture' => 'http://www.gzcsxy.cn/ewebeditor/uploadimages/WebLink/20231017160751707-767.jpg'] ], 'banner_2' => [ ['picture' => 'http://www.gzcsxy.cn/ewebeditor/uploadimages/WebLink/20221027123658712-869.jpg'] ], 'banner_3' => [ ['title' => '共性指标', 'picture' => url('images/form-active.png'), 'link_config' => ['target_type' => TargetType::App, 'target_url' => '/pages/article/detail?type=common']], ['title' => '进阶指标', 'picture' => url('images/form-active.png'), 'link_config' => ['target_type' => TargetType::App, 'target_url' => '/pages/article/detail?type=cate']], ['title' => '书记信箱', 'picture' => url('images/form-active.png'), 'link_config' => ['target_type' => TargetType::App, 'target_url' => '/pages/feedback/add']], ] ]; foreach ($banners as $key => $values) { $place = Keyword::where('key', $key)->first(); foreach ($values as $index => $v) { BannerService::make()->store(array_merge([ 'title' => $place->name, 'place_id' => $place->id, 'published_at' => $now, 'sort' => $index + 1, ], $v)); } } } }