作者 lyh

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

<?php
use App\Helper\Translate;
use App\Models\File\Image;
use App\Models\File\File as FileModel;
use App\Models\Project\DeployOptimize;
... ... @@ -851,7 +852,7 @@ function getCustomRouteMap($module_route,$route = '')
* @method :post
* @time :2023/11/10 14:29
*/
function getRouteMap($source,$source_id,$is_upgrade = 0){
function getRouteMap($source,$source_id,$is_upgrade = 0, $returnModel = false){
$route = '';
$routeMapModel = new RouteMap();
$info = $routeMapModel->read(['source'=>$source,'source_id'=>$source_id]);
... ... @@ -878,6 +879,9 @@ function getRouteMap($source,$source_id,$is_upgrade = 0){
$route = $info['route'];
}
}
if($returnModel){
return $info;
}
return $route;
}
... ... @@ -1237,4 +1241,115 @@ function getDomain($url) {
}
/**
* 解析url的 route
* @param $pathInfo
* @return string
* @author zbj
* @date 2025/5/24
*/
function analysisRoute($pathInfo)
{
$language = '';
$router = "";
$page = null;
$pathArr = explode("/", $pathInfo);
$pathArr = array_filter($pathArr);
$first = array_shift($pathArr);
$last = array_pop($pathArr);
$other = implode("/", $pathArr);
$first = $first == "zh-ct" ? "zh-TW" : $first;
$tlsLang = array_keys(Translate::$tls_list);
if (in_array($first, $tlsLang)) {
$language = $first;
$first = '';
}
$lastIsRoute = RouteMap::select("id")->where("route", $last)->first();
if (is_numeric($last) && empty($lastIsRoute)) {
$page = $last;
$last = '';
}
$router_array = compact('first', 'other', 'last');
$router_array = array_filter($router_array);
//解析路由5.0 + 6.0
$keyword = new \App\Models\Product\Keyword();
$topSearchRoute = $keyword->product_keyword_route;
if (isset($router_array['first'])) {
if (isset($router_array['other'])) {
if ($router_array['other'] == "page") {
$router = $router_array['first'];
} else {
$otherArr = explode("/", $router_array['other']);
$otherArr = array_filter($otherArr);
if (count($otherArr) >= 1) {
$router = $otherArr[0];
}
}
} else {
if (isset($router_array['last'])) {
if (in_array($router_array['first'], $topSearchRoute)) {
$router = $router_array['first'];
$page = (int)$router_array['last'];
} else {
$router = $router_array['last'];
}
} else {
$router = $router_array['first'];
}
}
} else {
if (isset($router_array['last'])) {
if ($router_array['last'] != "page") {
if (isset($router_array['other']) && in_array($router_array['other'], $topSearchRoute)) {
$router = $router_array['other'];
$page = (int)$router_array['last'];
} else {
$router = $router_array['last'];
}
} else {
$otherArr = explode("/", $router_array['other']);
$otherArr = array_filter($otherArr);
if (count($otherArr) == 1) {
$router = $otherArr[0];
} else {
$router = $otherArr[1];
}
}
} else {
if (!empty($router_array)) {
$otherArr = explode("/", $router_array['other']);
$otherArr = array_filter($otherArr);
if (count($otherArr) == 3) {
$router = $otherArr[1];
} else {
$router = $otherArr[0];
}
}
}
}
//路由算法处理,路由只有一级,route_map表中route(规定),不考虑小语种
//新增考虑小语种,判断是否小语种访问,有页面不说,当nginx 404页面之后进程序,生成当前小语种页面
$lang = $language;
if ($page == null) {
if ($router != null) {
if ($lang != null) {
$tlsLang = array_keys(Translate::$tls_list);
$isLang = in_array($lang, $tlsLang);
if (!$isLang) {
$router = $lang;
}
}
} else {
$tlsLang = array_keys(Translate::$tls_list);
$isLang = in_array($lang, $tlsLang);
if (!$isLang) {
$router = $lang;
}
}
}
return $router;
}
... ...
... ... @@ -61,7 +61,9 @@ class ProductController extends BaseController
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);//获取模版id
$userModel = new User();
foreach ($lists['list'] as $k=>$v){
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id']);
$route = getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id'], 0, true);
$v['url'] = $this->user['domain'] . $route['route'];
$v['pv'] = $route['pv'];
$v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
$v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
$v['created_uid_text'] = $userModel->getName($v['created_uid']);
... ... @@ -97,7 +99,9 @@ class ProductController extends BaseController
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);//获取模版id
$userModel = new User();
foreach ($lists['list'] as $k=>$v){
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id']);
$route = getRouteMap(RouteMap::SOURCE_PRODUCT,$v['id'], 0, true);
$v['url'] = $this->user['domain'] . $route['route'];
$v['pv'] = $route['pv'];
$v['category_id_text'] = $this->categoryName($v['id'],$cate_data);
$v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
$v['created_uid_text'] = $userModel->getName($v['created_uid']);
... ...
... ... @@ -197,4 +197,35 @@ class Keyword extends Base
$string_key = array_search($first_title, $this->firstNumWord);
return $string_key ?: 27;
}
public $product_keyword_route = [
"top-search",
"top-search-a",
"top-search-b",
"top-search-c",
"top-search-d",
"top-search-e",
"top-search-f",
"top-search-g",
"top-search-h",
"top-search-i",
"top-search-j",
"top-search-k",
"top-search-l",
"top-search-m",
"top-search-n",
"top-search-o",
"top-search-p",
"top-search-q",
"top-search-r",
"top-search-s",
"top-search-t",
"top-search-u",
"top-search-v",
"top-search-w",
"top-search-x",
"top-search-y",
"top-search-z",
"top-search-0",
];
}
... ...
... ... @@ -13,6 +13,7 @@ use App\Models\Project\AutoEmail;
use App\Models\Project\AutoEmailLog;
use App\Models\Project\InquiryFilterConfig;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Subscribe\Email;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\Visit\Visit;
... ... @@ -20,6 +21,7 @@ use App\Models\WebSetting\WebLanguage;
use App\Models\Workchat\MessagePush;
use App\Utils\LogUtils;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\URL;
... ... @@ -337,6 +339,20 @@ class SyncSubmitTaskService
}
Visit::saveData($visit_data, $visit_data['updated_date']);
//pv
try {
$url_path = trim(parse_url($visit_data['url'], PHP_URL_PATH), '/');
if($url_path){
$route = analysisRoute($url_path);
$row = RouteMap::where('route', $route)->increment('pv');
if(!$row){
Log::channel('visit')->info('route not found:' . $visit_data['url'] );
}
}
}catch (\Exception $e){
Log::channel('visit')->info('pv inc error:' . $visit_data['url'], [$e->getMessage(), $e->getFile(), $e->getLine()]);
}
return true;
}
... ...
... ... @@ -191,6 +191,12 @@ return [
'level' => 'debug',
'days' => 14,
],
'visit' => [
'driver' => 'daily',
'path' => storage_path('logs/visit/laravel.log'),
'level' => 'debug',
'days' => 14,
],
'ai_blog' => [
'driver' => 'daily',
'path' => storage_path('logs/ai_blog/laravel.log'),
... ...