ReportService.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2018/11/23
  6. * Time: 17:36
  7. */
  8. namespace App\Services\Content;
  9. use App\Repositories\ReportRepository;
  10. use App\Repositories\JobsRepository;
  11. use App\Repositories\ResumeRepository;
  12. use App\Exceptions\ResponseException;
  13. use Illuminate\Support\Facades\Cache;
  14. class ReportService
  15. {
  16. protected $reportRepository;
  17. protected $jobsRepository;
  18. protected $resumeRepository;
  19. /**
  20. * ReportService constructor.
  21. * @param $reportRepository
  22. * @param $jobsRepository
  23. * @param $resumeRepository
  24. */
  25. public function __construct(ReportRepository $reportRepository, JobsRepository $jobsRepository, ResumeRepository $resumeRepository)
  26. {
  27. $this->reportRepository = $reportRepository;
  28. $this->jobsRepository = $jobsRepository;
  29. $this->resumeRepository = $resumeRepository;
  30. }
  31. //获取举报类型
  32. public function getReportTypes($type)
  33. {
  34. return $this->reportRepository->getTypes($type);
  35. }
  36. //添加举报记录
  37. public function addReport($data)
  38. {
  39. if (array_get($data, 'utype') ==1) {
  40. //判断是否已举报过此职位
  41. $uid = auth('web-member')->user()->id;
  42. $report_record = $this->reportRepository->getReport(array('uid'=>$uid, 'utype_id'=> $data['utype_id'], 'utype'=>$data['utype']));
  43. if ($report_record) {
  44. throw new ResponseException('您已经举报过此职位!');
  45. }
  46. //判断职位是否存在
  47. $job_info = $this->jobsRepository->getInfo(array('id'=>$data['utype_id'],'valid'=>1));
  48. if (!$job_info) {
  49. throw new ResponseException('职位不存在!');
  50. }
  51. /*$subsite_id = Cache::get('subsite_id')?Cache::get('subsite_id'):0;*/
  52. $subsite_id = $job_info->subsite_id;
  53. $stime = date('Y-m-d H:i:s', time());
  54. //添加举报信息
  55. $report_data = array(
  56. 'uid' => $uid,
  57. 'username' => auth('web-member')->user()->username,
  58. 'utype' => $data['utype'],
  59. 'utype_id' => $data['utype_id'],
  60. 'utype_realname' => $job_info->jobs_name,
  61. 'type_id' => $data['type_id'],
  62. 'phone' => $data['phone'],
  63. 'content' => $data['content'],
  64. 'audit' => array_get($data, 'audit')?array_get($data, 'audit'):1,
  65. 'subsite_id' => $subsite_id,
  66. 'created_at' => $stime,
  67. 'updated_at' => $stime
  68. );
  69. $rst = $this->reportRepository->addInfo($report_data);
  70. if ($rst) {
  71. return $rst;
  72. } else {
  73. throw new ResponseException('举报失败!');
  74. }
  75. } else { //投诉简历
  76. //判断是否举报过该简历
  77. $user = auth('web-company')->user();
  78. $uid = $user->id;
  79. $report_record = $this->reportRepository->getReport(array('uid'=>$uid, 'utype_id'=> $data['utype_id'], 'utype'=>$data['utype']));
  80. if ($report_record) {
  81. throw new ResponseException('您已经举报过此简历!');
  82. //return array('status'=>0,'msg'=>'您已经举报过此简历!');
  83. }
  84. //判断简历是否存在
  85. $resume_info = $this->resumeRepository->getResumeById($data['utype_id']);
  86. if ($resume_info) {
  87. //简历中的真实名称
  88. $memberInfo = $resume_info->memberInfos;
  89. if ($memberInfo->display_name=="2") {
  90. $data['resume_realname']="N".str_pad($resume_info->id, 7, "0", STR_PAD_LEFT);
  91. } elseif ($memberInfo->display_name=="3") {
  92. if ($memberInfo->sex==1) {
  93. $data['resume_realname'] = cut_str($memberInfo->realname, 1, 0, "先生");
  94. } elseif ($memberInfo->sex == 2) {
  95. $data['resume_realname'] = cut_str($memberInfo->realname, 1, 0, "女士");
  96. }
  97. } else {
  98. $data['resume_realname'] = $memberInfo->realname;
  99. }
  100. /*$subsite_id = Cache::get('subsite_id')?Cache::get('subsite_id'):0;*/
  101. $subsite_id = $resume_info->subsite_id;
  102. $stime = date('Y-m-d H:i:s', time());
  103. //添加投诉信息
  104. $report_data = array(
  105. 'uid' => $uid,
  106. 'username' => $user->username,
  107. 'utype' => $data['utype'],
  108. 'utype_id' => $data['utype_id'],
  109. 'utype_realname' => $data['resume_realname'],
  110. 'type_id' => $data['type_id'],
  111. 'phone' => $data['phone'],
  112. 'content' => $data['content'],
  113. 'audit' => array_get($data, 'audit')?array_get($data, 'audit'):1,
  114. 'subsite_id' => $subsite_id,
  115. 'created_at' => $stime,
  116. 'updated_at' => $stime
  117. );
  118. $rst = $this->reportRepository->addInfo($report_data);
  119. if ($rst) {
  120. return $rst;
  121. } else {
  122. throw new ResponseException('投诉失败!');
  123. }
  124. } else {
  125. //return array('status'=>0,'msg'=>'简历不存在');
  126. throw new ResponseException('简历不存在!');
  127. }
  128. }
  129. }
  130. }