From 4a3a7103858d622db7588df534feb45c45ff003f Mon Sep 17 00:00:00 2001 From: xuanchen120 <122383162@qq.com> Date: Thu, 7 Jul 2022 10:51:00 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=96=B0=E5=AF=BC=E5=85=A5=E6=95=B0?= =?UTF-8?q?=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Article/IndexController.php | 2 +- app/Http/Controllers/TestController.php | 53 +++++++++++-------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/app/Admin/Controllers/Article/IndexController.php b/app/Admin/Controllers/Article/IndexController.php index 8ff1394..3c18052 100644 --- a/app/Admin/Controllers/Article/IndexController.php +++ b/app/Admin/Controllers/Article/IndexController.php @@ -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', '文章标题'); diff --git a/app/Http/Controllers/TestController.php b/app/Http/Controllers/TestController.php index 77f2bc3..a707440 100644 --- a/app/Http/Controllers/TestController.php +++ b/app/Http/Controllers/TestController.php @@ -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) {