重新导入数据

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() public function grid()
{ {
$grid = new Grid(new Article); $grid = new Grid(new Article);
$grid->model()->orderBy('id', 'desc'); $grid->model()->orderBy('created_at', 'desc');
$grid->filter(function ($filter) { $grid->filter(function ($filter) {
$filter->column(1 / 2, function ($filter) { $filter->column(1 / 2, function ($filter) {
$filter->like('title', '文章标题'); $filter->like('title', '文章标题');

View File

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