作者 lyh

Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6 into master-server

... ... @@ -199,17 +199,17 @@ class UpdateSeoTdk extends Command
}
$project_id = $task->project_id;
echo date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
echo getmypid() . ' ' . date('Y-m-d H:i:s') . ' start project_id: ' . $project_id . PHP_EOL;
try {
$this->project = ProjectServer::useProject($project_id);
$this->seo_tdk($project_id, $task->id);
DB::disconnect('custom_mysql');
}catch (\Exception $e){
echo date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
echo getmypid() . ' ' . date('Y-m-d H:i:s') . 'line: '. $e->getLine() .' error: ' . $project_id . '->' . $e->getMessage() . PHP_EOL;
ProjectUpdateTdk::retry($task->id, $e->getMessage());
}
Cache::forget('project_deploy_optimize_info_' . $project_id);
echo date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
echo getmypid() . ' ' . date('Y-m-d H:i:s') . ' end project_id: ' . $project_id . PHP_EOL;
}
}
public function sendNotify($project_id, $route)
... ... @@ -234,7 +234,7 @@ class UpdateSeoTdk extends Command
'language'=> [],
];
http_post($url, json_encode($param));
echo '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL;
echo getmypid() . ' ' . '更新中请稍后, 更新完成将会发送站内信通知更新结果!'. PHP_EOL;
}
public function seo_tdk($project_id, $task_id)
{
... ... @@ -246,7 +246,7 @@ class UpdateSeoTdk extends Command
foreach ($this->maps as $table => $map) {
$total_page = DB::connection('custom_mysql')->table($table)->count();
$update[$table] = ['total_page'=>$total_page, 'title'=>0, 'keyword'=>0, 'des'=>0,'keyword_title'=>0,'keyword_content'=>0];
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
echo getmypid() . ' ' . date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . PHP_EOL;
$list = DB::connection('custom_mysql')->table($table)
->where(function ($query) use ($table, $map){
if($table == 'gl_product'){
... ... @@ -280,7 +280,7 @@ class UpdateSeoTdk extends Command
}
echo date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
echo getmypid() . ' ' . date('Y-m-d H:i:s') . '更新--' . $table . ': 项目id' . $project_id . ':id' . $v['id'] . PHP_EOL;
$v = DB::connection('custom_mysql')->table($table)->where('id', $v['id'])->first();
$v = (array)$v;
$data = [];
... ... @@ -295,7 +295,7 @@ class UpdateSeoTdk extends Command
}
//已有值的 跳过
if ($value) {
echo $field.'已有值 跳过' . PHP_EOL;
echo getmypid() . ' ' . $field.'已有值 跳过' . PHP_EOL;
continue;
}
... ... @@ -423,7 +423,7 @@ class UpdateSeoTdk extends Command
if(strpos($prompt, '{topic}') !== false){
$topic = $data[$this->topic_fields[$table]] ?? '';
if(!$topic){
echo 'topic为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . 'topic为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{topic}', $topic, $prompt);
... ... @@ -432,7 +432,7 @@ class UpdateSeoTdk extends Command
if(strpos($prompt, '{keyword}') !== false) {
$keyword = $this->mainKeywords($project_id, 1);
if(!$keyword){
echo '核心关键词为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '核心关键词为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{keyword}', $keyword, $prompt);
... ... @@ -441,7 +441,7 @@ class UpdateSeoTdk extends Command
if(strpos($prompt, '{company name}') !== false) {
$company_name = $this->companyName($project_id);
if(!$company_name){
echo '公司英文全称为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '公司英文全称为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{company name}', $company_name, $prompt);
... ... @@ -450,7 +450,7 @@ class UpdateSeoTdk extends Command
if(strpos($prompt, '{company detail}') !== false) {
$company_detail = $this->companyName($project_id, 'company_detail');
if(!$company_detail){
echo '公司英文描述为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '公司英文描述为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{company detail}', $company_detail, $prompt);
... ... @@ -460,7 +460,7 @@ class UpdateSeoTdk extends Command
foreach ($matches[0] as $key=>$val) {
$keyword = $this->getPrefixKeyword($project_id, 'prefix', $matches[1][$key]);
if(!$keyword){
echo '前缀关键词为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '前缀关键词为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace($val, $keyword, $prompt);
... ... @@ -471,7 +471,7 @@ class UpdateSeoTdk extends Command
foreach ($matches[0] as $key=>$val) {
$keyword = $this->getPrefixKeyword($project_id, 'suffix', $matches[1][$key]);
if(!$keyword){
echo '前缀关键词为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '前缀关键词为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace($val, $keyword, $prompt);
... ... @@ -482,7 +482,7 @@ class UpdateSeoTdk extends Command
if(strpos($prompt, '{core keywords 8}') !== false) {
$main_keyword = $this->mainKeywords($project_id, 8);
if(!$main_keyword){
echo '核心关键词为空 跳过' . PHP_EOL;
echo getmypid() . ' ' . '核心关键词为空 跳过' . PHP_EOL;
return false;
}
$prompt = str_replace('{core keywords 8}', $main_keyword, $prompt);
... ... @@ -592,6 +592,8 @@ class UpdateSeoTdk extends Command
$text = Gpt::instance()->openai_chat_qqs($prompt);
if (!$text) {
echo getmypid() . ' ' . '生成失败' . PHP_EOL;
$cache_key = "ai_error_times_{$project_id}_{$table}_{$id}";
if (!Cache::get($cache_key)) {
Cache::put($cache_key, 0, 7 * 24 * 3600);
... ...
... ... @@ -37,7 +37,94 @@ class Temp extends Command
public function handle()
{
$this->check_cname_projects();
$this->change_cname_projects_240();
}
/**
* 240服务器上解析cname的项目迁移
* @author Akun
* @date 2025/02/17 14:21
*/
public function change_cname_projects_240()
{
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', 1)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain', 'amp_status']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain_id = $domain_info['id'];
$domain = $domain_info['domain'];
//迁移主站
$check = dns_get_record($domain, DNS_A);
$host = $check[0]['host'] ?? '';
if ($host == 'cname.globalso.com') {
//获取主站备份证书
$ssl_info = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $domain)->first();
if (!$ssl_info) {
$this->output('项目id:' . $project_id . ' | 未备份主站证书');
continue;
}
//创建主站建站任务
$task_info = DomainCreateTask::where('type', 1)->where('server_id', 20)->where('project_id', $project_id)->first();
if (!$task_info) {
$task_model = new DomainCreateTask();
$task_model->type = 1;
$task_model->server_id = 20;
$task_model->project_id = $project_id;
$task_model->domain_id = $domain_id;
$task_model->certs = json_encode(['key' => $ssl_info->private_key, 'csr' => $ssl_info->private_cert]);
$task_model->save();
}
}
if ($domain_info['amp_status'] == 1) {
//迁移amp站
$domain_array = parse_url($domain);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
$host_array[0] = 'm';
}
$amp_domain = implode('.', $host_array);
$check_amp = dns_get_record($amp_domain, DNS_A);
$host_amp = $check_amp[0]['host'] ?? '';
if ($host_amp == 'cname.globalso.com') {
//获取amp站备份证书
$ssl_info_amp = DB::table('gl_domain_ssl_backup')->select(['private_key', 'private_cert'])->where('domain', $amp_domain)->first();
if (!$ssl_info_amp) {
$this->output('项目id:' . $project_id . ' | 未备份amp站证书');
continue;
}
//创建amp站建站任务
$task_info_amp = DomainCreateTask::where('type', 2)->where('server_id', 20)->where('project_id', $project_id)->first();
if (!$task_info_amp) {
$task_model = new DomainCreateTask();
$task_model->type = 2;
$task_model->server_id = 20;
$task_model->project_id = $project_id;
$task_model->domain_id = $domain_id;
$task_model->certs = json_encode(['key' => $ssl_info_amp->private_key, 'csr' => $ssl_info_amp->private_cert]);
$task_model->save();
}
}
}
}
}
/**
... ... @@ -426,59 +513,6 @@ class Temp extends Command
}
/**
* 检查服务器上解析cname的项目
* @author Akun
* @date 2025/02/17 14:21
*/
public function check_cname_projects()
{
$server_id = 1;
$server_name = '硅谷云服务器';
$server_ip_model = new ServersIp();
$server_ip_ids = $server_ip_model->where('servers_id', $server_id)->get()->pluck('id')->toArray();
$project_list = Project::select(['id', 'serve_id', 'title'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$data = [];
foreach ($project_list as $value) {
$domain_info = $domain_model->read(['project_id' => $value->id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
$check = dns_get_record($domain, DNS_A);
$ip = $check[0]['ip'] ?? '';
$host = $check[0]['host'] ?? '';
if ($host == 'cname.globalso.com') {
$data[] = [
$value->id,
$value->title,
$domain,
$ip
];
}
}
$map = ['项目id', '名称', '域名', '解析IP'];
if ($data) {
$table = new BatchExportService($server_name . '解析cname的项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
} else {
$this->output('export success');
}
} else {
$this->output('no data');
}
}
/**
* 检查不在所属服务器解析上的域名
* @author Akun
* @date 2024/09/26 10:48
... ...
... ... @@ -75,6 +75,7 @@ class Gpt
$json = [];
}
} catch (\Throwable $e) {
Log::error('openai_chat_qqs data:', $data);
Log::error('openai_chat_qqs time ' . (time() - $time) . ' error:' . $e->getMessage());
$json = [];
}
... ...