重新导入数据

This commit is contained in:
2022-07-07 10:51:00 +08:00
parent 8b927799d6
commit 4a3a710385
2 changed files with 32 additions and 23 deletions

View File

@@ -18,7 +18,7 @@ class IndexController extends AdminController
public function grid()
{
$grid = new Grid(new Article);
$grid->model()->orderBy('id', 'desc');
$grid->model()->orderBy('created_at', 'desc');
$grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) {
$filter->like('title', '文章标题');

View File

@@ -21,6 +21,7 @@ class TestController extends Controller
//检查分类
public function checkCategory()
{
dd(1);
// $lists = Category::where('created_at','2020-06-03 15:57:55')->get();
// $i=1;
@@ -44,9 +45,9 @@ class TestController extends Controller
dd();
foreach ($diffids as $diffid) {
$info = DedeArctype::where('id', $diffid)
->where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->first();
->where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->first();
$data = $this->getData($info);
Category::create($data);
}
@@ -54,6 +55,9 @@ class TestController extends Controller
public function setCateArticle()
{
dd(1);
$article = [];
$lists = Category::where('content', '<>', '')->where('type', 'article')->get();
if ($lists->isEmpty()) {
@@ -87,27 +91,28 @@ class TestController extends Controller
public function checkArticle()
{
$lists = Article::where('category_id', 0)->get();
foreach ($lists as $list) {
$old = DedeArchive::find($list->oldid);
$cate = Category::where('oldid', $old->typeid)->first();
if (!$cate || !$old) {
dump($old);
dump($cate);
dd('出问题了');
}
$list->category_id = $cate->id;
$list->save();
}
dd();
dd(1);
// $lists = Article::where('category_id', 0)->get();
//
// foreach ($lists as $list) {
// $old = DedeArchive::find($list->oldid);
// $cate = Category::where('oldid', $old->typeid)->first();
// if (! $cate || ! $old) {
// dump($old);
// dump($cate);
// dd('出问题了');
// }
// $list->category_id = $cate->id;
// $list->save();
// }
// dd();
$articleids = Article::where('oldid', '>', 0)->pluck('oldid');
$oldids = DedeArchive::pluck('id');
$diffids = array_diff($oldids->toArray(), $articleids->toArray());
dump(count($articleids));
dump(count($oldids));
dump($diffids);
die();
dd();
$map = [
'id' => ['in', $diffids],
];
@@ -116,7 +121,7 @@ class TestController extends Controller
$data = [
'oldid' => $article->id,
'title' => $article->title,
'category_id' => $category->id ?? '0',
// 'category_id' => $category->id ?? '0',
'writer' => $article->writer,
'cover' => $article->litpic,
'source' => $article->source,
@@ -133,6 +138,8 @@ class TestController extends Controller
//导入文章
public function set_article()
{
dd(1);
$articles = Article::get();
if ($articles->count() > 4) {
dd('已经导入过数据');
@@ -159,7 +166,7 @@ class TestController extends Controller
];
$res = Article::create($data);
if (!$res) {
if (! $res) {
$error[] = $article->id;
} else {
$success[] = $article->id;
@@ -174,13 +181,15 @@ class TestController extends Controller
//导入分类
public function set_category()
{
dd(1);
$categorys = Category::get();
if ($categorys->count() > 1) {
dd('已经导入过数据');
}
$lists = DedeArctype::where('ishidden', 0)
->select('id', 'reid as parent_id', 'typename as title', 'content')
->get();
->select('id', 'reid as parent_id', 'typename as title', 'content')
->get();
$list = Tree::list2tree($lists->toArray(), 'id', 'parent_id', 'children', 0);
foreach ($list as $key => $value) {