input('name'); if(empty($name)){ return $this->failure('请输入敏感词类型名字'); } $badWordType = new BadWordType(); $res = $badWordType->where('name',$name)->first(); if($res){ return $this->failure('不能添加重复类型'); } $badWordType->name = $name; $badWordType->operator = auth()->id(); $badWordType->save(); return $this->success('ok'); } /** 修改 敏感词类型 名字 */ public function updateBadwordType(Request $request){ $id = $request->input('id'); $badWordType = new BadWordType(); $badWordTypeData = $badWordType->where('id',$id)->first(); if (empty($badWordTypeData)) return $this->failure('敏感词类型不存在'); if (empty($request->name)) return $this->failure('请输入敏感词'); if ($request->name && $request->name != $badWordTypeData->name) { $badWordTypeData->name = $request->name; } $badWordTypeData->operator = auth()->id(); $badWordTypeData->save(); return $this->success('ok',$badWordTypeData); } /** 删除 敏感词类型 */ public function deleteBadwordType(Request $request){ $id = $request->input('id',0); $status = $request->input('status',1); $badWordType = BadWordType::find($id); if (empty($badWordType)) return $this->failure('敏感词类型不存在'); $badWordType->delete();//删除类型 也删除类型对应的敏感词 BadWord::where('bad_word_type_id',$id)->delete(); return $this->success('ok'); } /** 列表 敏感词类型 */ public function pagingBadwordType(Request $request){ $keyword = $request->input('keyword'); $size = $request->input('size',15); $badWordType = new BadWordType(); $badWordType_list = $badWordType::with('user:id,nickname,app_avatar,circle_avatar') ->whereHas('user')->orderBy('id','desc'); if ($keyword) { $keyword = trim($keyword); $badWordType_list = $badWordType_list->whereHas('user',function($sql) use($keyword){ $sql->where('id',$keyword)->orWhere('nickname','like','%'.$keyword.'%'); }); } $badWordType_list = $badWordType_list->paginate($size); return $this->success('ok',$badWordType_list); } /** 开始校验 */ public function startVerifyAll(Request $request){ $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; $r = '耗时:'.(microtime(true)-$t1); return $this->success('完成',[$r]); } /**敏感词 校验记录 */ public function verifyLogList(Request $request){ $source_type = $request->input('source_type','user'); if ($source_type == 'user') { $verify_logsList = VerifyLog::with('user')->where('source_type',$source_type)->paginate()->toArray(); }else{ $verify_logsList = VerifyLog::where('source_type',$source_type)->paginate()->toArray(); } $verify_logs = $verify_logsList['data']; for($v = 0;$vsuccess('',$verify_logsList); } /***/ 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 ]); } }