作者 lyh

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

... ... @@ -63,13 +63,18 @@ class TemplateLog extends Command
* @time :2024/7/10 14:48
*/
public function deleteTemplate(){
$date = date('Y-m-d H:i:s', strtotime('-60 days'));
$date = date('Y-m-d H:i:s', strtotime('-30 days'));
$templateLogModel = new BTemplateLog();
$templateLogModel->del(['created_at'=>['<=',$date],'source'=>['!=',1]]);
//首页保存最新的20条记录
$latestIds = $templateLogModel->where(['source'=>1,'is_custom'=>0])->orderBy('created_at', 'desc')->take(20)->pluck('id'); // 仅提取ID字段
return $templateLogModel->del(['id'=>['not in',$latestIds],'source'=>1,'is_custom'=>0,'is_list'=>0]);
//查询最近20天是否有装修记录,首页保存最新的20条记录
$counts = $templateLogModel->counts(['source'=>1,'source_id'=>0,'is_custom'=>0,'created_at'=>['>=',$date]]);
if($counts == 0){
$latestIds = $templateLogModel->where(['source'=>1,'is_custom'=>0])->orderBy('created_at', 'desc')->take(20)->pluck('id'); // 仅提取ID字段
$templateLogModel->del(['id'=>['not in',$latestIds],'source'=>1,'is_custom'=>0,'is_list'=>0]);
}else{
$templateLogModel->del(['created_at'=>['<=',$date],'source'=>1]);
}
return true;
}
/**
... ...
... ... @@ -102,10 +102,10 @@ class DomainInfo extends Command
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
if($host_array[0] == 'www'){
$host_array[0] = 'm';
}else{
array_unshift($host_array,'m');
}
$amp_domain = implode('.', $host_array);
... ... @@ -192,10 +192,10 @@ class DomainInfo extends Command
$domain_array = parse_url($v['domain']);
$host = $domain_array['host'] ?? $domain_array['path'];
$host_array = explode('.', $host);
if (count($host_array) <= 2) {
array_unshift($host_array, 'm');
} else {
if($host_array[0] == 'www'){
$host_array[0] = 'm';
}else{
array_unshift($host_array,'m');
}
$amp_domain = implode('.', $host_array);
... ...
... ... @@ -6,6 +6,7 @@ use App\Helper\Arr;
use App\Helper\Common;
use App\Helper\Gpt;
use App\Models\Ai\AiCommand;
use App\Models\Ai\AiTdkErrorLog;
use App\Models\Com\UpdateNotify;
use App\Models\Domain\DomainInfo;
use App\Models\Mail\Mail;
... ... @@ -271,6 +272,14 @@ class UpdateSeoTdk extends Command
}
Redis::expire($cache_key, 120);
//连续3次失败的 不再处理
$error_log = AiTdkErrorLog::getLog($project_id, $table, $v['id']);
if($error_log){
continue;
}
echo 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;
... ... @@ -304,7 +313,7 @@ class UpdateSeoTdk extends Command
}elseif ($field_arr[1] == 'description'){
$update[$table]['des']++;
}
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt);
$data[$field_arr[0]][$field_arr[1]] = $this->ai_send($prompt, $project_id, $table, $v['id']);
}else{
if($field == 'title' || $field == 'seo_title'){
$update[$table]['title']++;
... ... @@ -321,7 +330,7 @@ class UpdateSeoTdk extends Command
if($field == 'keyword_content'){
$update[$table]['keyword_content']++;
}
$data[$field] = $this->ai_send($prompt);
$data[$field] = $this->ai_send($prompt, $project_id, $table, $v['id']);
}
} else {
//直接使用topic
... ... @@ -499,15 +508,29 @@ class UpdateSeoTdk extends Command
* @method :post
* @time :2023/8/19 10:40
*/
public function ai_send($prompt)
public function ai_send($prompt, $project_id, $table, $id)
{
$text = Gpt::instance()->openai_chat_qqs($prompt);
if (!$text) {
$cache_key = "ai_error_times_{$project_id}_{$table}_{$id}";
if (!Cache::get($cache_key)) {
Cache::put($cache_key, 0, 7 * 24 * 3600);
}
$times = Cache::increment($cache_key);
//3次错误 记录下来 后面不处理了
if ($times > 2) {
AiTdkErrorLog::insertLog($project_id, $table, $id, $prompt);
Cache::forget($cache_key);
}
}
$text = Common::deal_keywords($text);
$text = Common::deal_str($text);
//包含这写字 重新生成
if(Str::contains(Str::lower($text), ['[your brand]', '[brand name]'])){
return $this->ai_send($prompt);
return $this->ai_send($prompt, $project_id, $table, $id);
}
return $text;
... ...
... ... @@ -126,65 +126,6 @@ class Temp extends Command
}
/**
* 创建指定服务器所有项目主站生成任务
* @author Akun
* @date 2024/12/19 17:54
*/
public function create_server_update_page()
{
$server_id = 15;
$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'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => $server_id,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
$this->output('项目id:' . $project_id . ' | success');
}
}
}
/**
* 判断指定服务器项目是否正常访问
* @author Akun
* @date 2024/12/11 10:15
... ... @@ -272,6 +213,7 @@ class Temp extends Command
public function get_all_projects_by_server()
{
$server_id = 1;
$server_name = '240云服务器';
$server_ip_model = new ServersIp();
... ... @@ -297,7 +239,7 @@ class Temp extends Command
}
$map = ['项目id', '名称', '域名'];
if ($data) {
$table = new BatchExportService("240云服务器项目");
$table = new BatchExportService($server_name . '项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
... ... @@ -371,6 +313,7 @@ class Temp extends Command
public function check_no_server_projects()
{
$server_id = 15;
$server_name = '美服1';
$server_ip_model = new ServersIp();
... ... @@ -403,7 +346,7 @@ class Temp extends Command
}
$map = ['项目id', '名称', '域名', 'IP', '服务器ID',];
if ($data) {
$table = new BatchExportService("美服2项目解析未在当前服务器项目");
$table = new BatchExportService($server_name . '解析未在当前服务器项目');
$file = $table->head($map)->data($data)->save();
if (!$file) {
$this->output('文件生成失败,请重试');
... ... @@ -416,6 +359,65 @@ class Temp extends Command
}
/**
* 创建指定服务器所有项目主站生成任务
* @author Akun
* @date 2024/12/19 17:54
*/
public function create_server_update_page()
{
$server_id = 15;
$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'])->whereIn('serve_id', $server_ip_ids)->get();
$domain_model = new DomainInfo();
$notify_model = new Notify();
foreach ($project_list as $value) {
$project_id = $value->id;
$domain_info = $domain_model->read(['project_id' => $project_id, 'status' => 1], ['id', 'domain']);
if (!$domain_info) {
//过滤未绑定正式域名的项目
continue;
}
$domain = $domain_info['domain'];
//获取项目所在服务器
$serve_ip_info = $server_ip_model->read(['id' => $value->serve_id], ['domain', 'ip']);
if (!$serve_ip_info) {
$this->output('项目id:' . $project_id . ' | 未查询到服务器数据');
continue;
}
if (!check_domain_record($domain, $serve_ip_info)) {
$this->output('项目id:' . $project_id . ', domain:' . $domain . ' | 未解析到目标服务器');
continue;
}
$data = [
'project_id' => $project_id,
'type' => 1,
'route' => 1,
'server_id' => $server_id,
'status' => ['!=', Notify::STATUS_FINISH_SITEMAP]
];
$notify = $notify_model->read($data, ['id']);
if (!$notify) {
$data['data'] = Arr::a2s(['domain' => $domain, 'url' => null, 'language' => []]);
$data['status'] = Notify::STATUS_INIT;
$notify_model->add($data);
$this->output('项目id:' . $project_id . ' | success');
}
}
}
/**
* 创建所有amp站页面生成任务
* @author Akun
* @date 2024/09/26 10:48
... ... @@ -435,10 +437,10 @@ class Temp extends Command
$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 {
if ($host_array[0] == 'www') {
$host_array[0] = 'm';
} else {
array_unshift($host_array, 'm');
}
$amp_domain = implode('.', $host_array);
... ...
... ... @@ -93,7 +93,7 @@ class OptimizationReportController extends BaseController
'data' => array_values($indexed_pages['data'] ?? []),
];
//月统计报告
$data['month_count'] = $this->currentMonthCount($domain_info['domain'],$this->param['project_id']);
$data['month_count'] = $this->currentMonthCount($this->param['project_id']);
//测速
$speed = Speed::where('project_id', $this->param['project_id'])->first();
$data['speed'] = $speed['data'] ?? [];
... ... @@ -110,107 +110,30 @@ class OptimizationReportController extends BaseController
* @method :post
* @time :2023/7/3 9:55
*/
public function currentMonthCount($domain,$project_id){
// 获取当前月的开始时间
$startTime = date('Y-m-01', strtotime($this->param['date']));
// 获取当前月的结束时间
$endTime = date('Y-m-t', strtotime($this->param['date']));
public function currentMonthCount($project_id){
$arr = [];
$arr = $this->inquiryCount($arr,$startTime,$endTime,$domain,$project_id);
$arr = $this->flowCount($arr,$startTime,$endTime,$project_id);
$arr = $this->sourceCount($arr,$startTime,$endTime,$domain);
$arr['month'] = date('Y-m',time());
return $arr;
}
/**
* @param $domain
* @param $project_id
* @remark :询盘按月统计
* @name :inquiryCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:29
*/
public function inquiryCount(&$arr, &$startTime, $project_id){
$month = date('Y-m',strtotime($startTime));
$date = date('Y-m', strtotime($this->param['date']));
$monthCountModel = new MonthCount();
$info = $monthCountModel->read(['project_id'=>$project_id,'month'=>$month]);
if($info !== false){
$arr['country'] = $info['country'];
$arr['total'] = $info['total'];
$arr['month_total'] = $info['month_total'];
}
return $arr;
}
/**
* @remark :流量统计
* @name :flowCount
* @author :lyh
* @method :post
* @time :2023/6/30 14:31
*/
public function flowCount(&$arr,&$startTime,&$endTime,$project_id){
$pv_ip = DB::table('gl_count')
->where(['project_id'=>$project_id])
->whereBetween('date', [$startTime,$endTime])
->select(DB::raw('SUM(pv_num) as pv_num'), DB::raw('SUM(ip_num) as ip_num'))
->orderBy('id','desc')
->first();
$arr['pv'] = $pv_ip->pv_num;
$arr['ip'] = $pv_ip->ip_num;
$arr['rate'] = 0;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,2);
$month_info = $monthCountModel->read(['project_id'=>$project_id,'month'=>$date]);
if($month_info !== false){
$arr['country'] = $month_info['country'];
$arr['total'] = $month_info['total'];
$arr['month_total'] = $month_info['month_total'];
$arr['pv'] = $month_info['pv'];
$arr['ip'] = $month_info['ip'];
$arr['rate'] = 0;
if($arr['ip'] != 0){
$arr['rate'] = round(($arr['month_total'] / $arr['ip']) * 100,2);
}
$arr['source'] = json_decode($month_info['source'],true);
$arr['source_country'] = json_decode($month_info['source_country'],true);
$arr['referrer_url'] = json_decode($month_info['referrer_url'],true);
$arr['referrer_port'] = json_decode($month_info['referrer_port'],true);
}
$arr['month'] = date('Y-m',time());
return $arr;
}
/**
* @remark :来源访问前8
* @name :sourceCount
* @author :lyh
* @method :post
* @time :2023/6/30 16:14
*/
public function sourceCount(&$arr,$startTime,$endTime,$domain){
//访问来源前10
$source = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('referrer_url', DB::raw('COUNT(*) as count'))
->groupBy('referrer_url')
->where('referrer_url','!=','')
->whereBetween('updated_date', [$startTime,$endTime])
->orderByDesc('count')->limit(10)->get()->toArray();
$arr['source'] = $source;
//访问国家前15
$query = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('country',DB::raw('COUNT(*) as ip'),DB::raw('SUM(depth) as pv'))
->groupBy('country');
$query->where('country','<>','中国');
$source_country = $query->whereBetween('updated_date', [$startTime,$endTime])
->orderBy('ip','desc')->limit(15)->get()->toArray();
$arr['source_country'] = $source_country;
//受访界面前15
$referrer_url = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('url',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('url')
->limit(15)->get()->toArray();
$arr['referrer_url'] = $referrer_url;
//访问断后
$referrer_port = DB::connection('custom_mysql')->table('gl_customer_visit')
->select('device_port',DB::raw('COUNT(*) as num'))
->orderBy('num','desc')
->whereBetween('updated_date', [$startTime,$endTime])
->groupBy('device_port')
->limit(15)->get()->toArray();
$arr['referrer_port'] = $referrer_port;
return $arr;
}
public function getApiList($projectInfo,$export = false)
{
... ...
... ... @@ -61,13 +61,18 @@ class CNoticeController extends BaseController
],[
'language.required' => 'language不能为空',
]);
$project_id_arr = explode(',',env('PROJECT_ID')) ?? [];
if(in_array($this->user['project_id'],$project_id_arr)){
$this->response('success');
}
$lang_num = count($this->param['language']);
$keyword_num = (new Keyword())->counts(['route'=>['!=',null]]);
$data_num = $this->productNum() + $this->CustomNum() + $this->newsNum() + $this->blogNum();
$number = $keyword_num * 18 + $lang_num * $data_num;
if($number >= 45000){
$this->response('success',Code::SUCCESS,['msg'=>'翻译数量过多, 大概页面数量:'.$number.', 磁盘空间占用可能会超过40G,请谨慎使用!']);
if($number >= 450000){
$this->response('success',Code::SUCCESS,['msg'=>'翻译数量过多, 大概页面数量:'.$number.', 磁盘空间占用可能会超过40G,请联系管理员操作!']);
}
//? Copyright - 2010-2024 : All Rights Reserved.© Copyright - 2010-2024 : All Rights Reserved.
$this->response('success');
}
... ...
... ... @@ -88,7 +88,6 @@ class MonthReportController extends BaseController
])->count();
$info['service_duration'] = $this->user['service_duration'];//服务天数
$info['ip_total'] = (new Visit())->count();//ip总数
$info['remain_day'] = $this->user['remain_day'];//剩余服务天数
$info['speed'] = round((0.3 + mt_rand()/mt_getrandmax() * (1-0.3)),2);
$info['month_total'] = (int)$info['month_total'];
... ...
... ... @@ -12,6 +12,7 @@ use App\Http\Logic\Bside\Product\ProductLogic;
use App\Http\Requests\Bside\Product\ProductRequest;
use App\Models\Product\Category;
use App\Models\Product\CategoryRelated;
use App\Models\Product\Detail;
use App\Models\Product\Extend;
use App\Models\Product\ExtendInfo;
use App\Models\Product\Keyword;
... ... @@ -678,7 +679,11 @@ class ProductController extends BaseController
$new_content = htmlentities($contents);
}
if (!empty($new_content)){
$productInfo['content'] = $new_content . $productInfo['content'];
$detailModel = new Detail();
$detailInfo = $detailModel->read(['column_id'=>1]);
if($detailInfo !== false && !empty($detailInfo['content'])){
$productInfo['content'] = $new_content . $detailInfo['content']['content'];
}
}
$this->response('success',Code::SUCCESS,$productInfo);
}
... ...
... ... @@ -263,6 +263,7 @@ class UserLoginLogic
$info['upload_config'] = $project['upload_config'];
$info['main_lang_id'] = $project['main_lang_id'];
$info['image_max'] = $project['image_max'];
$info['is_del_inquiry'] = $project['is_del_inquiry'] ?? 0;
$info['uptime_type'] = $this->getHistory($project);
$info['uptime'] = $project['uptime'];
$info['is_update_language'] = $project['is_update_language'];
... ...
<?php
namespace App\Models\Ai;
use App\Models\Base;
class AiTdkErrorLog extends Base
{
//设置关联表名
protected $table = 'gl_ai_tdk_error_log';
//自动维护create_at创建时间 updated_at修改时间
public $timestamps = true;
public static function insertLog($project_id, $table, $table_id, $prompt){
$model = new self();
$model->project_id = $project_id;
$model->table_name = $table;
$model->table_id = $table_id;
$model->prompt = $prompt;
$model->save();
}
public static function getLog($project_id, $table, $table_id){
return self::where('project_id', $project_id)->where('table_name', $table)->where('table_id', $table_id)->first();
}
}
... ...