文章对应分类多个

This commit is contained in:
2021-04-02 10:15:47 +08:00
parent 5e1c402087
commit ead950990f
12 changed files with 324 additions and 180 deletions

View File

@@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Models\Article;
use App\Models\ArticleCategory;
use App\Models\Category;
use App\Models\DedeArchive;
use App\Models\DedeArctype;
@@ -10,6 +11,7 @@ use App\Traits\Tree;
class TestController extends Controller
{
use Tree;
public function index()
@@ -17,6 +19,22 @@ class TestController extends Controller
}
public function set_article_category()
{
$articles = Article::whereHas('category')
->chunk(200, function ($articles) {
foreach ($articles as $article) {
ArticleCategory::create([
'article_id' => $article->id,
'category_id' => $article->category_id,
]);
}
});
return true;
}
public function setCateArticle()
{
$article = [];
@@ -58,7 +76,7 @@ class TestController extends Controller
dump(count($oldids));
dump($diffids);
die();
$map = [
$map = [
'id' => ['in', $diffids],
];
$list = DedeArchive::whereIn('id', $diffids)->get();
@@ -88,7 +106,7 @@ class TestController extends Controller
dd('已经导入过数据');
}
$categorys = Category::get();
$error = $success = [];
$error = $success = [];
DedeArchive::whereNotNull('litpic')->chunk(200, function ($articles) use ($categorys) {
foreach ($articles as $article) {
@@ -128,7 +146,9 @@ class TestController extends Controller
if ($categorys->count()) {
dd('已经导入过数据');
}
$lists = DedeArctype::where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->get();
$lists = DedeArctype::where('ishidden', 0)
->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) {
@@ -151,6 +171,7 @@ class TestController extends Controller
'content' => $category['content'],
'status' => 1,
];
return $data;
}