作者 赵彬吉

update

... ... @@ -10,6 +10,7 @@
namespace App\Models\Com;
use App\Models\Base;
use Illuminate\Support\Facades\Cache;
/**
* @remark :国家信息
... ... @@ -21,4 +22,14 @@ use App\Models\Base;
class WordCountry extends Base
{
protected $table = 'gl_world_country_city';
public static function getCountryByIso2($iso2){
$key = 'getCountryByIso2_' . $iso2;
$info = Cache::get($key);
if (!$info) {
$info = self::where('pid', 0)->where('iso2', $iso2)->first();
Cache::put($key, $info, 24 * 3600);
}
return $info;
}
}
... ...
... ... @@ -100,4 +100,17 @@ class WebLanguage extends Base
return $this->hasOne(CountryCustom::class, 'language_id', 'id');
}
public static function getShorts(){
$key = 'language_shorts';
$list = Cache::get($key);
if (!$list) {
$list = self::pluck('short')->toArray();
if($list){
Cache::put($key, $list, 24 * 3600);
}
}
return $list;
}
}
... ...
... ... @@ -4,6 +4,7 @@
namespace App\Services;
use App\Exceptions\InquiryFilterException;
use App\Models\Com\WordCountry;
use App\Models\Domain\CountryCode;
use App\Models\Domain\DomainInfo;
use App\Models\Inquiry\InquiryForm;
... ... @@ -15,6 +16,7 @@ use App\Models\Project\Project;
use App\Models\Subscribe\Email;
use App\Models\SyncSubmitTask\SyncSubmitTask;
use App\Models\Visit\Visit;
use App\Models\WebSetting\WebLanguage;
use App\Models\Workchat\MessagePush;
use App\Utils\LogUtils;
use Illuminate\Support\Facades\Cache;
... ... @@ -74,7 +76,24 @@ class SyncSubmitTaskService
}
}
}
//$data['data']['referrer_url']为空 && 访问小语种 && 访问国家和IP所在国家不匹配 不记录数据
//$data['data']['referrer_url']为空 && 任何小语种 美国都不记
if (empty($data['data']['referrer_url']) && $task['type'] == 'visit') {
$tran_visit = '';
//是否是小语种 二级域名或二级目录
$langs = WebLanguage::getShorts();
foreach ($langs as $lang){
if(Str::contains($data['data']['url'], [$lang . '.' .$data['domain'], $data['domain'] . '/' . $lang. '/'])){
$tran_visit = $lang;
break;
}
}
//直接根据 语种缩写 去匹配 国家简码 不搞麻烦了,将就用
$tran_country = WordCountry::getCountryByIso2($tran_visit)['chinese_name'] ?? '';
if ($tran_visit !='en' && ($checkIpCountry['country'] == '美国' || $tran_country != $checkIpCountry['country'])) {
throw new InquiryFilterException( '判定为蜘蛛爬取小语种');
}
}
//域名 过滤国家或ip
$domain_info = DomainInfo::getCacheInfoByProjectId($project['id']);
if(!empty($domain_info['not_allow_country'])){
... ...