作者 李宇航

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

Lyh server



查看合并请求 !2145
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :AiDomainTask.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2025/6/19 10:53
  8 + */
  9 +
  10 +namespace App\Console\Commands\Ai;
  11 +
  12 +use App\Models\Domain\DomainInfo;
  13 +use Illuminate\Console\Command;
  14 +
  15 +/**
  16 + * @remark :拉取项目Ai域名
  17 + * @name :AiDomainTask
  18 + * @author :lyh
  19 + * @method :post
  20 + * @time :2025/6/19 10:54
  21 + */
  22 +class AiDomainTask extends Command
  23 +{
  24 + /**
  25 + * The name and signature of the console command.
  26 + *
  27 + * @var string
  28 + */
  29 + protected $signature = 'ai_domain';
  30 +
  31 + /**
  32 + * The console command description.
  33 + *
  34 + * @var string
  35 + */
  36 + protected $description = '获取对应域名的ai复制站域名';
  37 +
  38 + public $url = 'https://www.cmer.site/api/globalso_site';
  39 +
  40 + /**
  41 + * @remark :执行方法
  42 + * @name :handle
  43 + * @author :lyh
  44 + * @method :post
  45 + * @time :2025/6/19 11:32
  46 + */
  47 + public function handle(){
  48 + $pageSize = 300;
  49 + $page = 1;
  50 + $res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
  51 + if($res['status'] != 200){
  52 + echo date('Y-m-d H:i:s').'请求失败,状态码错误'.PHP_EOL;
  53 + return false;
  54 + }
  55 + if(empty($res['data']['data'])){
  56 + echo date('Y-m-d H:i:s').'请求失败,未拉取到数据'.PHP_EOL;
  57 + return false;
  58 + }
  59 + $data = $res['data']['data'];
  60 + while($page <= $res['data']['last_page']){
  61 + $res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
  62 + if($res['status'] != 200){
  63 + echo date('Y-m-d H:i:s').'第'.$page.'请求失败,未拉取到数据'.PHP_EOL;
  64 + return false;
  65 + }
  66 + $data = array_values(array_merge($data,$res['data']['data']));
  67 + $page++;
  68 + }
  69 + //处理数据
  70 + $this->handleData($data);
  71 + echo 'end'.PHP_EOL;
  72 + return true;
  73 + }
  74 +
  75 + /**
  76 + * @remark :处理数据
  77 + * @name :handleData
  78 + * @author :lyh
  79 + * @method :post
  80 + * @time :2025/6/19 11:21
  81 + */
  82 + public function handleData($data){
  83 + $domainInfoModel = new DomainInfo();
  84 + foreach ($data as $item){
  85 + $info = $domainInfoModel->read(['domain'=>$item['domain']],'id');
  86 + if($info === false){
  87 + $info = $domainInfoModel->read(['domain'=>$item['globalso_domain']],'id');
  88 + if($info !== false){
  89 + $domainInfoModel->edit(['ai_domain'=>$item['domain']],['id'=>$info['id']]);
  90 + }
  91 + }else{
  92 + $domainInfoModel->edit(['ai_domain'=>$item['globalso_domain']],['id'=>$info['id']]);
  93 + }
  94 + }
  95 + return true;
  96 + }
  97 +}
@@ -58,28 +58,7 @@ class lyhDemo extends Command @@ -58,28 +58,7 @@ class lyhDemo extends Command
58 protected $description = '更新路由'; 58 protected $description = '更新路由';
59 59
60 public function handle(){ 60 public function handle(){
61 - $projectModel = new Project();  
62 - $buildModel = new DeployBuild();  
63 - $lists = $projectModel->list(['delete_status' => 0,'project_type'=>0,'is_upgrade'=>0,'id'=>['<',1659],'extend_type'=>0,'type'=>['in',[1,2,3,4,6]]], 'id', ['id','notice_order_id']);  
64 - foreach ($lists as $item){  
65 - echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['id'] . PHP_EOL;  
66 - try {  
67 - if(!empty($item['notice_order_id'])){  
68 - $api = new OaGlobalsoApi();  
69 - $data = $api->order_info($item['notice_order_id']);  
70 - if(!empty($data)){  
71 - if(isset($data['data']['ads_price'])){  
72 - echo '奖励金额:'.$data['data']['ads_price'].PHP_EOL;  
73 - $buildModel->edit(['ads_price'=>$data['data']['ads_price'] ?? 0],['project_id'=>$item['id']]);  
74 - }  
75 - }  
76 - }  
77 - }catch (\Exception $e){  
78 - continue;  
79 - }  
80 - DB::disconnect('custom_mysql');  
81 - }  
82 - echo date('Y-m-d H:i:s') . '结束。。。' . PHP_EOL; 61 +
83 } 62 }
84 63
85 public function _actionTemplateMain(){ 64 public function _actionTemplateMain(){
@@ -51,11 +51,12 @@ class GeneratePage extends Command @@ -51,11 +51,12 @@ class GeneratePage extends Command
51 { 51 {
52 $noticeModel = new NoticeLog(); 52 $noticeModel = new NoticeLog();
53 while (true){ 53 while (true){
54 - $noticeInfo = $noticeModel->read(['status'=>0,'type'=>$noticeModel::GENERATE_PAGE,'start_at'=>['<=',date('Y-m-d H:i:s')]]); 54 + $task_id = $this->getTaskId();
55 if (empty($noticeInfo)) { 55 if (empty($noticeInfo)) {
56 sleep(10); 56 sleep(10);
57 continue; 57 continue;
58 } 58 }
  59 + $noticeInfo = $noticeModel->read(['id'=>$task_id]);
59 try { 60 try {
60 $this->output(' taskID: ' . $noticeInfo['id'] . ' start'); 61 $this->output(' taskID: ' . $noticeInfo['id'] . ' start');
61 $notice_data = json_decode($noticeInfo['data'],true); 62 $notice_data = json_decode($noticeInfo['data'],true);
@@ -80,6 +81,28 @@ class GeneratePage extends Command @@ -80,6 +81,28 @@ class GeneratePage extends Command
80 return true; 81 return true;
81 } 82 }
82 83
  84 + /**
  85 + * @remark :获取任务id
  86 + * @name :getTaskId
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2025/6/19 10:02
  90 + */
  91 + public function getTaskId()
  92 + {
  93 + $task_id = Redis::rpop('generate_page_id');
  94 + if (empty($task_id)) {
  95 + $noticeModel = new NoticeLog();
  96 + $ids = $noticeModel->selectField(['status'=>0],'id');
  97 + if(!empty($ids)){
  98 + foreach ($ids as $id) {
  99 + Redis::lpush('generate_page_id', $id);
  100 + }
  101 + }
  102 + $task_id = Redis::rpop('generate_page_id');
  103 + }
  104 + return $task_id;
  105 + }
83 106
84 /** 107 /**
85 * 输出message 108 * 输出message
@@ -61,7 +61,7 @@ if (!function_exists('http_post')) { @@ -61,7 +61,7 @@ if (!function_exists('http_post')) {
61 * @param type $url 61 * @param type $url
62 * @param type $post_data 62 * @param type $post_data
63 */ 63 */
64 - function http_post($url, $post_data, $header = [],$is_json = true) 64 + function http_post($url, $post_data, $header = [],$is_json = true,$timeout = 60)
65 { 65 {
66 if (empty($header)) { 66 if (empty($header)) {
67 $header = array( 67 $header = array(
@@ -73,6 +73,7 @@ if (!function_exists('http_post')) { @@ -73,6 +73,7 @@ if (!function_exists('http_post')) {
73 curl_setopt($ch, CURLOPT_URL, $url); 73 curl_setopt($ch, CURLOPT_URL, $url);
74 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); 74 curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
75 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 75 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  76 + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
76 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 77 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
77 curl_setopt($ch, CURLOPT_HTTPHEADER, $header); 78 curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
78 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)'); 79 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
@@ -262,6 +262,9 @@ class OptimizeController extends BaseController @@ -262,6 +262,9 @@ class OptimizeController extends BaseController
262 if(isset($this->map['ai_video']) && !empty($this->map['ai_video'])){ 262 if(isset($this->map['ai_video']) && !empty($this->map['ai_video'])){
263 $query = $query->where('gl_project_deploy_optimize.ai_video',$this->map['ai_video']); 263 $query = $query->where('gl_project_deploy_optimize.ai_video',$this->map['ai_video']);
264 } 264 }
  265 + if(isset($this->map['ai_domain']) && !empty($this->map['ai_domain'])){
  266 + $query = $query->whereNotNull('gl_project_association.ai_domain');
  267 + }
265 if(isset($this->map['amp_status'])){ 268 if(isset($this->map['amp_status'])){
266 $query = $query->where('gl_domain_info.amp_status',$this->map['amp_status']); 269 $query = $query->where('gl_domain_info.amp_status',$this->map['amp_status']);
267 } 270 }
@@ -123,7 +123,7 @@ class ProjectController extends BaseController @@ -123,7 +123,7 @@ class ProjectController extends BaseController
123 'gl_project_deploy_optimize.design_mid AS design_mid', 123 'gl_project_deploy_optimize.design_mid AS design_mid',
124 'gl_project_deploy_optimize.api_no AS api_no', 124 'gl_project_deploy_optimize.api_no AS api_no',
125 'gl_web_setting_template.template_id AS template_id', 125 'gl_web_setting_template.template_id AS template_id',
126 - 'gl_project_association.friend_id as friend_id' 126 + 'gl_project_association.friend_id as friend_id',
127 ]; 127 ];
128 return $select; 128 return $select;
129 } 129 }
@@ -301,8 +301,11 @@ class CNoticeController extends BaseController @@ -301,8 +301,11 @@ class CNoticeController extends BaseController
301 'language'=> $language, 301 'language'=> $language,
302 'is_sitemap' => $is_sitemap 302 'is_sitemap' => $is_sitemap
303 ]; 303 ];
304 -// http_post($c_url, json_encode($c_param));  
305 - NoticeLog::createLog(NoticeLog::GENERATE_PAGE, json_encode(['c_url'=>$c_url,'c_params'=>$c_param])); 304 + try {
  305 + http_post($c_url, json_encode($c_param));
  306 + }catch (\Exception $e){
  307 + NoticeLog::createLog(NoticeLog::GENERATE_PAGE, json_encode(['c_url'=>$c_url,'c_params'=>$c_param]));
  308 + }
306 } 309 }
307 $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!'); 310 $this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
308 } 311 }