ReportController.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Extensions\Tools\DialogTool;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\AuditReason;
  6. use App\Models\Company;
  7. use App\Models\Jobs;
  8. use App\Models\Member;
  9. use App\Models\MemberInfo;
  10. use App\Models\Report;
  11. use App\Models\Resume;
  12. use App\Models\Subsite;
  13. use App\Services\Common\PmsService;
  14. use App\Services\Common\TaskService;
  15. use Encore\Admin\Admin as js_Admin;
  16. use Encore\Admin\Controllers\HasResourceActions;
  17. use Encore\Admin\Facades\Admin;
  18. use Encore\Admin\Form;
  19. use Encore\Admin\Grid;
  20. use Encore\Admin\Grid\Filter;
  21. use Encore\Admin\Layout\Content;
  22. use Encore\Admin\Show;
  23. use Illuminate\Http\Request;
  24. use Illuminate\Support\Facades\Cache;
  25. class ReportController extends Controller
  26. {
  27. use HasResourceActions;
  28. protected $taskService;
  29. protected $pmsService;
  30. /**
  31. * ReportController constructor.
  32. * @param $taskService
  33. * @param $pmsService
  34. */
  35. public function __construct(TaskService $taskService, PmsService $pmsService)
  36. {
  37. $this->taskService = $taskService;
  38. $this->pmsService = $pmsService;
  39. }
  40. /**
  41. * Index interface.
  42. *
  43. * @param Content $content
  44. * @return Content
  45. */
  46. public function index(Content $content)
  47. {
  48. return $content
  49. ->header('举报信息')
  50. ->description(' ')
  51. //->body($this->grid());
  52. ->body(view('admin.content.report')->with(['grid'=>$this->grid()]));
  53. }
  54. /**
  55. * Show interface.
  56. *
  57. * @param mixed $id
  58. * @param Content $content
  59. * @return Content
  60. */
  61. public function show($id, Content $content)
  62. {
  63. return $content
  64. ->header('Detail')
  65. ->description('description')
  66. ->body($this->detail($id));
  67. }
  68. /**
  69. * Edit interface.
  70. *
  71. * @param mixed $id
  72. * @param Content $content
  73. * @return Content
  74. */
  75. public function edit($id, Content $content)
  76. {
  77. return $content
  78. ->header('Edit')
  79. ->description('description')
  80. ->body($this->form()->edit($id));
  81. }
  82. /**
  83. * Create interface.
  84. *
  85. * @param Content $content
  86. * @return Content
  87. */
  88. public function create(Content $content)
  89. {
  90. return $content
  91. ->header('Create')
  92. ->description('description')
  93. ->body($this->form());
  94. }
  95. public function reportTypes(Request $request)
  96. {
  97. $q = $request->input('q')?$request->input('q'):1;
  98. $report_reasons = Report::getReportTypes($q);
  99. $report_reasons = array(''=>'不限') + $report_reasons;
  100. $reasons = array();
  101. foreach ($report_reasons as $k => $v) {
  102. $reasons[] = array('id'=>$k,'text'=>$v);
  103. }
  104. return collect($reasons);
  105. }
  106. protected function grid()
  107. {
  108. $grid = new Grid(new Report);
  109. if (get_subsite_id() != 0) {
  110. $where['subsite_id'] = get_subsite_id();
  111. $grid->model()->where($where)->orderBy('audit', 'asc')->orderBy('created_at', 'desc');
  112. } else {
  113. $grid->model()->orderBy('audit', 'asc')->orderBy('created_at', 'desc');
  114. }
  115. /*$grid->model()->orderBy('audit', 'asc')->orderBy('created_at', 'desc');*/
  116. /*$grid->utype_realname('投诉职位/投诉简历')->limit(20);*/
  117. $grid->utype_realname('投诉职位/投诉简历')->display(function () {
  118. return '<span class="vtip" title="'.$this->utype_realname.'">'.cut_str($this->utype_realname, 15, 0, "...").'</span>';
  119. })->width(200);
  120. $grid->utype('举报类型')->display(function () {
  121. return $this->utype==1?'职位':'简历';
  122. });
  123. $grid->audit('核实情况')->display(function () {
  124. if ($this->audit == '1') {
  125. return '<span style="color:#ff0000;">未核实</span><input type="hidden" name="report_audit_status" id="report_'.$this->id.'" value="1"/>';
  126. } elseif ($this->audit=='2') {
  127. return '属实<input type="hidden" name="report_audit_status" id="report_'.$this->id.'" value="2"/>';
  128. } elseif ($this->audit=='3') {
  129. return '不属实<input type="hidden" name="report_audit_status" id="report_'.$this->id.'" value="3"/>';
  130. }
  131. });
  132. $grid->type_id('举报原因');
  133. $grid->content('举报内容')->display(function () {
  134. return '<span class="vtip" title="'.$this->content.'">'.cut_str($this->content, 30, 0, "...").'</span>';
  135. })->width(250);
  136. $grid->username('举报对象');
  137. if(get_subsite_open()){
  138. $grid->subsite_id('所属分站')->display(function () {
  139. $subsites = Cache::get('subsites_list');
  140. if (array_has($subsites, $this->subsite_id)) {
  141. return $subsites[$this->subsite_id]['sitename'];
  142. }
  143. return '';
  144. });
  145. }
  146. $grid->created_at('举报时间');
  147. $grid->actions(function ($actions) {
  148. /*$actions->disableEdit();*/
  149. if (Admin::user()->can('content_report_audit')) {
  150. $actions->append("<button class='btn btn-primary btn-xs jobaudit' data-code=".$actions->row['id'].">审核</button>");
  151. }
  152. if (Admin::user()->can('content_report_delete')) {
  153. $actions->disableDelete(false);
  154. }
  155. });
  156. if (Admin::user()->can('content_report_delete')) {
  157. $grid->tools(function ($tools) {
  158. $tools->batch(function ($batch) {
  159. $batch->disableDelete(false);
  160. });
  161. });
  162. }
  163. if (!Admin::user()->can('content_report_audit') && !Admin::user()->can('content_report_delete')) {
  164. $grid->disableRowSelector();
  165. }
  166. /*$grid->tools(function (Grid\Tools $tools) {
  167. $tools->disableRefreshButton();
  168. });*/
  169. $grid->filter(function (Filter $filter) {
  170. $filter->disableIdFilter();
  171. $filter->column(2/3, function ($filter) {
  172. /*if (get_subsite_id() == 0) {
  173. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  174. if ($subsites) {
  175. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  176. $filter->equal('subsite_id', '所属分站')->radio($subsites);
  177. }
  178. }*/
  179. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  180. if ($subsites) {
  181. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  182. $filter->equal('subsite_id', '所属分站')->select($subsites);
  183. }
  184. $types = array( ''=>'不限','1' => '职位', '2' => '简历');
  185. $filter->equal('utype', '举报类型')->select(collect($types))->load('type_id', 'report/types', 'id', 'text');
  186. $utype = \Illuminate\Support\Facades\Request::input('utype');
  187. $utype = $utype?$utype:'';
  188. $report_reasons = array(''=>'不限') + Report::getReportTypes($utype);
  189. $filter->equal('type_id', '举报原因')->select($report_reasons);
  190. if (get_subsite_id()) {
  191. $nums = Report::where(array('audit'=>'1','subsite_id'=>get_subsite_id()))->get()->count();
  192. } else {
  193. $nums = Report::where(array('audit'=>'1'))->get()->count();
  194. }
  195. $num_html ='';
  196. if ($nums>0) {
  197. $num_html = '('.$nums.')';
  198. }
  199. $status_option = array('1'=>'未核实'.$num_html,'2'=>'属实','3'=>'不属实');
  200. $status_option = array(''=>'不限')+$status_option;
  201. $filter->equal('audit', '核实情况')->radio($status_option);
  202. $date3 = date('Y-m-d', strtotime("-3 day"));
  203. $date7 = date('Y-m-d', strtotime("-7 day"));
  204. $date30 = date("Y-m-d", strtotime("-1 month"));
  205. $date180 = date("Y-m-d", strtotime("-6 month"));
  206. $date360 = date("Y-m-d", strtotime("-1 year"));
  207. $date_option = array(
  208. '' => '不限',
  209. $date3 => '三天内',
  210. $date7 => '一周内',
  211. $date30 => '一月内',
  212. $date180 => '半年内',
  213. $date360 => '一年内',
  214. );
  215. //$filter->gt('created_at', '举报时间')->radio($date_option);
  216. $filter->where(function ($query) {
  217. $query->where('created_at', '>=', "{$this->input}");
  218. }, '举报时间', 'created_at')->radio($date_option);
  219. });
  220. });
  221. //审核功能
  222. if (Admin::user()->can('content_report_audit')) {
  223. $grid->tools(function ($tools) {
  224. $form = new \Encore\Admin\Widgets\Form();
  225. $form->action(route('report.audit'));
  226. $audit_option = array('2'=>'属实','3'=>'不属实');
  227. $form->radio('audit', '将所选举报记录设置为:')->options($audit_option)->default(2)->setWidth(8, 4);
  228. $form->json('val');
  229. $config = array('title'=>'审核举报','button'=>'审核','dialog_cancel' => "取消", 'dialog_ok' => "确认", 'is_batch' => true);
  230. $tools->append(new DialogTool($form, $config));
  231. });
  232. }
  233. $this->script = <<<EOT
  234. $(document).ready(function(){
  235. $('table input[type="checkbox"]').each(function(){
  236. var \$data_id = $(this).data('id');
  237. if ($('#report_'+\$data_id).val() == 2) {
  238. $(this).parent().remove();
  239. }
  240. });
  241. });
  242. EOT;
  243. js_Admin::script($this->script);
  244. return $grid;
  245. }
  246. public function audit(Request $request)
  247. {
  248. $rst = $request->validate(['audit'=>'required'], array('audit.required'=>'请选择处理状态'));
  249. $ids = $request->input('ids');
  250. if (empty($ids)) {
  251. if($request->type){
  252. admin_toastr('请选择需要审核的数据', 'error');
  253. return back();
  254. }else {
  255. return admin_toastr('请选择需要审核的数据', 'error');
  256. }
  257. }
  258. $id_arr = explode(',', $ids);
  259. $update_data = array(
  260. 'audit' => $request->input('audit'),
  261. 'updated_at' => date('Y-m-d H:i:s', time())
  262. );
  263. $result = Report::whereIn('id', $id_arr)->where(array(array('audit','<>','2')))->get();
  264. if (Report::whereIn('id', $id_arr)->where(array(array('audit','<>','2')))->update($update_data) === false) {
  265. if($request->type){
  266. admin_toastr('审核失败', 'error');
  267. return back();
  268. }else {
  269. return admin_toastr('审核失败', 'error');
  270. }
  271. } else {
  272. //添加审核日志
  273. $reason_data = array('ids'=>$id_arr,'status'=>$request->input('audit'),'type'=>'6');
  274. if ($request->input('audit')=='2') {
  275. $reason_data['reason'] = '将举报记录设置为属实';
  276. } else {
  277. $reason_data['reason'] = '将举报记录设置为不属实';
  278. }
  279. AuditReason::addData($reason_data);
  280. if ($result->toArray()) {
  281. foreach ($result as $key => $list) {
  282. $utype = $list->utype;
  283. $timestring = date("Y年m月d日", time());
  284. if ($utype == 1) {
  285. //职位举报
  286. $per_info = MemberInfo::where(array('uid'=>$list->uid))->first();
  287. $member_info = Member::where(array('id'=>$list->uid))->first();
  288. $per_info->utype = $member_info->utype;
  289. $per_info->username = $member_info->username;
  290. $jobsinfo = Jobs::where(array('id'=>$list->utype_id))->first();
  291. if (!$jobsinfo) {
  292. continue;
  293. }
  294. $subsite_id = 0;
  295. if (!config('aix.system.site_safety.subsite.close_subsite')) {
  296. $subsite_id = $jobsinfo->subsite_id;
  297. }
  298. $jobsurl=route(url_rewrite('AIX_jobsshow', array('id'=>$jobsinfo->id), $subsite_id), array('id'=>$jobsinfo->id));
  299. $company_info = Company::where(array('id'=>$jobsinfo->company_id))->first();
  300. $company_info->uid = $company_info->id;
  301. if ($request->input('audit') == 2) {
  302. $r = $this->taskService->doUserTask($per_info, 13);
  303. $msg_p = '';
  304. if (array_get($r, 'code') == 1) {
  305. $msg_p = ",奖励".$r['data']['points']."积分,感谢您对".subsite_config('aix.system.site.site.site_name', '', $member_info->subsite_id)."的支持!";
  306. }
  307. $message="您于".$timestring."举报企业【".$jobsinfo->company_name."】发布的职位:【<a href=\"{$jobsurl}\" target=\"_blank\">".$list->utype_realname."</a>】,经平台核实情况属实".$msg_p;
  308. $this->pmsService->writePmsNotice($per_info, $message);
  309. $message_c="您发布的职位:【<a href=\"{$jobsurl}\" target=\"_blank\">{$list->utype_realname}</a>】于".$timestring."被举报,经平台核实情况属实,请尽快处理,如再有此类情况发生将作封号处理!";
  310. $this->pmsService->writePmsNotice($company_info, $message_c);
  311. } else {
  312. $message="您于".$timestring."举报企业【".$jobsinfo->company_name."】发布的职位:【<a href=\"{$jobsurl}\" target=\"_blank\">{$list->utype_realname}</a>】,经平台核实情况不属实";
  313. $this->pmsService->writePmsNotice($per_info, $message);
  314. }
  315. } else {
  316. //简历举报
  317. $company_info = Company::where(array('id'=>$list->uid))->first();
  318. if (!$company_info) {
  319. continue;
  320. }
  321. $company_info->uid = $company_info->id;
  322. $resume_info = Resume::where(array('id'=>$list->utype_id))->first();
  323. if (!$resume_info) {
  324. continue;
  325. }
  326. $resumeurl = route(url_rewrite('AIX_resumeshow'), ['id'=>$list->utype_id]);
  327. if ($request->input('audit') == 2) {
  328. $r = $this->taskService->doUserTask($company_info, 21); //5.1 获取举报职位所得积分信息
  329. $msg_p = '';
  330. if (array_get($r, 'code') == 1) {
  331. $msg_p = ",奖励".$r['data']['points']."积分,感谢您对".subsite_config('aix.system.site.site.site_name', '', $company_info->subsite_id)."的支持!";
  332. }
  333. $message="您于".$timestring."举报的简历:【<a href='".$resumeurl."' target='_blank'>".$list->utype_realname."</a>】,经平台核实情况属实".$msg_p;
  334. $this->pmsService->writePmsNotice($company_info, $message);
  335. $per_info = Member::where(array('id'=>$resume_info->uid))->first();
  336. if ($per_info) {
  337. $per_info->uid = $per_info->id;
  338. $message_c="您发布的简历【".$list->utype_realname."】于".$timestring."被举报,经平台核实情况属实,请尽快处理,如再有此类情况发生将作封号处理!";
  339. $this->pmsService->writePmsNotice($per_info, $message_c);
  340. }
  341. } else {
  342. $message="您于".$timestring."举报的简历【<a href=\"{$resumeurl}\" target=\"_blank\">{$list->utype_realname}</a>】,经平台核实情况不属实";
  343. $this->pmsService->writePmsNotice($company_info, $message);
  344. }
  345. }
  346. }
  347. }
  348. if($request->type){
  349. admin_toastr('审核成功', 'success');
  350. return back();
  351. }else {
  352. return admin_toastr('审核成功', 'success');
  353. }
  354. }
  355. }
  356. /**
  357. * Make a show builder.
  358. *
  359. * @param mixed $id
  360. * @return Show
  361. */
  362. protected function detail($id)
  363. {
  364. $show = new Show(Report::findOrFail($id));
  365. $report_info = Report::findOrFail($id);
  366. $show->id('ID');
  367. $show->username('举报对象');
  368. if ($report_info->utype == 1) {
  369. $show->utype_id('职位ID');
  370. $show->utype_realname('投诉职位');
  371. } else {
  372. $show->utype_id('简历ID');
  373. $show->utype_realname('投诉简历');
  374. }
  375. $show->utype('举报类型')->as(function ($utype) {
  376. if ($utype == 1) {
  377. return '职位';
  378. }
  379. return '简历';
  380. });
  381. $show->type_id('举报原因');
  382. if ($report_info->utype == 1) {
  383. $show->phone('联系电话');
  384. $show->content('内容描述');
  385. }
  386. $show->audit('核实情况')->as(function ($audit) {
  387. if ($audit == 1) {
  388. return '未核实';
  389. } else if ($audit == 2) {
  390. return '属实';
  391. } else if ($audit == 3) {
  392. return '不属实';
  393. }
  394. });
  395. if(get_subsite_open()){
  396. $show->subsite_id('所属分站')->as(function ($subsite_id) {
  397. if ($subsite_id) {
  398. $Subsite = Subsite::findOrFail($subsite_id);
  399. return $Subsite->sitename;
  400. }
  401. return '总站';
  402. });
  403. }
  404. $show->created_at('Created at');
  405. $show->updated_at('Updated at');
  406. /*$show->panel()
  407. ->tools(function ($tools) {
  408. $tools->disableEdit();
  409. $tools->disableDelete();
  410. });*/
  411. return $show;
  412. }
  413. /**
  414. * Make a form builder.
  415. *
  416. * @return Form
  417. */
  418. protected function form()
  419. {
  420. $form = new Form(new Report);
  421. $form->display('ID');
  422. $form->display('Created at');
  423. $form->display('Updated at');
  424. return $form;
  425. }
  426. }