|
|
|
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\CustomModule\CustomModuleCategory;
|
|
|
|
17
|
+use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
18
|
+use App\Models\News\News;
|
|
|
|
19
|
+use App\Models\News\NewsCategory;
|
|
|
|
20
|
+use App\Models\Product\Category;
|
|
|
|
21
|
+use App\Models\Product\CategoryRelated;
|
|
|
|
22
|
+use App\Models\Product\Product;
|
|
|
|
23
|
+use App\Models\Project\Project;
|
|
|
|
24
|
+use App\Services\ProjectServer;
|
|
|
|
25
|
+use Illuminate\Console\Command;
|
|
|
|
26
|
+use Illuminate\Support\Facades\DB;
|
|
|
|
27
|
+
|
|
|
|
28
|
+/**
|
|
|
|
29
|
+ * @remark :删除分类
|
|
|
|
30
|
+ * @name :DeleteProductCategory
|
|
|
|
31
|
+ * @author :lyh
|
|
|
|
32
|
+ * @method :post
|
|
|
|
33
|
+ * @time :2024/5/16 15:00
|
|
|
|
34
|
+ */
|
|
|
|
35
|
+class DeleteCustomCategory extends Command
|
|
|
|
36
|
+{
|
|
|
|
37
|
+ /**
|
|
|
|
38
|
+ * The name and signature of the console command.
|
|
|
|
39
|
+ *
|
|
|
|
40
|
+ * @var string
|
|
|
|
41
|
+ */
|
|
|
|
42
|
+ protected $signature = 'delete_custom_category';
|
|
|
|
43
|
+
|
|
|
|
44
|
+ /**
|
|
|
|
45
|
+ * The console command description.
|
|
|
|
46
|
+ *
|
|
|
|
47
|
+ * @var string
|
|
|
|
48
|
+ */
|
|
|
|
49
|
+ protected $description = '删除扩展模块分类';
|
|
|
|
50
|
+
|
|
|
|
51
|
+ /**
|
|
|
|
52
|
+ * Create a new command instance.
|
|
|
|
53
|
+ *
|
|
|
|
54
|
+ * @return void
|
|
|
|
55
|
+ */
|
|
|
|
56
|
+ public function __construct()
|
|
|
|
57
|
+ {
|
|
|
|
58
|
+ parent::__construct();
|
|
|
|
59
|
+ }
|
|
|
|
60
|
+
|
|
|
|
61
|
+ /**
|
|
|
|
62
|
+ * @remark :批量处理
|
|
|
|
63
|
+ * @name :handle
|
|
|
|
64
|
+ * @author :lyh
|
|
|
|
65
|
+ * @method :post
|
|
|
|
66
|
+ * @time :2024/5/16 15:02
|
|
|
|
67
|
+ */
|
|
|
|
68
|
+ public function handle(){
|
|
|
|
69
|
+ while (true){
|
|
|
|
70
|
+ $noticeLogModel = new NoticeLog();
|
|
|
|
71
|
+ $list = $noticeLogModel->list(['status'=>NoticeLog::STATUS_PENDING,'type'=>NoticeLog::DELETE_CUSTOM_CATEGORY],'id',['*'],'asc',100);
|
|
|
|
72
|
+ if(empty($list)){
|
|
|
|
73
|
+ sleep(100);
|
|
|
|
74
|
+ }
|
|
|
|
75
|
+ foreach ($list as $item){
|
|
|
|
76
|
+ echo 'start:' . $item['id'] . PHP_EOL;
|
|
|
|
77
|
+ try {
|
|
|
|
78
|
+ $projectModel = new Project();
|
|
|
|
79
|
+ $projectInfo = $projectModel->read(['id'=>$item['data']['project_id']]);
|
|
|
|
80
|
+ if($projectInfo === false){
|
|
|
|
81
|
+ continue;
|
|
|
|
82
|
+ }
|
|
|
|
83
|
+ ProjectServer::useProject($projectInfo['id']);
|
|
|
|
84
|
+ $this->updateCategory();
|
|
|
|
85
|
+ DB::disconnect('custom_mysql');
|
|
|
|
86
|
+ $noticeLogModel->edit(['status'=>NoticeLog::STATUS_SUCCESS],['id'=>$item['id']]);
|
|
|
|
87
|
+ echo 'success:' . $item['id'] . PHP_EOL;
|
|
|
|
88
|
+ }catch (\Exception $e){
|
|
|
|
89
|
+ echo 'error:' . $item['id'] . $e->getMessage() . PHP_EOL;
|
|
|
|
90
|
+ errorLog('项目初始化失败', $item, $e);
|
|
|
|
91
|
+ }
|
|
|
|
92
|
+ }
|
|
|
|
93
|
+ return true;
|
|
|
|
94
|
+ }
|
|
|
|
95
|
+ }
|
|
|
|
96
|
+
|
|
|
|
97
|
+ /**
|
|
|
|
98
|
+ * @remark :更新分类
|
|
|
|
99
|
+ * @name :updateProductCategory
|
|
|
|
100
|
+ * @author :lyh
|
|
|
|
101
|
+ * @method :post
|
|
|
|
102
|
+ * @time :2024/5/16 15:38
|
|
|
|
103
|
+ */
|
|
|
|
104
|
+ public function updateCategory(){
|
|
|
|
105
|
+ $page = 1;
|
|
|
|
106
|
+ $customModel = new CustomModuleContent();
|
|
|
|
107
|
+ while (true){
|
|
|
|
108
|
+ $customList = $customModel->lists(['status'=>0],$page,1000,'id',['id','category_id']);
|
|
|
|
109
|
+ if(empty($customList) || empty($customList['list'])){
|
|
|
|
110
|
+ return false;
|
|
|
|
111
|
+ }
|
|
|
|
112
|
+ foreach ($customList['list'] as $v){
|
|
|
|
113
|
+ $category_id_arr = Arr::setToArr(trim($v['category_id'],','));
|
|
|
|
114
|
+ if(empty($category_id_arr)){
|
|
|
|
115
|
+ continue;
|
|
|
|
116
|
+ }
|
|
|
|
117
|
+ $categoryModel = new CustomModuleCategory();
|
|
|
|
118
|
+ foreach ($category_id_arr as $k=>$cate_id){
|
|
|
|
119
|
+ $cateInfo = $categoryModel->read(['id'=>$cate_id],['id']);
|
|
|
|
120
|
+ if($cateInfo == false){
|
|
|
|
121
|
+ //删除关联表
|
|
|
|
122
|
+ unset($category_id_arr[$k]);
|
|
|
|
123
|
+ }
|
|
|
|
124
|
+ }
|
|
|
|
125
|
+ $str = !empty($category_id_arr) ? ','.Arr::arrToSet($category_id_arr).',' : '';
|
|
|
|
126
|
+ $customModel->edit(['category_id'=>$str],['id'=>$v['id']]);
|
|
|
|
127
|
+ }
|
|
|
|
128
|
+ $page++;
|
|
|
|
129
|
+ }
|
|
|
|
130
|
+ return true;
|
|
|
|
131
|
+ }
|
|
|
|
132
|
+} |