作者 lyh

gx数据

@@ -37,6 +37,8 @@ class AiBlogTask extends Command @@ -37,6 +37,8 @@ class AiBlogTask extends Command
37 */ 37 */
38 protected $signature = 'save_ai_blog'; 38 protected $signature = 'save_ai_blog';
39 39
  40 + public $updateProject = [];//需更新的列表
  41 +
40 /** 42 /**
41 * The console command description. 43 * The console command description.
42 * 44 *
@@ -45,61 +47,88 @@ class AiBlogTask extends Command @@ -45,61 +47,88 @@ class AiBlogTask extends Command
45 protected $description = '查询ai_blog是否已经生成'; 47 protected $description = '查询ai_blog是否已经生成';
46 48
47 public function handle(){ 49 public function handle(){
48 - $aiBlogTaskModel = new AiBlogTaskModel();  
49 while (true){ 50 while (true){
50 - $list = $aiBlogTaskModel->formatQuery(['status'=>1,'type'=>2])->inRandomOrder()->limit(1000)->get();  
51 - if(empty($list)){ 51 + //获取任务id
  52 + $task_id = $this->getTaskId();
  53 + if(empty($task_id)){
52 sleep(300); 54 sleep(300);
53 - continue;  
54 } 55 }
55 - $list = $list->toArray();  
56 - $updateProject = [];  
57 - foreach ($list as $item){  
58 - echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');  
59 - //获取配置  
60 - $aiSettingInfo = $this->getSetting($item['project_id']);  
61 - $aiBlogService = new AiBlogService();  
62 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
63 - $aiBlogService->key = $aiSettingInfo['key'];  
64 - $aiBlogService->task_id = $item['task_id'];  
65 - $result = $aiBlogService->getDetail();  
66 - if(!isset($result['status'])){  
67 - echo json_encode($result,true).PHP_EOL;  
68 - continue;  
69 - }  
70 - if($result['status'] != 200){  
71 - echo '错误状态码:'.$result['status'].PHP_EOL;  
72 - continue;  
73 - }  
74 - //保存当前项目ai_blog数据  
75 - ProjectServer::useProject($item['project_id']);  
76 - $aiBlogModel = new AiBlog();  
77 - $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);  
78 - if($aiBlogInfo === false){  
79 - echo '任务id不存在:'.$item['task_id'].PHP_EOL;  
80 - $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);  
81 - continue;  
82 - }  
83 - if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {  
84 - $updateProject[$item['project_id']][] = $result['data']['author_id'];  
85 - }  
86 - //拿到返回的路由查看是否重复  
87 - $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);  
88 - if($route != $result['data']['url']){  
89 - $aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]); 56 + $aiBlogTaskModel = new AiBlogTaskModel();
  57 + $item = $aiBlogTaskModel->read(['id'=>$task_id]);
  58 + echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
  59 + //获取配置
  60 + $aiSettingInfo = $this->getSetting($item['project_id']);
  61 + $aiBlogService = new AiBlogService();
  62 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  63 + $aiBlogService->key = $aiSettingInfo['key'];
  64 + $aiBlogService->task_id = $item['task_id'];
  65 + $result = $aiBlogService->getDetail();
  66 + if(!isset($result['status'])){
  67 + if($item['sort'] <= 5){
  68 + $aiBlogTaskModel->edit(['sort'=>$item['sort'] + 1],['id'=>$item['id']]);
  69 + }else{
  70 + $aiBlogTaskModel->edit(['status'=>9],['id'=>$item['id']]);
90 } 71 }
91 - $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'],'seo_title'=>$result['data']['title'],'seo_keyword'=>$result['data']['keyword'],'seo_description'=>$result['data']['description'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);  
92 - DB::disconnect('custom_mysql'); 72 + echo json_encode($result,true).PHP_EOL;
  73 + continue;
  74 + }
  75 + if($result['status'] != 200){
  76 + echo '错误状态码:'.$result['status'].PHP_EOL;
  77 + continue;
  78 + }
  79 + //保存当前项目ai_blog数据
  80 + ProjectServer::useProject($item['project_id']);
  81 + $aiBlogModel = new AiBlog();
  82 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
  83 + if($aiBlogInfo === false){
  84 + echo '任务id不存在:'.$item['task_id'].PHP_EOL;
93 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]); 85 $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
94 - echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s'); 86 + continue;
  87 + }
  88 + if (!in_array($result['data']['author_id'], $this->updateProject[$item['project_id']] ?? [])) {
  89 + $this->updateProject[$item['project_id']][] = $result['data']['author_id'];
95 } 90 }
96 - //TODO::更新列表页及作者  
97 - $this->updateProject($updateProject); 91 + //拿到返回的路由查看是否重复
  92 + $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
  93 + if($route != $result['data']['url']){
  94 + $aiBlogService->updateDetail(['route'=>$route,'task_id'=>$item['task_id']]);
  95 + }
  96 + $aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'],'seo_title'=>$result['data']['title'],'seo_keyword'=>$result['data']['keyword'],'seo_description'=>$result['data']['description'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
  97 + DB::disconnect('custom_mysql');
  98 + $aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
  99 + echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
98 } 100 }
99 return true; 101 return true;
100 } 102 }
101 103
102 /** 104 /**
  105 + * @remark :获取任务id
  106 + * @name :getTaskId
  107 + * @author :lyh
  108 + * @method :post
  109 + * @time :2025/3/19 16:16
  110 + */
  111 + public function getTaskId()
  112 + {
  113 + $task_id = Redis::rpop('ai_blog_task');
  114 + if (empty($task_id)) {
  115 + if(!empty($this->updateProject)){
  116 + $this->updateProject($this->updateProject);
  117 + $this->updateProject = [];
  118 + }
  119 + $aiBlogTaskModel = new AiBlogTaskModel();
  120 + $ids = $aiBlogTaskModel->formatQuery(['status'=>1,'type'=>2])->limit(1000)->pluck('id');
  121 + if(!empty($ids)){
  122 + foreach ($ids as $id) {
  123 + Redis::lpush('ai_blog_task', $id);
  124 + }
  125 + }
  126 + $task_id = Redis::rpop('ai_blog_task');
  127 + }
  128 + return $task_id;
  129 + }
  130 +
  131 + /**
103 * @remark :更新项目作者页面及列表页 132 * @remark :更新项目作者页面及列表页
104 * @name :updateProject 133 * @name :updateProject
105 * @author :lyh 134 * @author :lyh
1 -<?php  
2 -/**  
3 - * @remark :  
4 - * @name :ImportCustomModule.php  
5 - * @author :lyh  
6 - * @method :post  
7 - * @time :2024/12/9 11:35  
8 - */  
9 -  
10 -namespace App\Console\Commands\CustomModule;  
11 -  
12 -use App\Models\CustomModule\CustomModuleCategory;  
13 -use App\Models\CustomModule\CustomModuleContent;  
14 -use App\Models\CustomModule\CustomModuleExtentContent;  
15 -use App\Models\RouteMap\RouteMap;  
16 -use App\Services\ProjectServer;  
17 -use Illuminate\Console\Command;  
18 -use Illuminate\Support\Facades\DB;  
19 -  
20 -class ImportCustomModule extends Command  
21 -{  
22 - /**  
23 - * The name and signature of the console command.  
24 - *  
25 - * @var string  
26 - */  
27 - protected $signature = 'import_custom_module';  
28 -  
29 - /**  
30 - * The console command description.  
31 - *  
32 - * @var string  
33 - */  
34 - protected $description = '特殊项目导入扩展模块及扩展数据';  
35 -  
36 - /**  
37 - * @remark :导入  
38 - * @name :handle  
39 - * @author :lyh  
40 - * @method :post  
41 - * @time :2024/12/9 11:36  
42 - */  
43 - public function handle(){  
44 - echo date('Y-m-d H:i:s') . 'project_id:' . PHP_EOL;  
45 - ProjectServer::useProject(2837);  
46 - $this->import_module_content();  
47 - DB::disconnect('custom_mysql');  
48 - }  
49 -  
50 - /**  
51 - * @remark :导入扩展模块 (保留)  
52 - * @name :ceshis  
53 - * @author :lyh  
54 - * @method :post  
55 - * @time :2024/12/6 17:02  
56 - */  
57 - public function import_module_content(){  
58 - $data = 'MBR10100CT,Rectifier/Schottky Barrier Rectifier,TO-220AB,100,5*2,common cathode,100,0.85,10,2500,175,-,Active,https://v6-file.globalso.com/upload/p/2837/files/MBR10100CT.pdf  
59 -MBR2060BCT,Rectifier/Schottky Barrier Rectifier,ITO-220AB,60,10*2,common cathode,150,0.75,50,5000,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/MBR2060BCT.pdf  
60 -MBR20150DCT,Rectifier/Schottky Barrier Rectifier,TO-263(D2PAK),150,10*2,common cathode,150,0.88,5,1500,175,-,Active,https://v6-file.globalso.com/upload/p/2837/files/MBR20150DCT.pdf  
61 -MUR2060CT,Rectifier/High Efficient Rectifier,TO-220AB,600,10*2,common cathode,150,1.7,1,500,150,50,Active,https://v6-file.globalso.com/upload/p/2837/files/MUR2060CT.pdf  
62 -MUR2040FCT,Rectifier/High Efficient Rectifier,ITO-220AB,400,10*2,common cathode,150,1.3,1,500,150,50,Active,https://v6-file.globalso.com/upload/p/2837/files/MUR2040FCT.pdf  
63 -DSEK20S04B,Rectifier/Ultra fast soft Recovery Rectifier,TO-252(DPAK),400,10*2,common cathode,125,1.25,2,500,175,35,Active,https://v6-file.globalso.com/upload/p/2837/files/DSEK20S04B.pdf  
64 -DSEK30S06D,Rectifier/Ultra fast soft Recovery Rectifier,TO-263(D2PAK),600,15*2,common cathode,150,1.7,2,500,175,35,Active,https://v6-file.globalso.com/upload/p/2837/files/DSEK30S06D.pdf  
65 -DSEK60H06P,Rectifier/Ultra fast soft Recovery Rectifier,TO-247AD,600,30*2,common cathode,300,1.7,5,500,175,60,Active,https://v6-file.globalso.com/upload/p/2837/files/DSEK60H06P.pdf  
66 -GBU410,Rectifier/Bridge Rectifier,GBU,1000,4,-,125,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBU410.pdf  
67 -GBU1510,Rectifier/Bridge Rectifier,GBU,1000,15,-,250,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBU1510.pdf  
68 -GBJ2510,Rectifier/Bridge Rectifier,GBJ,1000,25,-,300,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBJ2510.pdf  
69 -GBU1504H,Rectifier/High Efficient Bridge Rectifier,GBU,400,15,-,150,1.3,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBU1504H.pdf  
70 -GBU1506H,Rectifier/High Efficient Bridge Rectifier,GBU,400,15,-,150,1.7,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBU1506H.pdf  
71 -GBJ2504H,Rectifier/High Efficient Bridge Rectifier,GBJ,600,25,-,250,1.3,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBJ2504H.pdf  
72 -GBJ2506H,Rectifier/High Efficient Bridge Rectifier,GBJ,600,25,-,250,1.7,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/GBJ2506H.pdf  
73 -1N4007,Rectifier/Standard Recovery Rectifier,DO-41,1000,1,-,50,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/1N4007.pdf  
74 -1N5399,Rectifier/Standard Recovery Rectifier,DO-15,1000,1.5,-,75,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/1N5399.pdf  
75 -1N5408,Rectifier/Standard Recovery Rectifier,DO-27,1000,3,-,100,1,1,500,150,-,Active,https://v6-file.globalso.com/upload/p/2837/files/1N5408.pdf  
76 -RS1M,Rectifier/Fast Recovery Rectifier,SMA,1000,1,-,50,1.3,1,500,150,500,Active,https://v6-file.globalso.com/upload/p/2837/files/RS1M.pdf  
77 -RS2M,Rectifier/Fast Recovery Rectifier,SMB,1000,2,-,75,1.3,1,500,150,500,Active,https://v6-file.globalso.com/upload/p/2837/files/RS2M.pdf  
78 -RS3M,Rectifier/Fast Recovery Rectifier,SMC,1000,3,-,100,1.3,1,500,150,500,Active,https://v6-file.globalso.com/upload/p/2837/files/RS3M.pdf  
79 -SF28,Rectifier/Super fast Recovery Rectifier,DO-15,600,2,-,60,1.7,1,500,150,35,Active,https://v6-file.globalso.com/upload/p/2837/files/SF28.pdf  
80 -SF56G,Rectifier/Super fast Recovery Rectifier,DO-27,400,5,-,125,1.3,1,500,150,35,Active,https://v6-file.globalso.com/upload/p/2837/files/SF56G.pdf  
81 -DSE1006,Rectifier/Super fast Recovery Rectifier,TO-220AC,600,10,Single Positive,150,1.7,1,500,150,35,Active,https://v6-file.globalso.com/upload/p/2837/files/DSE1006.pdf  
82 -DSE1504F,Rectifier/Super fast Recovery Rectifier,ITO-220AC,400,15,Single Positive,150,1.4,1,500,150,35,Active,https://v6-file.globalso.com/upload/p/2837/files/DSE1504F.pdf';  
83 - $array = explode("\n", $data);  
84 - foreach ($array as $values){  
85 - $array1 = explode(',',$values);  
86 - $contentData = [  
87 - 'name'=>$array1[0],  
88 - 'route'=>'',  
89 - 'project_id'=>2837,  
90 - 'operator_id'=>6393,  
91 - 'module_id'=>2,  
92 - ];  
93 - $customModuleCategoryModel = new CustomModuleCategory();  
94 - if(!empty($array1[1])){  
95 - $cate_ids = '';  
96 - $cate_arr = explode('/',$array1[1]);  
97 - foreach ($cate_arr as $cateV){  
98 - $catInfo = $customModuleCategoryModel->read(['name'=>$cateV]);  
99 - if($catInfo !== false){  
100 - $cate_ids = $cate_ids.','.$catInfo['id'];  
101 - }  
102 - }  
103 - $contentData['category_id'] = empty($cate_ids) ? '' : $cate_ids.',';  
104 - }else{  
105 - $catInfo = $customModuleCategoryModel->read(['name'=>$array1[1]]);  
106 - if($catInfo !== false){  
107 - $contentData['category_id'] = ','.$catInfo['id'].',';  
108 - }  
109 - }  
110 - $customModuleContentModel = new CustomModuleContent();  
111 - $contentId = $customModuleContentModel->addReturnId($contentData);  
112 - $route = RouteMap::setRoute($array1[0],RouteMap::SOURCE_MODULE,$contentId,2837);  
113 - $customModuleContentModel->edit(['route'=>$route],['id'=>$contentId]);  
114 - $pd_extended_field_arr = [  
115 - [  
116 - 'key'=>'pd_extended_field_1',  
117 - 'type'=>1,  
118 - 'project_id'=>2837,  
119 - 'values'=>$array1[2],  
120 - 'content_id'=>$contentId,  
121 - 'module_id'=>2,  
122 - 'created_at'=>date('Y-m-d H:i:s'),  
123 - 'updated_at'=>date('Y-m-d H:i:s'),  
124 - ],  
125 - [  
126 - 'key'=>'pd_extended_field_2',  
127 - 'type'=>1,  
128 - 'project_id'=>2837,  
129 - 'values'=>$array1[3],  
130 - 'module_id'=>2,  
131 - 'content_id'=>$contentId,  
132 - 'created_at'=>date('Y-m-d H:i:s'),  
133 - 'updated_at'=>date('Y-m-d H:i:s'),  
134 - ],  
135 - [  
136 - 'key'=>'pd_extended_field_3',  
137 - 'type'=>1,  
138 - 'project_id'=>2837,  
139 - 'values'=>$array1[4],  
140 - 'module_id'=>2,  
141 - 'content_id'=>$contentId,  
142 - 'created_at'=>date('Y-m-d H:i:s'),  
143 - 'updated_at'=>date('Y-m-d H:i:s'),  
144 - ],  
145 - [  
146 - 'key'=>'pd_extended_field_4',  
147 - 'type'=>1,  
148 - 'project_id'=>2837,  
149 - 'values'=>$array1[5],  
150 - 'module_id'=>2,  
151 - 'content_id'=>$contentId,  
152 - 'created_at'=>date('Y-m-d H:i:s'),  
153 - 'updated_at'=>date('Y-m-d H:i:s'),  
154 - ],  
155 - [  
156 - 'key'=>'pd_extended_field_5',  
157 - 'type'=>1,  
158 - 'project_id'=>2837,  
159 - 'values'=>$array1[6],  
160 - 'module_id'=>2,  
161 - 'content_id'=>$contentId,  
162 - 'created_at'=>date('Y-m-d H:i:s'),  
163 - 'updated_at'=>date('Y-m-d H:i:s'),  
164 - ],  
165 - [  
166 - 'key'=>'pd_extended_field_6',  
167 - 'type'=>1,  
168 - 'project_id'=>2837,  
169 - 'values'=>$array1[7],  
170 - 'module_id'=>2,  
171 - 'content_id'=>$contentId,  
172 - 'created_at'=>date('Y-m-d H:i:s'),  
173 - 'updated_at'=>date('Y-m-d H:i:s'),  
174 - ],  
175 - [  
176 - 'key'=>'pd_extended_field_7',  
177 - 'type'=>1,  
178 - 'project_id'=>2837,  
179 - 'values'=>$array1[8],  
180 - 'module_id'=>2,  
181 - 'content_id'=>$contentId,  
182 - 'created_at'=>date('Y-m-d H:i:s'),  
183 - 'updated_at'=>date('Y-m-d H:i:s'),  
184 - ],  
185 - [  
186 - 'key'=>'pd_extended_field_8',  
187 - 'type'=>1,  
188 - 'project_id'=>2837,  
189 - 'values'=>$array1[9],  
190 - 'module_id'=>2,  
191 - 'content_id'=>$contentId,  
192 - 'created_at'=>date('Y-m-d H:i:s'),  
193 - 'updated_at'=>date('Y-m-d H:i:s'),  
194 - ],  
195 - [  
196 - 'key'=>'pd_extended_field_9',  
197 - 'type'=>1,  
198 - 'project_id'=>2837,  
199 - 'values'=>$array1[10],  
200 - 'module_id'=>2,  
201 - 'content_id'=>$contentId,  
202 - 'created_at'=>date('Y-m-d H:i:s'),  
203 - 'updated_at'=>date('Y-m-d H:i:s'),  
204 - ],  
205 - [  
206 - 'key'=>'pd_extended_field_10',  
207 - 'type'=>1,  
208 - 'project_id'=>2837,  
209 - 'values'=>$array1[11],  
210 - 'module_id'=>2,  
211 - 'content_id'=>$contentId,  
212 - 'created_at'=>date('Y-m-d H:i:s'),  
213 - 'updated_at'=>date('Y-m-d H:i:s'),  
214 - ],  
215 - [  
216 - 'key'=>'pd_extended_field_11',  
217 - 'type'=>1,  
218 - 'project_id'=>2837,  
219 - 'values'=>$array1[12],  
220 - 'module_id'=>2,  
221 - 'content_id'=>$contentId,  
222 - 'created_at'=>date('Y-m-d H:i:s'),  
223 - 'updated_at'=>date('Y-m-d H:i:s'),  
224 - ],  
225 - [  
226 - 'key'=>'pd_extended_field_12',  
227 - 'type'=>4,  
228 - 'project_id'=>2837,  
229 - 'values'=>json_encode([['url'=>$array1[13]]]),  
230 - 'module_id'=>2,  
231 - 'content_id'=>$contentId,  
232 - 'created_at'=>date('Y-m-d H:i:s'),  
233 - 'updated_at'=>date('Y-m-d H:i:s'),  
234 - ],  
235 - ];  
236 - $extendContentModel = new CustomModuleExtentContent();  
237 - $extendContentModel->insert($pd_extended_field_arr);  
238 - }  
239 - }  
240 -  
241 -}