You've already forked guangan
手机端审核
This commit is contained in:
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\inspection\controller\api\auth;
|
||||||
|
|
||||||
|
use plugin\inspection\controller\api\Auth;
|
||||||
|
use plugin\ticket\model\ApprovalInstance;
|
||||||
|
use plugin\ticket\model\ApprovalInstance as Model;
|
||||||
|
use think\exception\HttpResponseException;
|
||||||
|
|
||||||
|
class Approval extends Auth
|
||||||
|
{
|
||||||
|
public function initialize()
|
||||||
|
{
|
||||||
|
parent::initialize();
|
||||||
|
if ($this->tokenInfo->is_admin != 1) {
|
||||||
|
$this->error('权限不足', [], 403);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function list()
|
||||||
|
{
|
||||||
|
$query = ApprovalInstance::query()->with(['ticket']);
|
||||||
|
$status = $this->request->get('status', false);
|
||||||
|
if (is_numeric($status)) {
|
||||||
|
$query->where('status', '=', $status);
|
||||||
|
}
|
||||||
|
if ($this->request->get('keywords', '')) {
|
||||||
|
$query->whereLike('title|ticket.title', "%{$this->request->get('keywords')}%");
|
||||||
|
}
|
||||||
|
$pageData = $query->order('id desc')->paginate();
|
||||||
|
$this->success('获取审批列表', $pageData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function info()
|
||||||
|
{
|
||||||
|
$id = $this->request->get('id', '');
|
||||||
|
if (empty($id)) {
|
||||||
|
$this->error('参数错误');
|
||||||
|
}
|
||||||
|
$instance = ApprovalInstance::query()->with(['ticket', 'steps'])->findOrEmpty($id);
|
||||||
|
if ($instance->isEmpty()) {
|
||||||
|
$this->error('审批单不存在');
|
||||||
|
}
|
||||||
|
$this->success('获取审批单详情', $instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function submit()
|
||||||
|
{
|
||||||
|
$data = $this->_vali([
|
||||||
|
'id.require'=>'请指定当前审核ID!',
|
||||||
|
'step_index.require'=>'请指定当前步骤!',
|
||||||
|
'status.require'=>'请指定审核结果!',
|
||||||
|
'content.default'=>'',
|
||||||
|
]);
|
||||||
|
$adminInfo = $this->user;
|
||||||
|
$instance = Model::query()->with('steps')->findOrEmpty($data['id']);
|
||||||
|
if ($instance->isEmpty()) {
|
||||||
|
$this->error('审核流程不存在!');
|
||||||
|
}
|
||||||
|
if ($instance->status == 1) {
|
||||||
|
$this->error('工单已通过,请勿重复操作!');
|
||||||
|
} else if ($instance->status == 2) {
|
||||||
|
$this->error('工单已驳回,请勿重复操作!');
|
||||||
|
}
|
||||||
|
if ($instance->current_step != $data['step_index']) {
|
||||||
|
$this->error('当前步骤不正确!');
|
||||||
|
}
|
||||||
|
if ($instance->current->approver_id != $adminInfo['id']) {
|
||||||
|
$this->error('您不是当前审核人,请勿操作!');
|
||||||
|
}
|
||||||
|
Model::mk()->startTrans();
|
||||||
|
try {
|
||||||
|
$instance->current->status = $data['status'];
|
||||||
|
$instance->current->content = $data['content'];
|
||||||
|
$instance->current->approve_time = date('Y-m-d H:i:s');
|
||||||
|
$instance->current->save();
|
||||||
|
if ($data['status'] == 2) {
|
||||||
|
$instance->status = 2;
|
||||||
|
} else {
|
||||||
|
$instance->current_step++;
|
||||||
|
if ($instance->current_step >= count($instance->steps)) {
|
||||||
|
$instance->status = 1;
|
||||||
|
} else {
|
||||||
|
$step = $instance->steps[$instance->current_step];
|
||||||
|
if ($step['approver_type'] == 3) {
|
||||||
|
$approve_data = $this->_vali([
|
||||||
|
'approver_id.require' => '请指定审核人!',
|
||||||
|
]);
|
||||||
|
$step->approver_id = $approve_data['approver_id'];
|
||||||
|
$step->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$instance->save();
|
||||||
|
Model::mk()->commit();
|
||||||
|
} catch (HttpResponseException $e) {
|
||||||
|
Model::mk()->rollback();
|
||||||
|
throw $e;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
Model::mk()->rollback();
|
||||||
|
$this->error("审核失败");
|
||||||
|
}
|
||||||
|
$this->success('审核成功!');
|
||||||
|
}
|
||||||
|
}
|
@ -15,6 +15,11 @@ class ApprovalInstance extends Model
|
|||||||
protected $updateTime = 'update_time';
|
protected $updateTime = 'update_time';
|
||||||
protected $append = ['status_text', 'current'];
|
protected $append = ['status_text', 'current'];
|
||||||
|
|
||||||
|
public function ticket()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(TicketTicket::class, 'oid', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
// 关联流程定义
|
// 关联流程定义
|
||||||
public function process()
|
public function process()
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user