|
|
|
<?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\Ai\AiBlogList;
|
|
|
|
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 {project_id}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = '生成blog列表';
|
|
|
|
|
|
|
|
public function handle(){
|
|
|
|
$project_id = $this->argument('project_id');
|
|
|
|
ProjectServer::useProject($project_id);
|
|
|
|
$projectAiSettingModel = new ProjectAiSetting();
|
|
|
|
$aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$project_id]);
|
|
|
|
$this->updateBlogList($aiSettingInfo);
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :更新列表页数据
|
|
|
|
* @name :updateBlogList
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2025/3/5 11:07
|
|
|
|
*/
|
|
|
|
public function updateBlogList($aiSettingInfo){
|
|
|
|
$aiBlogService = new AiBlogService();
|
|
|
|
$aiBlogService->mch_id = $aiSettingInfo['mch_id'];
|
|
|
|
$aiBlogService->key = $aiSettingInfo['key'];
|
|
|
|
$page = 1;
|
|
|
|
$saveData = [];
|
|
|
|
$result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
if(!isset($result['status']) && $result['status'] != 200){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
$total_page = $result['data']['total_page'];
|
|
|
|
//组装数据保存
|
|
|
|
$saveData[] = [
|
|
|
|
'route'=>$page,
|
|
|
|
'text'=>$result['data']['section'],
|
|
|
|
];
|
|
|
|
while ($total_page > $page){
|
|
|
|
$page++;
|
|
|
|
$result = $aiBlogService->getAiBlogList($page,15);
|
|
|
|
if(isset($result['status']) && $result['status'] == 200){
|
|
|
|
$saveData[] = [
|
|
|
|
'route'=>$page,
|
|
|
|
'text'=>$result['data']['section'],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$aiBlogListModel = new AiBlogList();
|
|
|
|
if(!empty($saveData)){
|
|
|
|
//写一条路由信息
|
|
|
|
$aiBlogListModel->truncate();
|
|
|
|
$aiBlogListModel->insertAll($saveData);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|