合并分支 'master-lyh-edit' 到 'master'
删除分类处理 查看合并请求 !555
正在显示
3 个修改的文件
包含
322 行增加
和
2 行删除
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Blog\Blog; | ||
| 14 | +use App\Models\Blog\BlogCategory; | ||
| 15 | +use App\Models\Com\NoticeLog; | ||
| 16 | +use App\Models\News\News; | ||
| 17 | +use App\Models\News\NewsCategory; | ||
| 18 | +use App\Models\Product\Category; | ||
| 19 | +use App\Models\Product\CategoryRelated; | ||
| 20 | +use App\Models\Product\Product; | ||
| 21 | +use App\Models\Project\Project; | ||
| 22 | +use App\Services\ProjectServer; | ||
| 23 | +use Illuminate\Console\Command; | ||
| 24 | +use Illuminate\Support\Facades\DB; | ||
| 25 | + | ||
| 26 | +/** | ||
| 27 | + * @remark :删除分类 | ||
| 28 | + * @name :DeleteProductCategory | ||
| 29 | + * @author :lyh | ||
| 30 | + * @method :post | ||
| 31 | + * @time :2024/5/16 15:00 | ||
| 32 | + */ | ||
| 33 | +class DeleteBlogCategory extends Command | ||
| 34 | +{ | ||
| 35 | + /** | ||
| 36 | + * The name and signature of the console command. | ||
| 37 | + * | ||
| 38 | + * @var string | ||
| 39 | + */ | ||
| 40 | + protected $signature = 'delete_blog_category'; | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * The console command description. | ||
| 44 | + * | ||
| 45 | + * @var string | ||
| 46 | + */ | ||
| 47 | + protected $description = '删除博客分类'; | ||
| 48 | + | ||
| 49 | + /** | ||
| 50 | + * Create a new command instance. | ||
| 51 | + * | ||
| 52 | + * @return void | ||
| 53 | + */ | ||
| 54 | + public function __construct() | ||
| 55 | + { | ||
| 56 | + parent::__construct(); | ||
| 57 | + } | ||
| 58 | + | ||
| 59 | + /** | ||
| 60 | + * @remark :批量处理 | ||
| 61 | + * @name :handle | ||
| 62 | + * @author :lyh | ||
| 63 | + * @method :post | ||
| 64 | + * @time :2024/5/16 15:02 | ||
| 65 | + */ | ||
| 66 | + public function handle(){ | ||
| 67 | + while (true){ | ||
| 68 | + $noticeLogModel = new NoticeLog(); | ||
| 69 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_BLOG_CATEGORY],'id',['*'],'asc',100); | ||
| 70 | + if(empty($list)){ | ||
| 71 | + sleep(100); | ||
| 72 | + } | ||
| 73 | + foreach ($list as $item){ | ||
| 74 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 75 | + try { | ||
| 76 | + $projectModel = new Project(); | ||
| 77 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 78 | + if($projectInfo === false){ | ||
| 79 | + continue; | ||
| 80 | + } | ||
| 81 | + ProjectServer::useProject($projectInfo['id']); | ||
| 82 | + $this->updateCategory(); | ||
| 83 | + DB::disconnect('custom_mysql'); | ||
| 84 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 85 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 86 | + }catch (\Exception $e){ | ||
| 87 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 88 | + errorLog('项目初始化失败', $item, $e); | ||
| 89 | + } | ||
| 90 | + } | ||
| 91 | + return true; | ||
| 92 | + } | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + /** | ||
| 96 | + * @remark :更新分类 | ||
| 97 | + * @name :updateProductCategory | ||
| 98 | + * @author :lyh | ||
| 99 | + * @method :post | ||
| 100 | + * @time :2024/5/16 15:38 | ||
| 101 | + */ | ||
| 102 | + public function updateCategory(){ | ||
| 103 | + $page = 1; | ||
| 104 | + $blogModel = new Blog(); | ||
| 105 | + while (true){ | ||
| 106 | + $blogList = $blogModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 107 | + if(empty($blogList) || empty($blogList['list'])){ | ||
| 108 | + return false; | ||
| 109 | + } | ||
| 110 | + foreach ($blogList['list'] as $v){ | ||
| 111 | + $category_id_arr = Arr::setToArr(trim($v['category_id'],',')); | ||
| 112 | + if(empty($category_id_arr)){ | ||
| 113 | + continue; | ||
| 114 | + } | ||
| 115 | + $categoryModel = new BlogCategory(); | ||
| 116 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 117 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 118 | + if($cateInfo == false){ | ||
| 119 | + //删除关联表 | ||
| 120 | + unset($category_id_arr[$k]); | ||
| 121 | + } | ||
| 122 | + } | ||
| 123 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 124 | + $blogModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 125 | + } | ||
| 126 | + $page++; | ||
| 127 | + } | ||
| 128 | + return true; | ||
| 129 | + } | ||
| 130 | +} |
| 1 | +<?php | ||
| 2 | +/** | ||
| 3 | + * @remark : | ||
| 4 | + * @name :DeleteProductCategory.php | ||
| 5 | + * @author :lyh | ||
| 6 | + * @method :post | ||
| 7 | + * @time :2024/5/16 14:59 | ||
| 8 | + */ | ||
| 9 | + | ||
| 10 | +namespace App\Console\Commands\DeleteCategory; | ||
| 11 | + | ||
| 12 | +use App\Helper\Arr; | ||
| 13 | +use App\Models\Com\NoticeLog; | ||
| 14 | +use App\Models\News\News; | ||
| 15 | +use App\Models\News\NewsCategory; | ||
| 16 | +use App\Models\Product\Category; | ||
| 17 | +use App\Models\Product\CategoryRelated; | ||
| 18 | +use App\Models\Product\Product; | ||
| 19 | +use App\Models\Project\Project; | ||
| 20 | +use App\Services\ProjectServer; | ||
| 21 | +use Illuminate\Console\Command; | ||
| 22 | +use Illuminate\Support\Facades\DB; | ||
| 23 | + | ||
| 24 | +/** | ||
| 25 | + * @remark :删除分类 | ||
| 26 | + * @name :DeleteProductCategory | ||
| 27 | + * @author :lyh | ||
| 28 | + * @method :post | ||
| 29 | + * @time :2024/5/16 15:00 | ||
| 30 | + */ | ||
| 31 | +class DeleteNewsCategory extends Command | ||
| 32 | +{ | ||
| 33 | + /** | ||
| 34 | + * The name and signature of the console command. | ||
| 35 | + * | ||
| 36 | + * @var string | ||
| 37 | + */ | ||
| 38 | + protected $signature = 'delete_news_category'; | ||
| 39 | + | ||
| 40 | + /** | ||
| 41 | + * The console command description. | ||
| 42 | + * | ||
| 43 | + * @var string | ||
| 44 | + */ | ||
| 45 | + protected $description = '删除新闻分类'; | ||
| 46 | + | ||
| 47 | + /** | ||
| 48 | + * Create a new command instance. | ||
| 49 | + * | ||
| 50 | + * @return void | ||
| 51 | + */ | ||
| 52 | + public function __construct() | ||
| 53 | + { | ||
| 54 | + parent::__construct(); | ||
| 55 | + } | ||
| 56 | + | ||
| 57 | + /** | ||
| 58 | + * @remark :批量处理 | ||
| 59 | + * @name :handle | ||
| 60 | + * @author :lyh | ||
| 61 | + * @method :post | ||
| 62 | + * @time :2024/5/16 15:02 | ||
| 63 | + */ | ||
| 64 | + public function handle(){ | ||
| 65 | + while (true){ | ||
| 66 | + $noticeLogModel = new NoticeLog(); | ||
| 67 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_NEWS_CATEGORY],'id',['*'],'asc',100); | ||
| 68 | + if(empty($list)){ | ||
| 69 | + sleep(100); | ||
| 70 | + } | ||
| 71 | + foreach ($list as $item){ | ||
| 72 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 73 | +// try { | ||
| 74 | + $projectModel = new Project(); | ||
| 75 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 76 | + if($projectInfo === false){ | ||
| 77 | + continue; | ||
| 78 | + } | ||
| 79 | + ProjectServer::useProject($projectInfo['id']); | ||
| 80 | + $this->updateCategory(); | ||
| 81 | + DB::disconnect('custom_mysql'); | ||
| 82 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 83 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 84 | +// }catch (\Exception $e){ | ||
| 85 | +// echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 86 | +// errorLog('项目初始化失败', $item, $e); | ||
| 87 | +// } | ||
| 88 | + } | ||
| 89 | + return true; | ||
| 90 | + } | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + /** | ||
| 94 | + * @remark :更新分类 | ||
| 95 | + * @name :updateProductCategory | ||
| 96 | + * @author :lyh | ||
| 97 | + * @method :post | ||
| 98 | + * @time :2024/5/16 15:38 | ||
| 99 | + */ | ||
| 100 | + public function updateCategory(){ | ||
| 101 | + $page = 1; | ||
| 102 | + $newsModel = new News(); | ||
| 103 | + while (true){ | ||
| 104 | + $newsList = $newsModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 105 | + if(empty($newsList) || empty($newsList['list'])){ | ||
| 106 | + return false; | ||
| 107 | + } | ||
| 108 | + foreach ($newsList['list'] as $v){ | ||
| 109 | + $category_id_arr = Arr::setToArr(trim($v['category_id'],',')); | ||
| 110 | + if(empty($category_id_arr)){ | ||
| 111 | + continue; | ||
| 112 | + } | ||
| 113 | + $categoryModel = new NewsCategory(); | ||
| 114 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 115 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 116 | + if($cateInfo === false){ | ||
| 117 | + //删除关联表 | ||
| 118 | + unset($category_id_arr[$k]); | ||
| 119 | + } | ||
| 120 | + } | ||
| 121 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 122 | + $newsModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 123 | + } | ||
| 124 | + $page++; | ||
| 125 | + } | ||
| 126 | + return true; | ||
| 127 | + } | ||
| 128 | +} |
| @@ -9,8 +9,15 @@ | @@ -9,8 +9,15 @@ | ||
| 9 | 9 | ||
| 10 | namespace App\Console\Commands\DeleteCategory; | 10 | namespace App\Console\Commands\DeleteCategory; |
| 11 | 11 | ||
| 12 | +use App\Helper\Arr; | ||
| 12 | use App\Models\Com\NoticeLog; | 13 | use App\Models\Com\NoticeLog; |
| 14 | +use App\Models\Product\Category; | ||
| 15 | +use App\Models\Product\CategoryRelated; | ||
| 16 | +use App\Models\Product\Product; | ||
| 17 | +use App\Models\Project\Project; | ||
| 18 | +use App\Services\ProjectServer; | ||
| 13 | use Illuminate\Console\Command; | 19 | use Illuminate\Console\Command; |
| 20 | +use Illuminate\Support\Facades\DB; | ||
| 14 | 21 | ||
| 15 | /** | 22 | /** |
| 16 | * @remark :删除分类 | 23 | * @remark :删除分类 |
| @@ -55,13 +62,68 @@ class DeleteProductCategory extends Command | @@ -55,13 +62,68 @@ class DeleteProductCategory extends Command | ||
| 55 | public function handle(){ | 62 | public function handle(){ |
| 56 | while (true){ | 63 | while (true){ |
| 57 | $noticeLogModel = new NoticeLog(); | 64 | $noticeLogModel = new NoticeLog(); |
| 58 | - $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc','100'); | 65 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_PRODUCT_CATEGORY],'id',['*'],'asc',100); |
| 59 | if(empty($list)){ | 66 | if(empty($list)){ |
| 60 | sleep(100); | 67 | sleep(100); |
| 61 | } | 68 | } |
| 62 | - foreach ($list as $v){ | 69 | + foreach ($list as $item){ |
| 70 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 71 | + try { | ||
| 72 | + $projectModel = new Project(); | ||
| 73 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 74 | + if($projectInfo === false){ | ||
| 75 | + continue; | ||
| 76 | + } | ||
| 77 | + ProjectServer::useProject($projectInfo['id']); | ||
| 78 | + $this->updateCategory(); | ||
| 79 | + DB::disconnect('custom_mysql'); | ||
| 80 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 81 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 82 | + }catch (\Exception $e){ | ||
| 83 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 84 | + errorLog('项目初始化失败', $item, $e); | ||
| 85 | + } | ||
| 86 | + } | ||
| 87 | + return true; | ||
| 88 | + } | ||
| 89 | + } | ||
| 63 | 90 | ||
| 91 | + /** | ||
| 92 | + * @remark :更新分类 | ||
| 93 | + * @name :updateProductCategory | ||
| 94 | + * @author :lyh | ||
| 95 | + * @method :post | ||
| 96 | + * @time :2024/5/16 15:38 | ||
| 97 | + */ | ||
| 98 | + public function updateCategory(){ | ||
| 99 | + $page = 1; | ||
| 100 | + while (true){ | ||
| 101 | + $productModel = new Product(); | ||
| 102 | + $productList = $productModel->lists(['status'=>1],$page,1000,'id',['id','category_id']); | ||
| 103 | + if(empty($productList) || empty($productList['list'])){ | ||
| 104 | + return false; | ||
| 105 | + } | ||
| 106 | + foreach ($productList['list'] as $v){ | ||
| 107 | + $categoryRelatedModel = new CategoryRelated(); | ||
| 108 | + if(empty($v['category_id'])){ | ||
| 109 | + $categoryRelatedModel->del(['product_id'=>$v['id']]); | ||
| 110 | + continue; | ||
| 111 | + } | ||
| 112 | + $category_id_arr = $v['category_id']; | ||
| 113 | + $categoryModel = new Category(); | ||
| 114 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 115 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 116 | + if($cateInfo == false){ | ||
| 117 | + //删除关联表 | ||
| 118 | + $categoryRelatedModel->del(['cate_id'=>$cate_id]); | ||
| 119 | + unset($category_id_arr[$k]); | ||
| 120 | + } | ||
| 121 | + } | ||
| 122 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 123 | + $productModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 64 | } | 124 | } |
| 125 | + $page++; | ||
| 65 | } | 126 | } |
| 127 | + return true; | ||
| 66 | } | 128 | } |
| 67 | } | 129 | } |
-
请 注册 或 登录 后发表评论