123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267 |
- <?php
- /**
- * Created by PhpStorm.
- * User: michaelwu
- * Date: 2019/07/09
- * Time: 11:22
- */
- namespace App\Services\Crm;
- use App\Exceptions\ResponseException;
- use App\Models\Company;
- use App\Models\Jobs;
- use App\Models\JobsContact;
- use App\Repositories\CompanyRepository;
- use App\Repositories\JobsRepository;
- use App\Repositories\TplRepository;
- use App\Repositories\CompanyTplRepository;
- use App\Repositories\MemberLogRepository;
- use App\Services\Common\TaskService;
- use App\Services\Common\SmsService;
- use App\Services\Common\PmsService;
- use App\Models\AuditReason;
- use Aix\Sms\Contracts\Smser;
- use Exception;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Validation\Rule;
- class CompanyService
- {
- protected $companyRepository;
- protected $jobsRepository;
- protected $taskService;
- protected $smsService;
- protected $pmsService;
- protected $tplRepository;
- protected $companyTplRepository;
- protected $memberLogRepository;
- /**
- * CompanyService constructor.
- */
- public function __construct(CompanyRepository $companyRepository, JobsRepository $jobsRepository, TaskService $taskService, SmsService $smsService, PmsService $pmsService, TplRepository $tplRepository, CompanyTplRepository $companyTplRepository, MemberLogRepository $memberLogRepository)
- {
- $this->companyRepository = $companyRepository;
- $this->jobsRepository = $jobsRepository;
- $this->taskService = $taskService;
- $this->smsService = $smsService;
- $this->pmsService = $pmsService;
- $this->tplRepository = $tplRepository;
- $this->companyTplRepository = $companyTplRepository;
- $this->memberLogRepository = $memberLogRepository;
- }
- public function getCompany($company_id)
- {
- return $this->companyRepository->getCompanyInfo(['id'=>$company_id]);
- }
- public function getTpl($tpl_id)
- {
- return $this->tplRepository->find($tpl_id);
- }
- public function getCompanyTpl($where)
- {
- return $this->companyTplRepository->getTpl($where);
- }
- //修改企业信息
- public function companySave($data)
- {
- if(empty($data['address'])){
- return ['status'=>0,'msg'=>'联系地址不能为空'];
- }
- $apiAddress = apiAddress($data['address']);
- if (!$apiAddress) {
- return ['status'=>0,'msg'=>'联系地址定位不准确'];
- }
- $id = $data['id'];
- $companyInfo = $this->companyRepository->find($id);
- if (!$companyInfo) {
- return ['status'=>0,'msg'=>'企业会员不存在'];
- }
- $companyInfo->uid = $companyInfo->id;
- ///// 公司名称、联系人、手机号码、固定电话、电子邮箱、通讯地址、企业介绍
- if ($companyInfo->companyname != $data['companyname']) {
- //判断企业名称是否可以相同
- if (config('aix.companyset.comset.other_set.company_repeat') != 1) {
- if (!$this->companyRepository->checkUniaue('companyname', $data['companyname'], $companyInfo->id)) {
- return ['status'=>0,'msg'=>'公司名称已存在'];
- }
- }
- }
- //判断联系人信息是否修改
- if (!$data['contact']) {
- return ['status'=>0,'msg'=>'联系人信息不能为空!'];
- }
- //判断手机号码或者固定电话是否填写,至少二选一
- if (!$data['telephone'] && !$data['landline_tel']) {
- return ['status'=>0,'msg'=>'手机号码、固定电话至少二选一!'];
- }
- if ($companyInfo->mobile != $data['telephone'] && $data['telephone']) {
- //判断电话是否已存在
- if (!$this->companyRepository->checkUniaue('mobile', $data['telephone'], $companyInfo->id)) {
- return ['status'=>0,'msg'=>'手机号码已存在!'];
- }
- }
- //判断固定电话格式
- if ($data['landline_tel'] && !preg_match("/^(([0\+]\d{1,9}-)?(\d{2,6})-)(\d{1,12})(-(\d{1,8}))?$/", $data['landline_tel'])) {
- return ['status'=>0,'msg'=>'固定电话格式不正确!'];
- }
- //判断企业介绍是否填写
- if (!$data['contents']) {
- return ['status'=>0,'msg'=>'企业介绍不能为空!'];
- }
- //判断邮箱是否填写
- if (!$data['email']) {
- return ['status'=>0,'msg'=>'电子邮箱不能为空!'];
- }
- //判断邮件是否重复
- if (!$this->companyRepository->checkUniaue('email', $data['email'], $companyInfo->id)) {
- return ['status'=>0,'msg'=>'电子邮箱已存在!'];
- }
- DB::beginTransaction();
- try {
- //修改企业会员信息
- $updateData['companyname'] = $data['companyname'];
- $updateData['contents'] = $data['contents'];
- $updateData['address'] = $data['address'];
- $updateData['contact'] = $data['contact'];
- $updateData['mobile'] = $data['telephone'];
- $updateData['landline_tel'] = $data['landline_tel'];
- $updateData['map_x'] = $apiAddress['lng'];
- $updateData['map_y'] = $apiAddress['lat'];
- $updateData['email'] = $data['email'];
- $com_rst = $this->companyRepository->companySave($updateData, $id);
- if (!$com_rst) {
- return ['status'=>0,'msg'=>'操作失败!'];
- }
- //修改职位信息并推到搜索引擎
- $updateJob['company_name'] = $data['companyname'];
- $updateJob['map_x'] = $apiAddress['lng'];
- $updateJob['map_y'] = $apiAddress['lat'];
- $jid = $this->jobsRepository->findWhere(['company_id'=>$id])->pluck('id')->toArray();
- if ($this->jobsRepository->modifyData($jid, $updateJob)) {
- $condition1 = [['whereIn','id', $jid]];
- event_search_update(Jobs::class, $condition1, 'update');
- }
- //修改职位的联系信息
- $contactInfo = [];
- if($jid){
- $contactInfo['telephone'] = $data['telephone'];
- $contactInfo['email'] = $data['email'];
- $contactInfo['contact'] = $data['contact'];
- $contactInfo['qq'] = $companyInfo->qq;
- $contactInfo['landline_tel'] = $data['landline_tel'];
- $contactInfo['address'] = $data['address'];
- $contactInfo['contact_show'] = $companyInfo->contact_show;
- $contactInfo['telephone_show'] = $companyInfo->telephone_show;
- $contactInfo['email_show'] = $companyInfo->email_show;
- $contactInfo['landline_tel_show'] = $companyInfo->landline_tel_show;
- JobsContact::whereIn('job_id',$jid)->update($contactInfo);
- }
- //企业信息推到搜索引擎上
- event_search_update(Company::class, (string)$id, 'update');
- DB::commit();
- } catch (\Exception $e) {
- DB::rollback();
- return ['status'=>0,'msg'=>'操作失败!'];
- }
- //增加操作记录
- $this->taskService->doTask(27, $id, 1);
- $this->memberLogRepository->createLog($companyInfo,1004,"");
- return ['status'=>1,'msg'=>'操作成功!'];
- }
- public function auditCompany($params)
- {
- $ids = $params['id'];
- $id = explode(',', $ids);
- $reason = $params['reason'];
- $audit = $params['audit'];
- $audit_username = $params['audit_username'];
- if ($this->companyRepository->updateCompanies([],['id'=>$id], ['audit'=>$audit])) {
- event_search_update(Company::class, [['whereIn','id', $id]], 'update');
- //获取企业职位信息
- $jid = $this->jobsRepository->findWhereIn('company_id', $id, ['id']);
- if ($jid) {
- $jids = array_column($jid->toArray(), 'id');
- //修改职位中企业状态字段
- if ($this->jobsRepository->modifyCom($jids, ['company_audit'=>$audit])) {
- $condition1 = [['whereIn','id', $jids]];
- event_search_update(Jobs::class, $condition1, 'update');
- }
- }
- //如果认证状态为通过(1)完成营业招聘审核
- if ($audit == 1) {
- foreach ($id as $key => $val) {
- $this->taskService->doTask(30, $val, 1);
- }
- }
- switch ($audit) {
- case 1:
- $html = "企业通过审核";
- $alias =Smser::TEMPLATE_SMS_LICENSEALLOW;
- break;
- case 3:
- $html = "企业未通过审核";
- $alias=Smser::TEMPLATE_SMS_LICENSENOTALLOW;
- break;
- }
- foreach ($id as $key => $val) {
- $companyInfo = $this->companyRepository->find($val, ['mobile']);
- if ($companyInfo->mobile) {
- $this->smsService->sendSms($companyInfo->mobile, $alias, ['sitename'=>config('aix.system.site.site.site_name'),'sitedomain'=>config('aix.system.site.site.site_domain')]);
- }
- }
- $auditData= [];
- $auditData['ids'] = $id;
- $auditData['status'] = $audit;
- $auditData['type'] = 8;
- $auditData['reason'] = $reason;
- $auditData['audit_man'] = $audit_username;
- AuditReason::addData($auditData);
- //站内信
- switch ($audit) {
- case 1:
- $html = "企业通过审核";
- break;
- case 3:
- $html = "企业未通过审核";
- break;
- }
- foreach ($id as $key => $val) {
- $com = $this->companyRepository->findWhere(['id'=>$val], ['*']);
- $insert_data[$key] = array(
- 'utype' => 1,
- 'msgtype' => 1,
- 'msgfromuid' => 0,
- 'msgfrom' => $audit_username,
- 'msgtoname' =>$com[0]->username,
- 'msgtouid' => $val,
- 'message' => $html.'【备注】'.$reason,
- 'new' => 1,
- 'created_at' =>date('Y-m-d H:i:s', time()),
- 'updated_at' =>date('Y-m-d H:i:s', time()),
- );
- }
- $this->pmsService->addBatchPms($insert_data);
- return ['status'=>10,'msg'=>'设置成功!'];
- } else {
- return ['status'=>0,'msg'=>'设置失败!'];
- }
- }
- }
|