作者 lyh

gx

@@ -41,6 +41,7 @@ class AiBlogTask extends Command @@ -41,6 +41,7 @@ class AiBlogTask extends Command
41 41
42 public $updateProject = [];//需更新的列表 42 public $updateProject = [];//需更新的列表
43 public $projectSetting = []; 43 public $projectSetting = [];
  44 + public $routes = [];//需要更新的路由
44 45
45 /** 46 /**
46 * The console command description. 47 * The console command description.
@@ -75,7 +76,7 @@ class AiBlogTask extends Command @@ -75,7 +76,7 @@ class AiBlogTask extends Command
75 public function sendRequest($task_id){ 76 public function sendRequest($task_id){
76 $aiBlogTaskModel = new AiBlogTaskModel(); 77 $aiBlogTaskModel = new AiBlogTaskModel();
77 $item = $aiBlogTaskModel->read(['id'=>$task_id]); 78 $item = $aiBlogTaskModel->read(['id'=>$task_id]);
78 - $this->output('start:project ID: ' . $item['project_id'] . ', task ID: ' . $task_id); 79 + $this->output('start:project ID: ' . $item['project_id'] . ',task ID: ' . $task_id);
79 //获取配置 80 //获取配置
80 $aiSettingInfo = $this->getSetting($item['project_id']); 81 $aiSettingInfo = $this->getSetting($item['project_id']);
81 $aiBlogService = new AiBlogService(); 82 $aiBlogService = new AiBlogService();
@@ -84,9 +85,7 @@ class AiBlogTask extends Command @@ -84,9 +85,7 @@ class AiBlogTask extends Command
84 $aiBlogService->task_id = $item['task_id']; 85 $aiBlogService->task_id = $item['task_id'];
85 //拉取文章数据 86 //拉取文章数据
86 $result = $aiBlogService->getDetail(); 87 $result = $aiBlogService->getDetail();
87 -  
88 - // 获取失败  
89 - if(empty($result['status']) || $result['status'] != 200){ 88 + if(empty($result['status']) || ($result['status'] != 200)){
90 if($item['sort'] < 5){ 89 if($item['sort'] < 5){
91 $aiBlogTaskModel->edit(['sort'=>$item['sort'] + 1],['id'=>$item['id']]); 90 $aiBlogTaskModel->edit(['sort'=>$item['sort'] + 1],['id'=>$item['id']]);
92 }else{ 91 }else{
@@ -100,14 +99,13 @@ class AiBlogTask extends Command @@ -100,14 +99,13 @@ class AiBlogTask extends Command
100 ]; 99 ];
101 $dingService->handle($body); 100 $dingService->handle($body);
102 } 101 }
103 - $this->output('error: 数据获取失败,status:' . $result['status'] . ', message: ' . ($result['message'] ?? 'null')); 102 + $this->output('error: 数据获取失败,status:' . $result['status'] . ',message: ' . ($result['message'] ?? 'null'));
104 return false; 103 return false;
105 } 104 }
106 -  
107 //保存当前项目ai_blog数据 105 //保存当前项目ai_blog数据
108 ProjectServer::useProject($item['project_id']); 106 ProjectServer::useProject($item['project_id']);
109 $aiBlogModel = new AiBlog(); 107 $aiBlogModel = new AiBlog();
110 - $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']); 108 + $aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id','route']);
111 if($aiBlogInfo === false){ 109 if($aiBlogInfo === false){
112 // 钉钉通知 110 // 钉钉通知
113 $dingService = new DingService(); 111 $dingService = new DingService();
@@ -117,15 +115,18 @@ class AiBlogTask extends Command @@ -117,15 +115,18 @@ class AiBlogTask extends Command
117 'isAtAll' => false, // 是否@所有人 115 'isAtAll' => false, // 是否@所有人
118 ]; 116 ];
119 $dingService->handle($body); 117 $dingService->handle($body);
120 -  
121 $this->output('error: 子库获取数据失败, task id: ' . $task_id); 118 $this->output('error: 子库获取数据失败, task id: ' . $task_id);
122 $aiBlogTaskModel->edit(['status'=>9],['id'=>$item['id']]); 119 $aiBlogTaskModel->edit(['status'=>9],['id'=>$item['id']]);
123 DB::disconnect('custom_mysql'); 120 DB::disconnect('custom_mysql');
124 return false; 121 return false;
125 } 122 }
  123 + //需要更新的路由
126 if (!in_array($result['data']['author_id'], $this->updateProject[$item['project_id']] ?? [])) { 124 if (!in_array($result['data']['author_id'], $this->updateProject[$item['project_id']] ?? [])) {
127 $this->updateProject[$item['project_id']][] = $result['data']['author_id']; 125 $this->updateProject[$item['project_id']][] = $result['data']['author_id'];
128 } 126 }
  127 + if (!in_array($aiBlogInfo['route'], $this->routes[$item['project_id']] ?? [])) {
  128 + $this->routes[$item['project_id']][] = $aiBlogInfo['route'];
  129 + }
129 //拿到返回的路由查看是否重复 130 //拿到返回的路由查看是否重复
130 $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']); 131 $route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
131 if($route != $result['data']['url']){ 132 if($route != $result['data']['url']){
@@ -134,7 +135,6 @@ class AiBlogTask extends Command @@ -134,7 +135,6 @@ class AiBlogTask extends Command
134 $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'=>$aiBlogModel::STATUS_FINISH], ['task_id'=>$item['task_id']]); 135 $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'=>$aiBlogModel::STATUS_FINISH], ['task_id'=>$item['task_id']]);
135 DB::disconnect('custom_mysql'); 136 DB::disconnect('custom_mysql');
136 $aiBlogTaskModel->edit(['status'=>$aiBlogModel::STATUS_FINISH],['id'=>$item['id']]); 137 $aiBlogTaskModel->edit(['status'=>$aiBlogModel::STATUS_FINISH],['id'=>$item['id']]);
137 -  
138 $this->output('success: task id: ' . $task_id); 138 $this->output('success: task id: ' . $task_id);
139 return true; 139 return true;
140 } 140 }
@@ -152,6 +152,10 @@ class AiBlogTask extends Command @@ -152,6 +152,10 @@ class AiBlogTask extends Command
152 $this->updateProject($this->updateProject); 152 $this->updateProject($this->updateProject);
153 $this->updateProject = []; 153 $this->updateProject = [];
154 } 154 }
  155 + if(!empty($this->routes)){
  156 + $this->updateRoutes($this->routes);
  157 + $this->routes = [];
  158 + }
155 $aiBlogTaskModel = new AiBlogTaskModel(); 159 $aiBlogTaskModel = new AiBlogTaskModel();
156 $finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour')); 160 $finish_at = date('Y-m-d H:i:s', strtotime('-' . $finish_at . ' hour'));
157 $ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_BLOG, 'updated_at'=>['<=',$finish_at]])->pluck('id'); 161 $ids = $aiBlogTaskModel->formatQuery(['status'=>$aiBlogTaskModel::STATUS_RUNNING, 'type'=>$aiBlogTaskModel::TYPE_BLOG, 'updated_at'=>['<=',$finish_at]])->pluck('id');
@@ -174,7 +178,6 @@ class AiBlogTask extends Command @@ -174,7 +178,6 @@ class AiBlogTask extends Command
174 if(empty($updateProject)){ 178 if(empty($updateProject)){
175 return true; 179 return true;
176 } 180 }
177 -  
178 foreach ($updateProject as $project_id => $author){ 181 foreach ($updateProject as $project_id => $author){
179 ProjectServer::useProject($project_id); 182 ProjectServer::useProject($project_id);
180 $aiSettingInfo = $this->getSetting($project_id); 183 $aiSettingInfo = $this->getSetting($project_id);
@@ -184,11 +187,10 @@ class AiBlogTask extends Command @@ -184,11 +187,10 @@ class AiBlogTask extends Command
184 //更新作者 187 //更新作者
185 $this->output('sync: author start, project_id: ' . $project_id); 188 $this->output('sync: author start, project_id: ' . $project_id);
186 foreach ($author as $val){ 189 foreach ($author as $val){
187 - $this->updateAiBlogAuthor($aiSettingInfo,$val); 190 + $this->updateAiBlogAuthor($aiSettingInfo,$val,$project_id);
188 } 191 }
189 $this->output('sync: author end'); 192 $this->output('sync: author end');
190 DB::disconnect('custom_mysql'); 193 DB::disconnect('custom_mysql');
191 - $this->curlDelRoute($project_id);  
192 } 194 }
193 195
194 return true; 196 return true;
@@ -202,12 +204,11 @@ class AiBlogTask extends Command @@ -202,12 +204,11 @@ class AiBlogTask extends Command
202 public function getSetting($project_id) 204 public function getSetting($project_id)
203 { 205 {
204 $project_setting = $this->projectSetting; 206 $project_setting = $this->projectSetting;
205 - if (FALSE == empty($project_setting[$project_id])) 207 + if (FALSE == empty($project_setting[$project_id])){
206 return $project_setting[$project_id]; 208 return $project_setting[$project_id];
207 - 209 + }
208 $projectAiSettingModel = new ProjectAiSetting(); 210 $projectAiSettingModel = new ProjectAiSetting();
209 $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]); 211 $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
210 -  
211 $this->projectSetting[$project_id] = $aiSettingInfo; 212 $this->projectSetting[$project_id] = $aiSettingInfo;
212 return $aiSettingInfo; 213 return $aiSettingInfo;
213 } 214 }
@@ -218,7 +219,7 @@ class AiBlogTask extends Command @@ -218,7 +219,7 @@ class AiBlogTask extends Command
218 * @param $author_id 219 * @param $author_id
219 * @return bool 220 * @return bool
220 */ 221 */
221 - public function updateAiBlogAuthor($aiSettingInfo,$author_id){ 222 + public function updateAiBlogAuthor($aiSettingInfo,$author_id,$project_id){
222 if(empty($author_id)){ 223 if(empty($author_id)){
223 return true; 224 return true;
224 } 225 }
@@ -230,7 +231,12 @@ class AiBlogTask extends Command @@ -230,7 +231,12 @@ class AiBlogTask extends Command
230 if(isset($result['status']) && $result['status'] == 200){ 231 if(isset($result['status']) && $result['status'] == 200){
231 //当前作者的页面 232 //当前作者的页面
232 $aiBlogAuthorModel = new AiBlogAuthor(); 233 $aiBlogAuthorModel = new AiBlogAuthor();
233 - if(!empty($result['data']['section'])){ 234 + $authorInfo = $aiBlogAuthorModel->read(['author_id'=>$author_id],['id','route']);
  235 + if($authorInfo !== false && !empty($result['data']['section'])){
  236 + //需要更新的路由
  237 + if (!in_array($authorInfo['route'], $this->routes[$item['project_id']] ?? [])) {
  238 + $this->routes[$project_id][] = $authorInfo['route'];
  239 + }
234 $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]); 240 $aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
235 } 241 }
236 } 242 }
@@ -282,18 +288,17 @@ class AiBlogTask extends Command @@ -282,18 +288,17 @@ class AiBlogTask extends Command
282 * @param $project_id 288 * @param $project_id
283 * @return bool 289 * @return bool
284 */ 290 */
285 - public function curlDelRoute($project_id){ 291 + public function updateRoutes($routes){
286 $domainModel = new DomainInfo(); 292 $domainModel = new DomainInfo();
287 - //获取项目域名 293 + $project_model = new Project();
  294 + foreach ($routes as $project_id => $route){
  295 + $route[] = 'top-blog';
288 $domain = $domainModel->getProjectIdDomain($project_id); 296 $domain = $domainModel->getProjectIdDomain($project_id);
289 if (empty($domain)) { 297 if (empty($domain)) {
290 $this->output('send: 域名不存在, project id: ' . $project_id); 298 $this->output('send: 域名不存在, project id: ' . $project_id);
291 return true; 299 return true;
292 } 300 }
293 -  
294 -  
295 //判断是否是自建站服务器,如果是,不请求C端接口,数据直接入库 301 //判断是否是自建站服务器,如果是,不请求C端接口,数据直接入库
296 - $project_model = new Project();  
297 $project_info = $project_model->read(['id'=>$project_id],['serve_id']); 302 $project_info = $project_model->read(['id'=>$project_id],['serve_id']);
298 if(!$project_info){ 303 if(!$project_info){
299 $this->output('send: 项目不存在, project id: ' . $project_id); 304 $this->output('send: 项目不存在, project id: ' . $project_id);
@@ -313,21 +318,28 @@ class AiBlogTask extends Command @@ -313,21 +318,28 @@ class AiBlogTask extends Command
313 'status' => ['!=',Notify::STATUS_FINISH_SITEMAP] 318 'status' => ['!=',Notify::STATUS_FINISH_SITEMAP]
314 ]; 319 ];
315 $notify = $notify_model->read($data,['id']); 320 $notify = $notify_model->read($data,['id']);
316 -  
317 if(!$notify){ 321 if(!$notify){
318 $domain_array = parse_url($domain); 322 $domain_array = parse_url($domain);
319 - $data['data'] = Arr::a2s(['domain'=>$domain_array['host'],'url'=>[],'language'=>[]]); 323 + $data['data'] = Arr::a2s(['domain'=>$domain_array['host'],'url'=>$route,'language'=>[]]);
320 $data['status'] = Notify::STATUS_INIT; 324 $data['status'] = Notify::STATUS_INIT;
321 $data['sort'] = 2; 325 $data['sort'] = 2;
322 $notify_model->add($data); 326 $notify_model->add($data);
323 } 327 }
324 $this->output('send: 自建站项目, project id: ' . $project_id); 328 $this->output('send: 自建站项目, project id: ' . $project_id);
325 }else{ 329 }else{
326 - $url = $domain . 'api/update_page/?project_id='.$project_id.'&route=7';  
327 - $res = http_get($url); 330 + $c_url = $domain.'api/update_page/';
  331 + $param = [
  332 + 'project_id' => $project_id,
  333 + 'type' => 1,
  334 + 'route' => 3,
  335 + 'url' => $route,
  336 + 'language'=> [],
  337 + 'is_sitemap' => 0
  338 + ];
  339 + $res = http_post($c_url, json_encode($param,true));
328 $this->output('notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)); 340 $this->output('notify: project id: ' . $project_id . ', result: ' . json_encode($res,JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES));
329 } 341 }
330 - 342 + }
331 return true; 343 return true;
332 } 344 }
333 345