123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?php
- /**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/11/23
- * Time: 17:36
- */
- namespace App\Services\Content;
- use App\Repositories\ReportRepository;
- use App\Repositories\JobsRepository;
- use App\Repositories\ResumeRepository;
- use App\Exceptions\ResponseException;
- use Illuminate\Support\Facades\Cache;
- class ReportService
- {
- protected $reportRepository;
- protected $jobsRepository;
- protected $resumeRepository;
- /**
- * ReportService constructor.
- * @param $reportRepository
- * @param $jobsRepository
- * @param $resumeRepository
- */
- public function __construct(ReportRepository $reportRepository, JobsRepository $jobsRepository, ResumeRepository $resumeRepository)
- {
- $this->reportRepository = $reportRepository;
- $this->jobsRepository = $jobsRepository;
- $this->resumeRepository = $resumeRepository;
- }
- //获取举报类型
- public function getReportTypes($type)
- {
- return $this->reportRepository->getTypes($type);
- }
- //添加举报记录
- public function addReport($data)
- {
- if (array_get($data, 'utype') ==1) {
- //判断是否已举报过此职位
- $uid = auth('web-member')->user()->id;
- $report_record = $this->reportRepository->getReport(array('uid'=>$uid, 'utype_id'=> $data['utype_id'], 'utype'=>$data['utype']));
- if ($report_record) {
- throw new ResponseException('您已经举报过此职位!');
- }
- //判断职位是否存在
- $job_info = $this->jobsRepository->getInfo(array('id'=>$data['utype_id'],'valid'=>1));
- if (!$job_info) {
- throw new ResponseException('职位不存在!');
- }
- /*$subsite_id = Cache::get('subsite_id')?Cache::get('subsite_id'):0;*/
- $subsite_id = $job_info->subsite_id;
- $stime = date('Y-m-d H:i:s', time());
- //添加举报信息
- $report_data = array(
- 'uid' => $uid,
- 'username' => auth('web-member')->user()->username,
- 'utype' => $data['utype'],
- 'utype_id' => $data['utype_id'],
- 'utype_realname' => $job_info->jobs_name,
- 'type_id' => $data['type_id'],
- 'phone' => $data['phone'],
- 'content' => $data['content'],
- 'audit' => array_get($data, 'audit')?array_get($data, 'audit'):1,
- 'subsite_id' => $subsite_id,
- 'created_at' => $stime,
- 'updated_at' => $stime
- );
- $rst = $this->reportRepository->addInfo($report_data);
- if ($rst) {
- return $rst;
- } else {
- throw new ResponseException('举报失败!');
- }
- } else { //投诉简历
- //判断是否举报过该简历
- $user = auth('web-company')->user();
- $uid = $user->id;
- $report_record = $this->reportRepository->getReport(array('uid'=>$uid, 'utype_id'=> $data['utype_id'], 'utype'=>$data['utype']));
- if ($report_record) {
- throw new ResponseException('您已经举报过此简历!');
- //return array('status'=>0,'msg'=>'您已经举报过此简历!');
- }
- //判断简历是否存在
- $resume_info = $this->resumeRepository->getResumeById($data['utype_id']);
- if ($resume_info) {
- //简历中的真实名称
- $memberInfo = $resume_info->memberInfos;
- if ($memberInfo->display_name=="2") {
- $data['resume_realname']="N".str_pad($resume_info->id, 7, "0", STR_PAD_LEFT);
- } elseif ($memberInfo->display_name=="3") {
- if ($memberInfo->sex==1) {
- $data['resume_realname'] = cut_str($memberInfo->realname, 1, 0, "先生");
- } elseif ($memberInfo->sex == 2) {
- $data['resume_realname'] = cut_str($memberInfo->realname, 1, 0, "女士");
- }
- } else {
- $data['resume_realname'] = $memberInfo->realname;
- }
- /*$subsite_id = Cache::get('subsite_id')?Cache::get('subsite_id'):0;*/
- $subsite_id = $resume_info->subsite_id;
- $stime = date('Y-m-d H:i:s', time());
- //添加投诉信息
- $report_data = array(
- 'uid' => $uid,
- 'username' => $user->username,
- 'utype' => $data['utype'],
- 'utype_id' => $data['utype_id'],
- 'utype_realname' => $data['resume_realname'],
- 'type_id' => $data['type_id'],
- 'phone' => $data['phone'],
- 'content' => $data['content'],
- 'audit' => array_get($data, 'audit')?array_get($data, 'audit'):1,
- 'subsite_id' => $subsite_id,
- 'created_at' => $stime,
- 'updated_at' => $stime
- );
- $rst = $this->reportRepository->addInfo($report_data);
- if ($rst) {
- return $rst;
- } else {
- throw new ResponseException('投诉失败!');
- }
- } else {
- //return array('status'=>0,'msg'=>'简历不存在');
- throw new ResponseException('简历不存在!');
- }
- }
- }
- }
|