作者 李宇航

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

Lyh server



查看合并请求 !2145
<?php
/**
* @remark :
* @name :AiDomainTask.php
* @author :lyh
* @method :post
* @time :2025/6/19 10:53
*/
namespace App\Console\Commands\Ai;
use App\Models\Domain\DomainInfo;
use Illuminate\Console\Command;
/**
* @remark :拉取项目Ai域名
* @name :AiDomainTask
* @author :lyh
* @method :post
* @time :2025/6/19 10:54
*/
class AiDomainTask extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'ai_domain';
/**
* The console command description.
*
* @var string
*/
protected $description = '获取对应域名的ai复制站域名';
public $url = 'https://www.cmer.site/api/globalso_site';
/**
* @remark :执行方法
* @name :handle
* @author :lyh
* @method :post
* @time :2025/6/19 11:32
*/
public function handle(){
$pageSize = 300;
$page = 1;
$res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
if($res['status'] != 200){
echo date('Y-m-d H:i:s').'请求失败,状态码错误'.PHP_EOL;
return false;
}
if(empty($res['data']['data'])){
echo date('Y-m-d H:i:s').'请求失败,未拉取到数据'.PHP_EOL;
return false;
}
$data = $res['data']['data'];
while($page <= $res['data']['last_page']){
$res = http_get($this->url.'?pagesize='.$pageSize.'&page='.$page);
if($res['status'] != 200){
echo date('Y-m-d H:i:s').'第'.$page.'请求失败,未拉取到数据'.PHP_EOL;
return false;
}
$data = array_values(array_merge($data,$res['data']['data']));
$page++;
}
//处理数据
$this->handleData($data);
echo 'end'.PHP_EOL;
return true;
}
/**
* @remark :处理数据
* @name :handleData
* @author :lyh
* @method :post
* @time :2025/6/19 11:21
*/
public function handleData($data){
$domainInfoModel = new DomainInfo();
foreach ($data as $item){
$info = $domainInfoModel->read(['domain'=>$item['domain']],'id');
if($info === false){
$info = $domainInfoModel->read(['domain'=>$item['globalso_domain']],'id');
if($info !== false){
$domainInfoModel->edit(['ai_domain'=>$item['domain']],['id'=>$info['id']]);
}
}else{
$domainInfoModel->edit(['ai_domain'=>$item['globalso_domain']],['id'=>$info['id']]);
}
}
return true;
}
}
... ...
... ... @@ -58,28 +58,7 @@ class lyhDemo extends Command
protected $description = '更新路由';
public function handle(){
$projectModel = new Project();
$buildModel = new DeployBuild();
$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']);
foreach ($lists as $item){
echo date('Y-m-d H:i:s') . '开始--项目的id:'. $item['id'] . PHP_EOL;
try {
if(!empty($item['notice_order_id'])){
$api = new OaGlobalsoApi();
$data = $api->order_info($item['notice_order_id']);
if(!empty($data)){
if(isset($data['data']['ads_price'])){
echo '奖励金额:'.$data['data']['ads_price'].PHP_EOL;
$buildModel->edit(['ads_price'=>$data['data']['ads_price'] ?? 0],['project_id'=>$item['id']]);
}
}
}
}catch (\Exception $e){
continue;
}
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . '结束。。。' . PHP_EOL;
}
public function _actionTemplateMain(){
... ...
... ... @@ -51,11 +51,12 @@ class GeneratePage extends Command
{
$noticeModel = new NoticeLog();
while (true){
$noticeInfo = $noticeModel->read(['status'=>0,'type'=>$noticeModel::GENERATE_PAGE,'start_at'=>['<=',date('Y-m-d H:i:s')]]);
$task_id = $this->getTaskId();
if (empty($noticeInfo)) {
sleep(10);
continue;
}
$noticeInfo = $noticeModel->read(['id'=>$task_id]);
try {
$this->output(' taskID: ' . $noticeInfo['id'] . ' start');
$notice_data = json_decode($noticeInfo['data'],true);
... ... @@ -80,6 +81,28 @@ class GeneratePage extends Command
return true;
}
/**
* @remark :获取任务id
* @name :getTaskId
* @author :lyh
* @method :post
* @time :2025/6/19 10:02
*/
public function getTaskId()
{
$task_id = Redis::rpop('generate_page_id');
if (empty($task_id)) {
$noticeModel = new NoticeLog();
$ids = $noticeModel->selectField(['status'=>0],'id');
if(!empty($ids)){
foreach ($ids as $id) {
Redis::lpush('generate_page_id', $id);
}
}
$task_id = Redis::rpop('generate_page_id');
}
return $task_id;
}
/**
* 输出message
... ...
... ... @@ -61,7 +61,7 @@ if (!function_exists('http_post')) {
* @param type $url
* @param type $post_data
*/
function http_post($url, $post_data, $header = [],$is_json = true)
function http_post($url, $post_data, $header = [],$is_json = true,$timeout = 60)
{
if (empty($header)) {
$header = array(
... ... @@ -73,6 +73,7 @@ if (!function_exists('http_post')) {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (compatible; MSIE 5.01; Windows NT 5.0)');
... ...
... ... @@ -262,6 +262,9 @@ class OptimizeController extends BaseController
if(isset($this->map['ai_video']) && !empty($this->map['ai_video'])){
$query = $query->where('gl_project_deploy_optimize.ai_video',$this->map['ai_video']);
}
if(isset($this->map['ai_domain']) && !empty($this->map['ai_domain'])){
$query = $query->whereNotNull('gl_project_association.ai_domain');
}
if(isset($this->map['amp_status'])){
$query = $query->where('gl_domain_info.amp_status',$this->map['amp_status']);
}
... ...
... ... @@ -123,7 +123,7 @@ class ProjectController extends BaseController
'gl_project_deploy_optimize.design_mid AS design_mid',
'gl_project_deploy_optimize.api_no AS api_no',
'gl_web_setting_template.template_id AS template_id',
'gl_project_association.friend_id as friend_id'
'gl_project_association.friend_id as friend_id',
];
return $select;
}
... ...
... ... @@ -301,9 +301,12 @@ class CNoticeController extends BaseController
'language'=> $language,
'is_sitemap' => $is_sitemap
];
// http_post($c_url, json_encode($c_param));
try {
http_post($c_url, json_encode($c_param));
}catch (\Exception $e){
NoticeLog::createLog(NoticeLog::GENERATE_PAGE, json_encode(['c_url'=>$c_url,'c_params'=>$c_param]));
}
}
$this->response('更新中请稍后, 更新完成将会发送站内信通知更新结果!');
}
... ...