合并分支 'master-lyh-edit' 到 'master'
自定义模块删除分类 查看合并请求 !556
正在显示
5 个修改的文件
包含
135 行增加
和
14 行删除
| @@ -13,11 +13,6 @@ use App\Helper\Arr; | @@ -13,11 +13,6 @@ use App\Helper\Arr; | ||
| 13 | use App\Models\Blog\Blog; | 13 | use App\Models\Blog\Blog; |
| 14 | use App\Models\Blog\BlogCategory; | 14 | use App\Models\Blog\BlogCategory; |
| 15 | use App\Models\Com\NoticeLog; | 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; | 16 | use App\Models\Project\Project; |
| 22 | use App\Services\ProjectServer; | 17 | use App\Services\ProjectServer; |
| 23 | use Illuminate\Console\Command; | 18 | use Illuminate\Console\Command; |
| 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\CustomModule\CustomModuleCategory; | ||
| 15 | +use App\Models\CustomModule\CustomModuleContent; | ||
| 16 | +use App\Models\Project\Project; | ||
| 17 | +use App\Services\ProjectServer; | ||
| 18 | +use Illuminate\Console\Command; | ||
| 19 | +use Illuminate\Support\Facades\DB; | ||
| 20 | + | ||
| 21 | +/** | ||
| 22 | + * @remark :删除分类 | ||
| 23 | + * @name :DeleteProductCategory | ||
| 24 | + * @author :lyh | ||
| 25 | + * @method :post | ||
| 26 | + * @time :2024/5/16 15:00 | ||
| 27 | + */ | ||
| 28 | +class DeleteCustomCategory extends Command | ||
| 29 | +{ | ||
| 30 | + /** | ||
| 31 | + * The name and signature of the console command. | ||
| 32 | + * | ||
| 33 | + * @var string | ||
| 34 | + */ | ||
| 35 | + protected $signature = 'delete_custom_category'; | ||
| 36 | + | ||
| 37 | + /** | ||
| 38 | + * The console command description. | ||
| 39 | + * | ||
| 40 | + * @var string | ||
| 41 | + */ | ||
| 42 | + protected $description = '删除扩展模块分类'; | ||
| 43 | + | ||
| 44 | + /** | ||
| 45 | + * Create a new command instance. | ||
| 46 | + * | ||
| 47 | + * @return void | ||
| 48 | + */ | ||
| 49 | + public function __construct() | ||
| 50 | + { | ||
| 51 | + parent::__construct(); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | + /** | ||
| 55 | + * @remark :批量处理 | ||
| 56 | + * @name :handle | ||
| 57 | + * @author :lyh | ||
| 58 | + * @method :post | ||
| 59 | + * @time :2024/5/16 15:02 | ||
| 60 | + */ | ||
| 61 | + public function handle(){ | ||
| 62 | + while (true){ | ||
| 63 | + $noticeLogModel = new NoticeLog(); | ||
| 64 | + $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_CUSTOM_CATEGORY],'id',['*'],'asc',100); | ||
| 65 | + if(empty($list)){ | ||
| 66 | + sleep(100); | ||
| 67 | + } | ||
| 68 | + foreach ($list as $item){ | ||
| 69 | + echo 'start:' . $item['id'] . PHP_EOL; | ||
| 70 | + try { | ||
| 71 | + $projectModel = new Project(); | ||
| 72 | + $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]); | ||
| 73 | + if($projectInfo === false){ | ||
| 74 | + continue; | ||
| 75 | + } | ||
| 76 | + ProjectServer::useProject($projectInfo['id']); | ||
| 77 | + $this->updateCategory(); | ||
| 78 | + DB::disconnect('custom_mysql'); | ||
| 79 | + $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]); | ||
| 80 | + echo 'success:' . $item['id'] . PHP_EOL; | ||
| 81 | + }catch (\Exception $e){ | ||
| 82 | + echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL; | ||
| 83 | + errorLog('项目初始化失败', $item, $e); | ||
| 84 | + } | ||
| 85 | + } | ||
| 86 | + return true; | ||
| 87 | + } | ||
| 88 | + } | ||
| 89 | + | ||
| 90 | + /** | ||
| 91 | + * @remark :更新分类 | ||
| 92 | + * @name :updateProductCategory | ||
| 93 | + * @author :lyh | ||
| 94 | + * @method :post | ||
| 95 | + * @time :2024/5/16 15:38 | ||
| 96 | + */ | ||
| 97 | + public function updateCategory(){ | ||
| 98 | + $page = 1; | ||
| 99 | + $customModel = new CustomModuleContent(); | ||
| 100 | + while (true){ | ||
| 101 | + $customList = $customModel->lists(['status'=>0],$page,1000,'id',['id','category_id']); | ||
| 102 | + if(empty($customList) || empty($customList['list'])){ | ||
| 103 | + return false; | ||
| 104 | + } | ||
| 105 | + foreach ($customList['list'] as $v){ | ||
| 106 | + $category_id_arr = Arr::setToArr(trim($v['category_id'],',')); | ||
| 107 | + if(empty($category_id_arr)){ | ||
| 108 | + continue; | ||
| 109 | + } | ||
| 110 | + $categoryModel = new CustomModuleCategory(); | ||
| 111 | + foreach ($category_id_arr as $k=>$cate_id){ | ||
| 112 | + $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']); | ||
| 113 | + if($cateInfo == false){ | ||
| 114 | + //删除关联表 | ||
| 115 | + unset($category_id_arr[$k]); | ||
| 116 | + } | ||
| 117 | + } | ||
| 118 | + $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : ''; | ||
| 119 | + $customModel->edit(['category_id'=>$str],['id'=>$v['id']]); | ||
| 120 | + } | ||
| 121 | + $page++; | ||
| 122 | + } | ||
| 123 | + return true; | ||
| 124 | + } | ||
| 125 | +} |
| @@ -13,9 +13,6 @@ use App\Helper\Arr; | @@ -13,9 +13,6 @@ use App\Helper\Arr; | ||
| 13 | use App\Models\Com\NoticeLog; | 13 | use App\Models\Com\NoticeLog; |
| 14 | use App\Models\News\News; | 14 | use App\Models\News\News; |
| 15 | use App\Models\News\NewsCategory; | 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; | 16 | use App\Models\Project\Project; |
| 20 | use App\Services\ProjectServer; | 17 | use App\Services\ProjectServer; |
| 21 | use Illuminate\Console\Command; | 18 | use Illuminate\Console\Command; |
| @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\CustomModule; | @@ -11,6 +11,7 @@ namespace App\Http\Logic\Bside\CustomModule; | ||
| 11 | 11 | ||
| 12 | use App\Helper\Arr; | 12 | use App\Helper\Arr; |
| 13 | use App\Http\Logic\Bside\BaseLogic; | 13 | use App\Http\Logic\Bside\BaseLogic; |
| 14 | +use App\Models\Com\NoticeLog; | ||
| 14 | use App\Models\CustomModule\CustomModuleCategory; | 15 | use App\Models\CustomModule\CustomModuleCategory; |
| 15 | use App\Models\CustomModule\CustomModuleContent; | 16 | use App\Models\CustomModule\CustomModuleContent; |
| 16 | use App\Models\RouteMap\RouteMap; | 17 | use App\Models\RouteMap\RouteMap; |
| @@ -190,14 +191,16 @@ class CustomModuleCategoryLogic extends BaseLogic | @@ -190,14 +191,16 @@ class CustomModuleCategoryLogic extends BaseLogic | ||
| 190 | public function categoryDel(){ | 191 | public function categoryDel(){ |
| 191 | $ids = $this->param['id']; | 192 | $ids = $this->param['id']; |
| 192 | foreach ($ids as $id){ | 193 | foreach ($ids as $id){ |
| 194 | + $str = []; | ||
| 195 | + $this->getAllSub($id,$str); | ||
| 196 | + $str[] = $id; | ||
| 197 | + foreach ($str as $value){ | ||
| 193 | //删除路由 | 198 | //删除路由 |
| 194 | - $this->delRoute($id); | ||
| 195 | - $this->model->del(['id'=>$id]); | ||
| 196 | - //同步删除产品字段category_id | ||
| 197 | - $contentModel = new CustomModuleContent(); | ||
| 198 | - $contentModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]); | ||
| 199 | - $contentModel->edit(['category_id'=>null],['category_id'=>',']); | 199 | + $this->delRoute($value); |
| 200 | + $this->model->del(['id'=>$value]); | ||
| 201 | + } | ||
| 200 | } | 202 | } |
| 203 | + NoticeLog::createLog(NoticeLog::DELETE_CUSTOM_CATEGORY, ['project_id' => $this->user['project_id']]); | ||
| 201 | return $this->success(); | 204 | return $this->success(); |
| 202 | } | 205 | } |
| 203 | 206 |
| @@ -17,6 +17,7 @@ class NoticeLog extends Base | @@ -17,6 +17,7 @@ class NoticeLog extends Base | ||
| 17 | const DELETE_PRODUCT_CATEGORY = 'delete_product_category'; | 17 | const DELETE_PRODUCT_CATEGORY = 'delete_product_category'; |
| 18 | const DELETE_BLOG_CATEGORY = 'delete_blog_category'; | 18 | const DELETE_BLOG_CATEGORY = 'delete_blog_category'; |
| 19 | const DELETE_NEWS_CATEGORY = 'delete_news_category'; | 19 | const DELETE_NEWS_CATEGORY = 'delete_news_category'; |
| 20 | + const DELETE_CUSTOM_CATEGORY = 'delete_custom_category'; | ||
| 20 | const STATUS_PENDING = 0; | 21 | const STATUS_PENDING = 0; |
| 21 | const STATUS_SUCCESS = 1; | 22 | const STATUS_SUCCESS = 1; |
| 22 | const STATUS_FAIL = 2; | 23 | const STATUS_FAIL = 2; |
-
请 注册 或 登录 后发表评论