作者 赵彬吉

update

@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Models\Com; 10 namespace App\Models\Com;
11 11
12 use App\Models\Base; 12 use App\Models\Base;
  13 +use Illuminate\Support\Facades\Cache;
13 14
14 /** 15 /**
15 * @remark :国家信息 16 * @remark :国家信息
@@ -21,4 +22,14 @@ use App\Models\Base; @@ -21,4 +22,14 @@ use App\Models\Base;
21 class WordCountry extends Base 22 class WordCountry extends Base
22 { 23 {
23 protected $table = 'gl_world_country_city'; 24 protected $table = 'gl_world_country_city';
  25 +
  26 + public static function getCountryByIso2($iso2){
  27 + $key = 'getCountryByIso2_' . $iso2;
  28 + $info = Cache::get($key);
  29 + if (!$info) {
  30 + $info = self::where('pid', 0)->where('iso2', $iso2)->first();
  31 + Cache::put($key, $info, 24 * 3600);
  32 + }
  33 + return $info;
  34 + }
24 } 35 }
@@ -100,4 +100,17 @@ class WebLanguage extends Base @@ -100,4 +100,17 @@ class WebLanguage extends Base
100 return $this->hasOne(CountryCustom::class, 'language_id', 'id'); 100 return $this->hasOne(CountryCustom::class, 'language_id', 'id');
101 } 101 }
102 102
  103 +
  104 + public static function getShorts(){
  105 + $key = 'language_shorts';
  106 + $list = Cache::get($key);
  107 + if (!$list) {
  108 + $list = self::pluck('short')->toArray();
  109 + if($list){
  110 + Cache::put($key, $list, 24 * 3600);
  111 + }
  112 + }
  113 + return $list;
  114 + }
  115 +
103 } 116 }
@@ -4,6 +4,7 @@ @@ -4,6 +4,7 @@
4 namespace App\Services; 4 namespace App\Services;
5 5
6 use App\Exceptions\InquiryFilterException; 6 use App\Exceptions\InquiryFilterException;
  7 +use App\Models\Com\WordCountry;
7 use App\Models\Domain\CountryCode; 8 use App\Models\Domain\CountryCode;
8 use App\Models\Domain\DomainInfo; 9 use App\Models\Domain\DomainInfo;
9 use App\Models\Inquiry\InquiryForm; 10 use App\Models\Inquiry\InquiryForm;
@@ -15,6 +16,7 @@ use App\Models\Project\Project; @@ -15,6 +16,7 @@ use App\Models\Project\Project;
15 use App\Models\Subscribe\Email; 16 use App\Models\Subscribe\Email;
16 use App\Models\SyncSubmitTask\SyncSubmitTask; 17 use App\Models\SyncSubmitTask\SyncSubmitTask;
17 use App\Models\Visit\Visit; 18 use App\Models\Visit\Visit;
  19 +use App\Models\WebSetting\WebLanguage;
18 use App\Models\Workchat\MessagePush; 20 use App\Models\Workchat\MessagePush;
19 use App\Utils\LogUtils; 21 use App\Utils\LogUtils;
20 use Illuminate\Support\Facades\Cache; 22 use Illuminate\Support\Facades\Cache;
@@ -74,7 +76,24 @@ class SyncSubmitTaskService @@ -74,7 +76,24 @@ class SyncSubmitTaskService
74 } 76 }
75 } 77 }
76 } 78 }
77 - 79 + //$data['data']['referrer_url']为空 && 访问小语种 && 访问国家和IP所在国家不匹配 不记录数据
  80 + //$data['data']['referrer_url']为空 && 任何小语种 美国都不记
  81 + if (empty($data['data']['referrer_url']) && $task['type'] == 'visit') {
  82 + $tran_visit = '';
  83 + //是否是小语种 二级域名或二级目录
  84 + $langs = WebLanguage::getShorts();
  85 + foreach ($langs as $lang){
  86 + if(Str::contains($data['data']['url'], [$lang . '.' .$data['domain'], $data['domain'] . '/' . $lang. '/'])){
  87 + $tran_visit = $lang;
  88 + break;
  89 + }
  90 + }
  91 + //直接根据 语种缩写 去匹配 国家简码 不搞麻烦了,将就用
  92 + $tran_country = WordCountry::getCountryByIso2($tran_visit)['chinese_name'] ?? '';
  93 + if ($tran_visit !='en' && ($checkIpCountry['country'] == '美国' || $tran_country != $checkIpCountry['country'])) {
  94 + throw new InquiryFilterException( '判定为蜘蛛爬取小语种');
  95 + }
  96 + }
78 //域名 过滤国家或ip 97 //域名 过滤国家或ip
79 $domain_info = DomainInfo::getCacheInfoByProjectId($project['id']); 98 $domain_info = DomainInfo::getCacheInfoByProjectId($project['id']);
80 if(!empty($domain_info['not_allow_country'])){ 99 if(!empty($domain_info['not_allow_country'])){