|
...
|
...
|
@@ -41,52 +41,76 @@ class AiBlogTask extends Command |
|
|
|
public function handle(){
|
|
|
|
$aiBlogTaskModel = new AiBlogTaskModel();
|
|
|
|
while (true){
|
|
|
|
$info = $aiBlogTaskModel->where('status',1)->where('type',2)->inRandomOrder()->first();
|
|
|
|
if(empty($info)){
|
|
|
|
$list = $aiBlogTaskModel->list(['status'=>1,'type'=>2],'id',['*'],'asc',1000);
|
|
|
|
if(empty($list)){
|
|
|
|
sleep(300);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$info = $info->toArray();
|
|
|
|
echo '开始->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
//获取配置
|
|
|
|
$aiSettingInfo = $this->getSetting($info['project_id']);
|
|
|
|
$aiBlogService = new AiBlogService();
|
|
|
|
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
$aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
$aiBlogService->task_id = $info['task_id'];
|
|
|
|
$result = $aiBlogService->getDetail();
|
|
|
|
if(!isset($result['status'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if($result['status'] != 200){
|
|
|
|
sleep(10);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//保存当前项目ai_blog数据
|
|
|
|
ProjectServer::useProject($info['project_id']);
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$info['task_id']],['id']);
|
|
|
|
if($aiBlogInfo === false){
|
|
|
|
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
|
|
|
|
continue;
|
|
|
|
$updateProject = [];
|
|
|
|
foreach ($list as $item){
|
|
|
|
echo '开始->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
//获取配置
|
|
|
|
$aiSettingInfo = $this->getSetting($item['project_id']);
|
|
|
|
$aiBlogService = new AiBlogService();
|
|
|
|
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
$aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
$aiBlogService->task_id = $item['task_id'];
|
|
|
|
$result = $aiBlogService->getDetail();
|
|
|
|
if($result['status'] != 200){
|
|
|
|
sleep(10);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//保存当前项目ai_blog数据
|
|
|
|
ProjectServer::useProject($item['project_id']);
|
|
|
|
$aiBlogModel = new AiBlog();
|
|
|
|
$aiBlogInfo = $aiBlogModel->read(['task_id'=>$item['task_id']],['id']);
|
|
|
|
if($aiBlogInfo === false){
|
|
|
|
$aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!in_array($result['data']['author_id'], $updateProject[$item['project_id']] ?? [])) {
|
|
|
|
$updateProject[$item['project_id']][] = $result['data']['author_id'];
|
|
|
|
}
|
|
|
|
//拿到返回的路由查看是否重复
|
|
|
|
$route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $item['project_id']);
|
|
|
|
if($route != $result['data']['url']){
|
|
|
|
$aiBlogService->updateDetail(['route'=>$this->param['route']]);
|
|
|
|
}
|
|
|
|
$aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$item['task_id']]);
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
$aiBlogTaskModel->edit(['status'=>2],['id'=>$item['id']]);
|
|
|
|
}
|
|
|
|
//拿到返回的路由查看是否重复
|
|
|
|
$route = RouteMap::setRoute($result['data']['url'], RouteMap::SOURCE_AI_BLOG, $aiBlogInfo['id'], $info['project_id']);
|
|
|
|
if($route != $result['data']['url']){
|
|
|
|
$aiBlogService->updateDetail(['route'=>$this->param['route']]);
|
|
|
|
}
|
|
|
|
$aiBlogModel->edit(['new_title'=>$result['data']['title'], 'image'=>$result['data']['thumb'], 'text'=>$result['data']['section'], 'author_id'=>$result['data']['author_id'], 'route'=>$route ,'status'=>2], ['task_id'=>$info['task_id']]);
|
|
|
|
$this->updateAiBlogAuthor($aiSettingInfo,$result['data']['author_id']);
|
|
|
|
//TODO::更新列表页及作者
|
|
|
|
$this->updateProject($updateProject);
|
|
|
|
echo '结束->任务id:' . $item['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新项目作者页面及列表页
|
|
|
|
* @name :updateProject
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/4 10:25
|
|
|
|
*/
|
|
|
|
public function updateProject($updateProject){
|
|
|
|
if(empty($updateProject)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
foreach ($updateProject as $project_id => $author){
|
|
|
|
ProjectServer::useProject($project_id);
|
|
|
|
$aiSettingInfo = $this->getSetting($project_id);
|
|
|
|
$this->updateBlogList($aiSettingInfo);
|
|
|
|
//更新作者
|
|
|
|
foreach ($author as $val){
|
|
|
|
$this->updateAiBlogAuthor($aiSettingInfo,$val);
|
|
|
|
}
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
//修改任务状态
|
|
|
|
$aiBlogTaskModel->edit(['status'=>2],['id'=>$info['id']]);
|
|
|
|
echo '结束->任务id:' . $info['task_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取项目配置
|
|
|
|
* @name :getSetting
|
...
|
...
|
|