作者 李宇航

合并分支 'master-server' 到 'master'

gx复制项目脚本



查看合并请求 !1333
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiBlogTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/2/14 11:14
  8 + */
  9 +
  10 +namespace App\Console\Commands\AiBlog;
  11 +
  12 +use App\Models\Ai\AiBlog;
  13 +use App\Models\Ai\AiBlogAuthor;
  14 +use App\Models\Ai\AiBlogList;
  15 +use App\Models\Project\ProjectAiSetting;
  16 +use App\Models\RouteMap\RouteMap;
  17 +use App\Services\AiBlogService;
  18 +use App\Services\ProjectServer;
  19 +use Illuminate\Console\Command;
  20 +use App\Models\Project\AiBlogTask as AiBlogTaskModel;
  21 +use Illuminate\Support\Facades\Cache;
  22 +use Illuminate\Support\Facades\DB;
  23 +use function Symfony\Component\String\s;
  24 +
  25 +class AiBlogListTask extends Command
  26 +{
  27 + /**
  28 + * The name and signature of the console command.
  29 + *
  30 + * @var string
  31 + */
  32 + protected $signature = 'save_ai_blog_list {project_id}';
  33 +
  34 + /**
  35 + * The console command description.
  36 + *
  37 + * @var string
  38 + */
  39 + protected $description = '生成blog列表';
  40 +
  41 + public function handle(){
  42 + $project_id = $this->argument('project_id');
  43 + ProjectServer::useProject($project_id);
  44 + $projectAiSettingModel = new ProjectAiSetting();
  45 + $aiSettingInfo = $projectAiSettingModel->read(['project_id'=>$this->user['project_id']]);
  46 + $this->updateBlogList($aiSettingInfo);
  47 + DB::disconnect('custom_mysql');
  48 + return true;
  49 + }
  50 +
  51 + /**
  52 + * @remark :更新列表页数据
  53 + * @name :updateBlogList
  54 + * @author :lyh
  55 + * @method :post
  56 + * @time :2025/3/5 11:07
  57 + */
  58 + public function updateBlogList($aiSettingInfo){
  59 + $aiBlogService = new AiBlogService();
  60 + $aiBlogService->mch_id = $aiSettingInfo['mch_id'];
  61 + $aiBlogService->key = $aiSettingInfo['key'];
  62 + $page = 1;
  63 + $saveData = [];
  64 + $result = $aiBlogService->getAiBlogList($page,15);
  65 + if(!isset($result['status']) && $result['status'] != 200){
  66 + return true;
  67 + }
  68 + $total_page = $result['data']['total_page'];
  69 + //组装数据保存
  70 + $saveData[] = [
  71 + 'route'=>$page,
  72 + 'text'=>$result['data']['section'],
  73 + ];
  74 + while ($total_page > $page){
  75 + $page++;
  76 + $result = $aiBlogService->getAiBlogList($page,15);
  77 + if(isset($result['status']) && $result['status'] == 200){
  78 + $saveData[] = [
  79 + 'route'=>$page,
  80 + 'text'=>$result['data']['section'],
  81 + ];
  82 + }
  83 + }
  84 + $aiBlogListModel = new AiBlogList();
  85 + if(!empty($saveData)){
  86 + //写一条路由信息
  87 + $aiBlogListModel->truncate();
  88 + $aiBlogListModel->insertAll($saveData);
  89 + }
  90 + return true;
  91 + }
  92 +}
@@ -387,7 +387,7 @@ class OptimizeController extends BaseController @@ -387,7 +387,7 @@ class OptimizeController extends BaseController
387 } 387 }
388 $url = $domain.'api/update_robots/?project_id='.$this->param['project_id']; 388 $url = $domain.'api/update_robots/?project_id='.$this->param['project_id'];
389 $res = curlGet($url); 389 $res = curlGet($url);
390 - if(empty($res) || $res['status'] != 200){ 390 + if(empty($res) || !isset($res['status']) || $res['status'] != 200){
391 $this->response('生成robots失败,请联系开发人员',Code::SYSTEM_ERROR,['url'=>$url]); 391 $this->response('生成robots失败,请联系开发人员',Code::SYSTEM_ERROR,['url'=>$url]);
392 } 392 }
393 $this->response('success',Code::SUCCESS,['url'=>$domain.'robots.txt']); 393 $this->response('success',Code::SUCCESS,['url'=>$domain.'robots.txt']);
@@ -131,8 +131,8 @@ class AiBlogLogic extends BaseLogic @@ -131,8 +131,8 @@ class AiBlogLogic extends BaseLogic
131 //删除路由映射 131 //删除路由映射
132 RouteMap::delRoute(RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']); 132 RouteMap::delRoute(RouteMap::SOURCE_AI_BLOG, $id, $this->user['project_id']);
133 $this->model->del(['id'=>$id]); 133 $this->model->del(['id'=>$id]);
134 - $this->updateBlogList($aiSettingInfo);  
135 } 134 }
  135 + shell_exec('php artisan save_ai_blog_list '.$this->user['project_id'].' > /dev/null 2>&1 &');
136 }catch (\Exception $e){ 136 }catch (\Exception $e){
137 $this->fail('删除失败'); 137 $this->fail('删除失败');
138 } 138 }
@@ -140,45 +140,4 @@ class AiBlogLogic extends BaseLogic @@ -140,45 +140,4 @@ class AiBlogLogic extends BaseLogic
140 } 140 }
141 141
142 142
143 - /**  
144 - * @remark :更新列表页数据  
145 - * @name :updateBlogList  
146 - * @author :lyh  
147 - * @method :post  
148 - * @time :2025/3/5 11:07  
149 - */  
150 - public function updateBlogList($aiSettingInfo){  
151 - $aiBlogService = new AiBlogService();  
152 - $aiBlogService->mch_id = $aiSettingInfo['mch_id'];  
153 - $aiBlogService->key = $aiSettingInfo['key'];  
154 - $page = 1;  
155 - $saveData = [];  
156 - $result = $aiBlogService->getAiBlogList($page,15);  
157 - if(!isset($result['status']) && $result['status'] != 200){  
158 - return true;  
159 - }  
160 - $total_page = $result['data']['total_page'];  
161 - //组装数据保存  
162 - $saveData[] = [  
163 - 'route'=>$page,  
164 - 'text'=>$result['data']['section'],  
165 - ];  
166 - while ($total_page > $page){  
167 - $page++;  
168 - $result = $aiBlogService->getAiBlogList($page,15);  
169 - if(isset($result['status']) && $result['status'] == 200){  
170 - $saveData[] = [  
171 - 'route'=>$page,  
172 - 'text'=>$result['data']['section'],  
173 - ];  
174 - }  
175 - }  
176 - $aiBlogListModel = new AiBlogList();  
177 - if(!empty($saveData)){  
178 - //写一条路由信息  
179 - $aiBlogListModel->truncate();  
180 - $aiBlogListModel->insertAll($saveData);  
181 - }  
182 - return true;  
183 - }  
184 } 143 }