作者 赵彬吉

update

1 <?php 1 <?php
2 2
  3 +use App\Helper\Translate;
3 use App\Models\File\Image; 4 use App\Models\File\Image;
4 use App\Models\File\File as FileModel; 5 use App\Models\File\File as FileModel;
5 use App\Models\Project\DeployOptimize; 6 use App\Models\Project\DeployOptimize;
@@ -1237,4 +1238,159 @@ function getDomain($url) { @@ -1237,4 +1238,159 @@ function getDomain($url) {
1237 } 1238 }
1238 1239
1239 1240
  1241 +/**
  1242 + * 解析url的 route
  1243 + * @param $pathInfo
  1244 + * @return array
  1245 + * @author zbj
  1246 + * @date 2025/5/24
  1247 + */
  1248 +function analysisRoute($pathInfo): array
  1249 +{
  1250 + $language = '';
  1251 + $router = "";
  1252 + $page = null;
  1253 + $routeType = "";
  1254 + $source = "";
  1255 +
  1256 + if (strpos($pathInfo, '_catalog') !== false) {
  1257 + $source = "module_category";
  1258 + }
  1259 + if (strpos($pathInfo, 'news_catalog') !== false) {
  1260 + $source = "news_category";
  1261 + }
  1262 + if (strpos($pathInfo, 'blog_catalog') !== false) {
  1263 + $source = "blog_category";
  1264 + }
  1265 + if (strpos($pathInfo, 'top-blog') !== false) {
  1266 + $source = "ai_blog_list";
  1267 + }
  1268 +
  1269 + $pathArr = explode("/", $pathInfo);
  1270 + $pathArr = array_filter($pathArr);
  1271 + $first = array_shift($pathArr);
  1272 + $last = array_pop($pathArr);
  1273 + $other = implode("/", $pathArr);
  1274 +
  1275 + $first = $first == "zh-ct" ? "zh-TW" : $first;
  1276 + $tlsLang = Translate::getTls();
  1277 + if (in_array($first, $tlsLang)) {
  1278 + $language = $first;
  1279 + $first = '';
  1280 + }
  1281 + $lastIsRoute = RouteMap::select("id")->where("route", $last)->first();
  1282 + if (is_numeric($last) && empty($lastIsRoute)) {
  1283 + $page = $last;
  1284 + $last = '';
  1285 + }
  1286 + $router_array = compact('first', 'other', 'last');
  1287 + $router_array = array_filter($router_array);
  1288 +
  1289 + //解析路由5.0 + 6.0
  1290 + $keyword = new \App\Models\Product\Keyword();
  1291 + $topSearchRoute = $keyword->product_keyword_route;
  1292 + if (isset($router_array['first'])) {
  1293 + if (isset($router_array['other'])) {
  1294 + if ($router_array['other'] == "page") {
  1295 + $router = $router_array['first'];
  1296 + } else {
  1297 + $otherArr = explode("/", $router_array['other']);
  1298 + $otherArr = array_filter($otherArr);
  1299 + if (count($otherArr) >= 1) {
  1300 + $router = $otherArr[0];
  1301 + }
  1302 + }
  1303 + } else {
  1304 + if (isset($router_array['last'])) {
  1305 + if ($router_array['first']) {
  1306 + if ($router_array['first'] == "news" || $router_array['first'] == "blogs") {
  1307 + $routeType = $router_array['first'];
  1308 + }
  1309 + if ($router_array['first'] == "user"){
  1310 + $source = "ai_blog_author";
  1311 + }
  1312 + }
  1313 + if (in_array($router_array['first'], $topSearchRoute)) {
  1314 + $router = $router_array['first'];
  1315 + $page = (int)$router_array['last'];
  1316 + } else {
  1317 + $router = $router_array['last'];
  1318 + }
  1319 + } else {
  1320 + $router = $router_array['first'];
  1321 + }
  1322 + }
  1323 + } else {
  1324 + if (isset($router_array['last'])) {
  1325 + if (isset($router_array['other'])) {
  1326 + if ($router_array['other'] == "news" || $router_array['other'] == "blogs") {
  1327 + $routeType = $router_array['other'];
  1328 + }
  1329 + }
  1330 + if ($router_array['last'] != "page") {
  1331 + if (isset($router_array['other']) && in_array($router_array['other'], $topSearchRoute)) {
  1332 + $router = $router_array['other'];
  1333 + $page = (int)$router_array['last'];
  1334 + } else {
  1335 + $router = $router_array['last'];
  1336 + }
  1337 + } else {
  1338 + $otherArr = explode("/", $router_array['other']);
  1339 + $otherArr = array_filter($otherArr);
  1340 + if (count($otherArr) == 1) {
  1341 + $router = $otherArr[0];
  1342 + } else {
  1343 + $router = $otherArr[1];
  1344 + }
  1345 + }
  1346 + } else {
  1347 + if (!empty($router_array)) {
  1348 + $otherArr = explode("/", $router_array['other']);
  1349 + $otherArr = array_filter($otherArr);
  1350 + if (count($otherArr) == 3) {
  1351 + $router = $otherArr[1];
  1352 + } else {
  1353 + $router = $otherArr[0];
  1354 + }
  1355 + }
  1356 + }
  1357 + }
1240 1358
  1359 + //路由算法处理,路由只有一级,route_map表中route(规定),不考虑小语种
  1360 + //新增考虑小语种,判断是否小语种访问,有页面不说,当nginx 404页面之后进程序,生成当前小语种页面
  1361 + $lang = $language;
  1362 + if ($page == null) {
  1363 + if ($router != null) {
  1364 + if ($lang != null) {
  1365 + $tlsLang = Translate::getTls();
  1366 + $isLang = in_array($lang, $tlsLang);
  1367 + if (!$isLang) {
  1368 + $page = (int)$router;
  1369 + $router = $lang;
  1370 + $lang = "";
  1371 + }
  1372 + }
  1373 + } else {
  1374 + $tlsLang = Translate::getTls();
  1375 + $isLang = in_array($lang, $tlsLang);
  1376 + if (!$isLang) {
  1377 + $router = $lang;
  1378 + $lang = "";
  1379 + }
  1380 + }
  1381 + }
  1382 +
  1383 + if ($routeType == "news") {
  1384 + $source = "news";
  1385 + }
  1386 + if ($routeType == "blogs") {
  1387 + $source = "blog";
  1388 + }
  1389 +
  1390 + $routeArr["lang"] = $lang;
  1391 + $routeArr["router"] = $router;
  1392 + $routeArr["page"] = (int)$page;
  1393 + $routeArr["routeType"] = $routeType;
  1394 + $routeArr["source"] = $source;
  1395 + return $routeArr;
  1396 +}
@@ -197,4 +197,35 @@ class Keyword extends Base @@ -197,4 +197,35 @@ class Keyword extends Base
197 $string_key = array_search($first_title, $this->firstNumWord); 197 $string_key = array_search($first_title, $this->firstNumWord);
198 return $string_key ?: 27; 198 return $string_key ?: 27;
199 } 199 }
  200 +
  201 + public $product_keyword_route = [
  202 + "top-search",
  203 + "top-search-a",
  204 + "top-search-b",
  205 + "top-search-c",
  206 + "top-search-d",
  207 + "top-search-e",
  208 + "top-search-f",
  209 + "top-search-g",
  210 + "top-search-h",
  211 + "top-search-i",
  212 + "top-search-j",
  213 + "top-search-k",
  214 + "top-search-l",
  215 + "top-search-m",
  216 + "top-search-n",
  217 + "top-search-o",
  218 + "top-search-p",
  219 + "top-search-q",
  220 + "top-search-r",
  221 + "top-search-s",
  222 + "top-search-t",
  223 + "top-search-u",
  224 + "top-search-v",
  225 + "top-search-w",
  226 + "top-search-x",
  227 + "top-search-y",
  228 + "top-search-z",
  229 + "top-search-0",
  230 + ];
200 } 231 }
@@ -13,6 +13,7 @@ use App\Models\Project\AutoEmail; @@ -13,6 +13,7 @@ use App\Models\Project\AutoEmail;
13 use App\Models\Project\AutoEmailLog; 13 use App\Models\Project\AutoEmailLog;
14 use App\Models\Project\InquiryFilterConfig; 14 use App\Models\Project\InquiryFilterConfig;
15 use App\Models\Project\Project; 15 use App\Models\Project\Project;
  16 +use App\Models\RouteMap\RouteMap;
16 use App\Models\Subscribe\Email; 17 use App\Models\Subscribe\Email;
17 use App\Models\SyncSubmitTask\SyncSubmitTask; 18 use App\Models\SyncSubmitTask\SyncSubmitTask;
18 use App\Models\Visit\Visit; 19 use App\Models\Visit\Visit;
@@ -20,6 +21,7 @@ use App\Models\WebSetting\WebLanguage; @@ -20,6 +21,7 @@ use App\Models\WebSetting\WebLanguage;
20 use App\Models\Workchat\MessagePush; 21 use App\Models\Workchat\MessagePush;
21 use App\Utils\LogUtils; 22 use App\Utils\LogUtils;
22 use Illuminate\Support\Facades\Cache; 23 use Illuminate\Support\Facades\Cache;
  24 +use Illuminate\Support\Facades\DB;
23 use Illuminate\Support\Facades\Http; 25 use Illuminate\Support\Facades\Http;
24 use Illuminate\Support\Facades\Log; 26 use Illuminate\Support\Facades\Log;
25 use Illuminate\Support\Facades\URL; 27 use Illuminate\Support\Facades\URL;
@@ -337,6 +339,20 @@ class SyncSubmitTaskService @@ -337,6 +339,20 @@ class SyncSubmitTaskService
337 } 339 }
338 Visit::saveData($visit_data, $visit_data['updated_date']); 340 Visit::saveData($visit_data, $visit_data['updated_date']);
339 341
  342 + //pv
  343 + try {
  344 + $url_path = trim(parse_url($visit_data['url'], PHP_URL_PATH), '/');
  345 + if($url_path){
  346 + $route = analysisRoute($url_path);
  347 + $row = RouteMap::where('route', $route)->increment('pv');
  348 + if(!$row){
  349 + Log::channel('visit')->info('route not found:' . $visit_data['url'] );
  350 + }
  351 + }
  352 + }catch (\Exception $e){
  353 + Log::channel('visit')->info('pv inc error:' . $visit_data['url'], [$e->getMessage(), $e->getFile(), $e->getLine()]);
  354 + }
  355 +
340 return true; 356 return true;
341 } 357 }
342 358
@@ -191,6 +191,12 @@ return [ @@ -191,6 +191,12 @@ return [
191 'level' => 'debug', 191 'level' => 'debug',
192 'days' => 14, 192 'days' => 14,
193 ], 193 ],
  194 + 'visit' => [
  195 + 'driver' => 'daily',
  196 + 'path' => storage_path('logs/visit/laravel.log'),
  197 + 'level' => 'debug',
  198 + 'days' => 14,
  199 + ],
194 'ai_blog' => [ 200 'ai_blog' => [
195 'driver' => 'daily', 201 'driver' => 'daily',
196 'path' => storage_path('logs/ai_blog/laravel.log'), 202 'path' => storage_path('logs/ai_blog/laravel.log'),