145 lines
3.7 KiB
PHP
145 lines
3.7 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Services;
|
||
|
|
|
||
|
|
use App\Models\Audit;
|
||
|
|
use App\Models\ProfileMarriage;
|
||
|
|
use App\Models\User;
|
||
|
|
use Exception;
|
||
|
|
|
||
|
|
class AuditService
|
||
|
|
{
|
||
|
|
/**
|
||
|
|
* 审核数据的id
|
||
|
|
* @var
|
||
|
|
*/
|
||
|
|
public $id;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 处理的审核状态 1=通过 -1=不通过
|
||
|
|
* @var
|
||
|
|
*/
|
||
|
|
public $status;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @var
|
||
|
|
*/
|
||
|
|
private $audit_model;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
public function handle()
|
||
|
|
{
|
||
|
|
$this->check();
|
||
|
|
$this->beforeEvent();
|
||
|
|
switch ($this->audit_model->type) {
|
||
|
|
case Audit::TYPE_INDUSTRY_SUB:
|
||
|
|
$this->industrySubAudit();//职位审核
|
||
|
|
break;
|
||
|
|
case Audit::TYPE_MARRIAGE_APPROVE;
|
||
|
|
$this->marriageApproveAudit();
|
||
|
|
break;
|
||
|
|
//todo 要审核其他数据 加其他类型就可以了
|
||
|
|
default:
|
||
|
|
throw new Exception('审核类型不存在');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
private function check()
|
||
|
|
{
|
||
|
|
if (!in_array($this->status, [1, -1])) {
|
||
|
|
throw new Exception('审核操作参数错误');
|
||
|
|
}
|
||
|
|
$audit = Audit::find($this->id);
|
||
|
|
if (!$audit) {
|
||
|
|
throw new Exception('审核数据不存在');
|
||
|
|
}
|
||
|
|
if ($audit->status != 0) {
|
||
|
|
throw new Exception('该数据已审核过了');
|
||
|
|
}
|
||
|
|
$this->audit_model = $audit;
|
||
|
|
}
|
||
|
|
|
||
|
|
private function beforeEvent()
|
||
|
|
{
|
||
|
|
$this->audit_model->status = $this->status;
|
||
|
|
$this->audit_model->operator_id = auth()->id();
|
||
|
|
$this->audit_model->save();
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 职位审核
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
private function industrySubAudit()
|
||
|
|
{
|
||
|
|
$user = User::find($this->audit_model->user_id);
|
||
|
|
if (!$user) {
|
||
|
|
throw new Exception('用户不存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
$user_service = new UserService();
|
||
|
|
$industry_sub = $this->audit_model->check_data['industry_sub'] ?? '';
|
||
|
|
|
||
|
|
//不通过
|
||
|
|
if ($this->status == -1){
|
||
|
|
$message = "您填写个人资料的其他行业-{$industry_sub}审核不通过!";
|
||
|
|
$user_service->sendNotice($user->id, 1, 'system', $message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
//通过
|
||
|
|
$user->industry_sub = $industry_sub;
|
||
|
|
$user->save();
|
||
|
|
$message = "您填写个人资料的其他行业-{$industry_sub}审核已通过!";
|
||
|
|
$user_service->sendNotice($user->id, 1, 'system', $message);
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* 介绍人认证
|
||
|
|
* @throws Exception
|
||
|
|
*/
|
||
|
|
private function marriageApproveAudit()
|
||
|
|
{
|
||
|
|
$user = User::find($this->audit_model->user_id);
|
||
|
|
if (!$user) {
|
||
|
|
throw new Exception('用户不存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
$desc = $this->audit_model->check_data['desc'] ?? '';
|
||
|
|
$certificates = $this->audit_model->check_data['certificates'] ?? '';
|
||
|
|
|
||
|
|
$user_service = new UserService();
|
||
|
|
|
||
|
|
if ($this->status == -1) {
|
||
|
|
$message = "您提交的福恋介绍人认证资料审核不通过!";
|
||
|
|
$user_service->sendNotice($user->id, 1, 'system', $message);
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
$profile_marriage = ProfileMarriage::query()->where('user_id', $user->id)->first();
|
||
|
|
if (!$profile_marriage) {
|
||
|
|
throw new Exception('介绍人资料不存在');
|
||
|
|
}
|
||
|
|
|
||
|
|
$profile_marriage->desc = $desc;
|
||
|
|
if ($certificates) {
|
||
|
|
$profile_marriage->certificates = json_encode($certificates);
|
||
|
|
}
|
||
|
|
|
||
|
|
$profile_marriage->save();
|
||
|
|
|
||
|
|
$user->is_marriage_approved = 1;
|
||
|
|
$user->save();
|
||
|
|
|
||
|
|
$message = "您提交的福恋介绍人认证资料审核已通过!";
|
||
|
|
$user_service->sendNotice($user->id, 1, 'system', $message);
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
}
|