文章关联多分类
This commit is contained in:
@@ -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;
|
||||
@@ -11,6 +12,7 @@ use Illuminate\Support\Facades\DB;
|
||||
|
||||
class TestController extends Controller
|
||||
{
|
||||
|
||||
use Tree;
|
||||
|
||||
public function index()
|
||||
@@ -18,17 +20,34 @@ 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 checkCategory()
|
||||
{
|
||||
$article = Article::find(913);
|
||||
dd($article->get_one_cover());
|
||||
dd();
|
||||
$lists = Category::where('created_at','2020-06-03 15:57:55')->get();
|
||||
$i=1;
|
||||
foreach ($lists as $info){
|
||||
$old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')->find($info->oldid);
|
||||
$cate = Category::where('oldid',$old->parent_id)->first();
|
||||
$lists = Category::where('created_at', '2020-06-03 15:57:55')->get();
|
||||
$i = 1;
|
||||
foreach ($lists as $info) {
|
||||
$old = DedeArctype::select('id', 'reid as parent_id', 'typename as title', 'content')
|
||||
->find($info->oldid);
|
||||
$cate = Category::where('oldid', $old->parent_id)->first();
|
||||
$info->parent_id = $cate->id;
|
||||
$info->save();
|
||||
$i++;
|
||||
@@ -38,14 +57,17 @@ class TestController extends Controller
|
||||
dump(count($lists));
|
||||
dd();
|
||||
$cateids = Category::where('oldid', '>', 0)->pluck('oldid');
|
||||
$oldids = DedeArctype::where('ishidden', 0)->pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $cateids->toArray());
|
||||
$oldids = DedeArctype::where('ishidden', 0)->pluck('id');
|
||||
$diffids = array_diff($oldids->toArray(), $cateids->toArray());
|
||||
dump(count($cateids));
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
|
||||
foreach ($diffids as $diffid) {
|
||||
$info = DedeArctype::where('id',$diffid)->where('ishidden', 0)->select('id', 'reid as parent_id', 'typename as title', 'content')->first();
|
||||
$info = DedeArctype::where('id', $diffid)
|
||||
->where('ishidden', 0)
|
||||
->select('id', 'reid as parent_id', 'typename as title', 'content')
|
||||
->first();
|
||||
$data = $this->getData($info);
|
||||
Category::create($data);
|
||||
}
|
||||
@@ -87,9 +109,9 @@ class TestController extends Controller
|
||||
{
|
||||
$lists = Article::where('category_id', 0)->get();
|
||||
foreach ($lists as $list) {
|
||||
$old = DedeArchive::find($list->oldid);
|
||||
$cate = Category::where('oldid',$old->typeid)->first();
|
||||
$list ->category_id = $cate->id;
|
||||
$old = DedeArchive::find($list->oldid);
|
||||
$cate = Category::where('oldid', $old->typeid)->first();
|
||||
$list->category_id = $cate->id;
|
||||
$list->save();
|
||||
}
|
||||
dd();
|
||||
@@ -100,7 +122,7 @@ class TestController extends Controller
|
||||
dump(count($oldids));
|
||||
dump($diffids);
|
||||
die();
|
||||
$map = [
|
||||
$map = [
|
||||
'id' => ['in', $diffids],
|
||||
];
|
||||
$list = DedeArchive::whereIn('id', $diffids)->get();
|
||||
@@ -130,7 +152,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) {
|
||||
@@ -170,7 +192,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) {
|
||||
@@ -193,6 +217,7 @@ class TestController extends Controller
|
||||
'content' => $category['content'],
|
||||
'status' => 1,
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user