作者 赵彬吉

update

<?php
use App\Helper\Translate;
use App\Models\File\Image;
use App\Models\File\File as FileModel;
use App\Models\Project\DeployOptimize;
... ... @@ -1237,4 +1238,159 @@ function getDomain($url) {
}
/**
* 解析url的 route
* @param $pathInfo
* @return array
* @author zbj
* @date 2025/5/24
*/
function analysisRoute($pathInfo): array
{
$language = '';
$router = "";
$page = null;
$routeType = "";
$source = "";
if (strpos($pathInfo, '_catalog') !== false) {
$source = "module_category";
}
if (strpos($pathInfo, 'news_catalog') !== false) {
$source = "news_category";
}
if (strpos($pathInfo, 'blog_catalog') !== false) {
$source = "blog_category";
}
if (strpos($pathInfo, 'top-blog') !== false) {
$source = "ai_blog_list";
}
$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 = Translate::getTls();
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 ($router_array['first']) {
if ($router_array['first'] == "news" || $router_array['first'] == "blogs") {
$routeType = $router_array['first'];
}
if ($router_array['first'] == "user"){
$source = "ai_blog_author";
}
}
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 (isset($router_array['other'])) {
if ($router_array['other'] == "news" || $router_array['other'] == "blogs") {
$routeType = $router_array['other'];
}
}
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 = Translate::getTls();
$isLang = in_array($lang, $tlsLang);
if (!$isLang) {
$page = (int)$router;
$router = $lang;
$lang = "";
}
}
} else {
$tlsLang = Translate::getTls();
$isLang = in_array($lang, $tlsLang);
if (!$isLang) {
$router = $lang;
$lang = "";
}
}
}
if ($routeType == "news") {
$source = "news";
}
if ($routeType == "blogs") {
$source = "blog";
}
$routeArr["lang"] = $lang;
$routeArr["router"] = $router;
$routeArr["page"] = (int)$page;
$routeArr["routeType"] = $routeType;
$routeArr["source"] = $source;
return $routeArr;
}
... ...
... ... @@ -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'),
... ...