|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :AiBlogTask.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/2/14 11:14
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Console\Commands\AiBlog;
|
|
|
|
|
|
|
|
use App\Models\Ai\AiBlog;
|
|
|
|
use App\Models\Ai\AiBlogAuthor;
|
|
|
|
use App\Models\Project\ProjectAiSetting;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Services\AiBlogService;
|
|
|
|
use App\Services\ProjectServer;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
use App\Models\Project\AiBlogTask as AiBlogTaskModel;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
use function Symfony\Component\String\s;
|
|
|
|
|
|
|
|
class AiBlogListTask extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'save_ai_blog_list';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '查询ai_blog是否已经生成';
|
|
|
|
|
|
|
|
public function handle(){
|
|
|
|
$aiBlogTaskModel = new AiBlogTaskModel();
|
|
|
|
$lists = $aiBlogTaskModel->list(['type'=>3,'status'=>1]);
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
echo '开始->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
$projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$v['project_id']]);
|
|
|
|
if($aiSettingInfo === false){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$aiBlogService = new AiBlogService();
|
|
|
|
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
$aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
$page = 1;
|
|
|
|
$result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
if(!isset($result['status'])){
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
//保存当前项目ai_blog数据
|
|
|
|
ProjectServer::useProject($v['project_id']);
|
|
|
|
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
//修改任务状态
|
|
|
|
$aiBlogTaskModel->edit(['status'=>2],['id'=>$v['id']]);
|
|
|
|
echo '结束->->项目id:' . $v['project_id'] . PHP_EOL . date('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取项目配置
|
|
|
|
* @name :getSetting
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/2/14 11:27
|
|
|
|
*/
|
|
|
|
public function getSetting($project_id){
|
|
|
|
$ai_cache = Cache::get('ai_blog_'.$project_id);
|
|
|
|
if($ai_cache){
|
|
|
|
return $ai_cache;
|
|
|
|
}
|
|
|
|
$projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
Cache::put('ai_blog_'.$project_id,$aiSettingInfo,3600);
|
|
|
|
return $aiSettingInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新作者的页面
|
|
|
|
* @name :updateAiBlogAuthor
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/2/21 11:53
|
|
|
|
*/
|
|
|
|
public function updateAiBlogAuthor($aiSettingInfo,$author_id){
|
|
|
|
if(empty($author_id)){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$aiBlogService = new AiBlogService();
|
|
|
|
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
$aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
$aiBlogService->author_id = $author_id;
|
|
|
|
$result = $aiBlogService->getAuthorDetail();
|
|
|
|
if(isset($result['status']) && $result['status'] == 200){
|
|
|
|
//当前作者的页面
|
|
|
|
$aiBlogAuthorModel = new AiBlogAuthor();
|
|
|
|
if(!empty($result['data']['section'])){
|
|
|
|
$aiBlogAuthorModel->edit(['text'=>$result['data']['section']],['author_id'=>$author_id]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|