112 lines
3.9 KiB
PHP
112 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use App\Models\User;
|
|
use App\Models\Wechat;
|
|
use App\Models\Message;
|
|
use App\Utils\Messenger;
|
|
use App\Jobs\SendSmsBatch;
|
|
use App\Models\BadWord;
|
|
use App\Models\HandleLogs;
|
|
use App\Models\Moment;
|
|
use App\Models\VerifyLog;
|
|
use App\Services\CommonUtilsService;
|
|
use App\Services\UserService;
|
|
|
|
class AutomaticCheckBadWord extends Command
|
|
{
|
|
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'automatic_check_bad_word';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = '每天01.30 自动校验敏感词';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
|
|
try{
|
|
$t1=microtime(true);
|
|
$momentList = Moment::get();
|
|
$illegality_keyword = BadWord::get();
|
|
$violation_moment_list = [];
|
|
$violation_userinfo_list = [];
|
|
VerifyLog::where('id','>=','1')->delete();
|
|
foreach ($momentList as $m_i){
|
|
$res = \CommonUtilsService::verifyTextV2([$m_i->content],$illegality_keyword,1);
|
|
if($res['code'] != 1){
|
|
$violation_moment_list[] = $this->verifyStatisticsArray('moment',$m_i->id,$res['detail_context'],$res['code'],$res['type'],$res['context'],'content');
|
|
}
|
|
}
|
|
$userCount = User::where('type','signle')->count();
|
|
for($uc=0;$uc<=$userCount;$uc+=10000){
|
|
$thisUserCount = $uc;
|
|
$userList = User::with('profileCourtship')
|
|
->whereHas('profileCourtship', function ($sql){
|
|
$sql->where('introduction','<>','');
|
|
$sql->where('ideal_mate','<>','');
|
|
})
|
|
->where('type','single')
|
|
->limit(10000)
|
|
->offset($thisUserCount)
|
|
->get();
|
|
foreach ($userList as $u){
|
|
$introduction = $u->profileCourtship->introduction;
|
|
$ideal_mate = $u->profileCourtship->ideal_mate;
|
|
$res = \CommonUtilsService::verifyTextV2([$introduction],$illegality_keyword,1);
|
|
if($res['code'] != 1){
|
|
$violation_userinfo_list[] = $this->verifyStatisticsArray('user',$u->id,$res['detail_context'],$res['code'],$res['type'],$res['context'],'introduction');
|
|
}
|
|
$res = \CommonUtilsService::verifyTextV2([$ideal_mate],$illegality_keyword,1);
|
|
if($res['code'] != 1){
|
|
$violation_userinfo_list[] = $this->verifyStatisticsArray('user',$u->id,$res['detail_context'],$res['code'],$res['type'],$res['context'],'ideal_mate');
|
|
}
|
|
}
|
|
}
|
|
$data['violation_moment_list'] = $violation_moment_list;
|
|
$data['violation_userinfo_list'] = $violation_userinfo_list;
|
|
$HandleLogsData['elapsed_time']='耗时:'.(microtime(true)-$t1);
|
|
HandleLogs::add(1,'检验敏感词完成',$HandleLogsData,'log_sensitive_word');
|
|
} catch (\Exception $e) {
|
|
HandleLogs::add(2,'检验敏感词失败 ',$e->getMessage(),'log_sensitive_word');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
/***/
|
|
protected function verifyStatisticsArray($sourceType,$sourceId,$context,$errorCode,$errorType,$errorContext,$source_context_field){
|
|
VerifyLog::create([
|
|
'source_type'=>$sourceType,
|
|
'source_id'=>$sourceId,
|
|
'source_context'=>$context,
|
|
'source_context_field'=>$source_context_field,
|
|
'error_code'=>$errorCode,
|
|
'error_type'=>$errorType,
|
|
'error_context'=>$errorContext
|
|
]);
|
|
}
|
|
|
|
|
|
}
|