You've already forked guangan
分类
This commit is contained in:
@ -2,10 +2,18 @@
|
||||
|
||||
namespace plugin\ticket\controller;
|
||||
|
||||
use plugin\inspection\model\InspectionStaff;
|
||||
use plugin\ticket\model\ApprovalInstance;
|
||||
use plugin\ticket\model\ApprovalProcess;
|
||||
use plugin\ticket\model\ApprovalStep;
|
||||
use plugin\ticket\model\TicketReply;
|
||||
use plugin\ticket\model\TicketTicket;
|
||||
use plugin\ticket\model\TicketTicketInter;
|
||||
use plugin\ticket\model\TicketType;
|
||||
use think\admin\Controller;
|
||||
use think\admin\helper\QueryHelper;
|
||||
use think\admin\model\SystemUser;
|
||||
use think\exception\HttpResponseException;
|
||||
|
||||
/**
|
||||
* 内部工单管理
|
||||
@ -32,23 +40,17 @@ class TicketInter extends Controller
|
||||
$query->like(['title|content|contact_name|ticket_address|contact_phone#keyword'])
|
||||
->dateBetween(['create_at'])
|
||||
->equal(['status', 'type_id']);
|
||||
$query->append(['imgs_arr', 'source_type_name', 'status_text', 'type_name']);
|
||||
$query->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with(['user_shares', 'views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process']);
|
||||
});
|
||||
}
|
||||
|
||||
public function my()
|
||||
public function _form_filter(&$data)
|
||||
{
|
||||
$this->title = '我的工单';
|
||||
$this->user_id = $this->request->session('user')['id'];
|
||||
TicketTicketInter::mQuery()->layTable(function () {
|
||||
|
||||
}, function (QueryHelper $query) {
|
||||
$query->like(['title|content|contact_name|ticket_address|contact_phone#keyword'])
|
||||
->dateBetween(['create_at'])
|
||||
->equal(['status', 'type_id']);
|
||||
$query->append(['imgs_arr', 'source_type_name', 'status_text', 'type_name']);
|
||||
$query->where(['current_admin_id' => $this->user_id]);
|
||||
});
|
||||
if ($this->request->isPost()) {
|
||||
$data['user_id'] = 0;
|
||||
}
|
||||
ApprovalInstance::query()->where('oid', '=', $data['id'])->delete();
|
||||
$data['status'] = -1;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -61,8 +63,493 @@ class TicketInter extends Controller
|
||||
{
|
||||
$this->title = '工单详情';
|
||||
['id' => $id] = $this->_vali(['id.require' => '请指定工单ID!']);
|
||||
$this->vo = TicketTicketInter::mk()->with(['user', 'type', 'reply'])->append(['imgs_arr', 'status_text', 'type_name', 'last_reply'])->find($id);
|
||||
$this->vo = TicketTicketInter::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($id);
|
||||
$this->ticket = $this->vo;
|
||||
$process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty();
|
||||
$instance = ApprovalInstance::query()->with(['steps.approver', 'logs'])->where('process_id', '=', $process->id)->where('oid', '=', $id)->findOrEmpty();
|
||||
$this->instance = $instance;
|
||||
if ($instance->isEmpty()) {
|
||||
$this->step_index = -1;
|
||||
} else {
|
||||
$this->step_index = $instance->current_step;
|
||||
}
|
||||
$this->fetch();
|
||||
}
|
||||
|
||||
public function reply()
|
||||
{
|
||||
$this->title = '回复工单';
|
||||
[
|
||||
'ticket_id'=>$ticket_id,
|
||||
'id'=>$id
|
||||
] = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
'id.require'=>'请指定回复ID!'
|
||||
]);
|
||||
$this->vo = TicketTicket::mk()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($ticket_id);
|
||||
TicketReply::mForm('reply');
|
||||
}
|
||||
|
||||
public function _reply_form_filter(&$data)
|
||||
{
|
||||
if ($this->request->isPost()) {
|
||||
$this->_applyFormToken();
|
||||
$data['type'] = 1;
|
||||
$adminInfo = $this->request->session('user');
|
||||
$data['user_id'] = $adminInfo['id'];
|
||||
$data['username'] = $adminInfo['nickname'];
|
||||
$data['contact'] = $adminInfo['contact_phone'];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 审核页面
|
||||
* @auth true
|
||||
* @menu true
|
||||
*/
|
||||
public function approve()
|
||||
{
|
||||
$this->title = '审核流程';
|
||||
[
|
||||
'id'=>$id
|
||||
] = $this->_vali([
|
||||
'id.require'=>'请指定回复ID!'
|
||||
]);
|
||||
$this->vo = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->find($id);
|
||||
$process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty();
|
||||
if ($process->isEmpty()) {
|
||||
$this->error('未找到可用的审核流程');
|
||||
}
|
||||
$this->process = $process;
|
||||
$instance = ApprovalInstance::query()->with(['steps', 'logs'])->where('process_id', '=', $process->id)->where('oid', '=', $id)->findOrEmpty();
|
||||
$this->instance = $instance;
|
||||
if ($instance->isEmpty()) {
|
||||
$this->step_index = -1;
|
||||
$this->current_step = $process->steps[0];
|
||||
} else {
|
||||
$this->step_index = $instance->current_step;
|
||||
if (sizeof($instance->steps) <= ($instance->current_step + 1)) {
|
||||
$this->current_step = ['approver_type' => 0];
|
||||
} else {
|
||||
$this->current_step = $instance->steps[$instance->current_step + 1];
|
||||
}
|
||||
}
|
||||
$this->users = SystemUser::query()->field('id,username,nickname')->select();
|
||||
$this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \Exception
|
||||
* 审核提交
|
||||
* @auth true
|
||||
* @menu true
|
||||
*/
|
||||
public function create_approval()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'id.require'=>'请指定工单ID!',
|
||||
'title.default'=>'工单审核',
|
||||
'content.default'=>'',
|
||||
]);
|
||||
$process = ApprovalProcess::where('type', '=', 'GDSH')->order('id', 'asc')->findOrEmpty();
|
||||
if ($process->isEmpty()) {
|
||||
$this->error('未找到可用的审核流程');
|
||||
}
|
||||
$adminInfo = $this->request->session('user');
|
||||
ApprovalInstance::mk()->startTrans();
|
||||
try {
|
||||
$instance = ApprovalInstance::create([
|
||||
'process_id' => $process->id,
|
||||
'oid' => $data['id'],
|
||||
'title' => $data['title'],
|
||||
'content' => $data['content'],
|
||||
'status' => 0,
|
||||
'current_step' => 0,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'create_by' => $adminInfo['id'],
|
||||
'create_name' => $adminInfo['username'],
|
||||
]);
|
||||
foreach ($process->steps as $index => $step) {
|
||||
$approver_id = $step['approver_id'] ?? 0;
|
||||
if ($index == 0) {
|
||||
if ($step['approver_type'] == 3) {
|
||||
$approve_data = $this->_vali([
|
||||
'approver_id.require' => '请指定审核人!',
|
||||
]);
|
||||
$approver_id = $approve_data['approver_id'];
|
||||
}
|
||||
}
|
||||
ApprovalStep::create([
|
||||
'instance_id' => $instance->id,
|
||||
'step_number' => $index,
|
||||
'approver_type' => $step['approver_type'],
|
||||
'approver_id' => $approver_id,
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
ApprovalInstance::mk()->commit();
|
||||
} catch (HttpResponseException $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
// $this->error("创建失败");
|
||||
throw $e;
|
||||
}
|
||||
$this->success('创建成功!');
|
||||
}
|
||||
|
||||
public function view_process_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$process = ApprovalProcess::where('type', '=', 'HSSH')->order('id', 'asc')->findOrEmpty();
|
||||
if ($process->isEmpty()) {
|
||||
$this->error('未找到可用的审核流程');
|
||||
}
|
||||
$adminInfo = $this->request->session('user');
|
||||
$ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$instance_data = $this->_vali([
|
||||
'title.default'=>'核验工单审核',
|
||||
'content.default'=>'',
|
||||
]);
|
||||
ApprovalInstance::mk()->startTrans();
|
||||
try {
|
||||
$instance = ApprovalInstance::create([
|
||||
'process_id' => $process->id,
|
||||
'oid' => $ticket->id,
|
||||
'title' => $instance_data['title'],
|
||||
'content' => $instance_data['content'],
|
||||
'status' => 0,
|
||||
'current_step' => 0,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'create_by' => $adminInfo['id'],
|
||||
'create_name' => $adminInfo['username'],
|
||||
]);
|
||||
foreach ($process->steps as $index => $step) {
|
||||
$approver_id = $step['approver_id'] ?? 0;
|
||||
if ($index == 0) {
|
||||
if ($step['approver_type'] == 3) {
|
||||
$approve_data = $this->_vali([
|
||||
'approver_id.require' => '请指定审核人!',
|
||||
]);
|
||||
$approver_id = $approve_data['approver_id'];
|
||||
}
|
||||
}
|
||||
ApprovalStep::create([
|
||||
'instance_id' => $instance->id,
|
||||
'step_number' => $index,
|
||||
'approver_type' => $step['approver_type'],
|
||||
'approver_id' => $approver_id,
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
$ticket->view_pid = $instance->id;
|
||||
$ticket->save();
|
||||
ApprovalInstance::mk()->commit();
|
||||
} catch (HttpResponseException $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
$this->error("创建失败");
|
||||
}
|
||||
$this->success('创建成功!');
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->process = $process;
|
||||
$this->step_index = -1;
|
||||
$this->current_step = $process->steps[0];
|
||||
$this->users = SystemUser::query()->field('id,username,nickname')->select();
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function view_ticket_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$ticket = TicketTicket::query()->with(['view_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
$staffs = InspectionStaff::query()->field('id,name,phone')->select();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$adminInfo = $this->request->session('user');
|
||||
$instance_data = $this->_vali([
|
||||
'staff_id.require'=>'请指定维修人员!',
|
||||
]);
|
||||
$view = $ticket->views()->save([
|
||||
'staff_id'=>$instance_data['staff_id'],
|
||||
'status'=>0,
|
||||
'create_by'=>$adminInfo['id'],
|
||||
]);
|
||||
$this->success('创建成功!', $view);
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->staffs = $staffs;
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function repair_process_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$process = ApprovalProcess::where('type', '=', 'WXSH')->order('id', 'asc')->findOrEmpty();
|
||||
if ($process->isEmpty()) {
|
||||
$this->error('未找到可用的审核流程');
|
||||
}
|
||||
$adminInfo = $this->request->session('user');
|
||||
$ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$instance_data = $this->_vali([
|
||||
'title.default'=>'核验工单审核',
|
||||
'content.default'=>'',
|
||||
]);
|
||||
ApprovalInstance::mk()->startTrans();
|
||||
try {
|
||||
$instance = ApprovalInstance::create([
|
||||
'process_id' => $process->id,
|
||||
'oid' => $ticket->id,
|
||||
'title' => $instance_data['title'],
|
||||
'content' => $instance_data['content'],
|
||||
'status' => 0,
|
||||
'current_step' => 0,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'create_by' => $adminInfo['id'],
|
||||
'create_name' => $adminInfo['username'],
|
||||
]);
|
||||
foreach ($process->steps as $index => $step) {
|
||||
$approver_id = $step['approver_id'] ?? 0;
|
||||
if ($index == 0) {
|
||||
if ($step['approver_type'] == 3) {
|
||||
$approve_data = $this->_vali([
|
||||
'approver_id.require' => '请指定审核人!',
|
||||
]);
|
||||
$approver_id = $approve_data['approver_id'];
|
||||
}
|
||||
}
|
||||
ApprovalStep::create([
|
||||
'instance_id' => $instance->id,
|
||||
'step_number' => $index,
|
||||
'approver_type' => $step['approver_type'],
|
||||
'approver_id' => $approver_id,
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
$ticket->repair_pid = $instance->id;
|
||||
$ticket->save();
|
||||
ApprovalInstance::mk()->commit();
|
||||
} catch (HttpResponseException $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
$this->error("创建失败");
|
||||
}
|
||||
$this->success('创建成功!');
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->process = $process;
|
||||
$this->step_index = -1;
|
||||
$this->current_step = $process->steps[0];
|
||||
$this->users = SystemUser::query()->field('id,username,nickname')->select();
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function repair_ticket_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$ticket = TicketTicket::query()->with(['repair_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
$staffs = InspectionStaff::query()->field('id,name,phone')->select();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$adminInfo = $this->request->session('user');
|
||||
$instance_data = $this->_vali([
|
||||
'staff_id.require'=>'请指定维修人员!',
|
||||
]);
|
||||
$view = $ticket->repairs()->save([
|
||||
'staff_id'=>$instance_data['staff_id'],
|
||||
'status'=>0,
|
||||
'create_by'=>$adminInfo['id'],
|
||||
]);
|
||||
$this->success('创建成功!', $view);
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->staffs = $staffs;
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function verify_process_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$process = ApprovalProcess::where('type', '=', 'YSSH')->order('id', 'asc')->findOrEmpty();
|
||||
if ($process->isEmpty()) {
|
||||
$this->error('未找到可用的审核流程');
|
||||
}
|
||||
$adminInfo = $this->request->session('user');
|
||||
$ticket = TicketTicket::query()->with(['user', 'type'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$instance_data = $this->_vali([
|
||||
'title.default'=>'核验工单审核',
|
||||
'content.default'=>'',
|
||||
]);
|
||||
ApprovalInstance::mk()->startTrans();
|
||||
try {
|
||||
$instance = ApprovalInstance::create([
|
||||
'process_id' => $process->id,
|
||||
'oid' => $ticket->id,
|
||||
'title' => $instance_data['title'],
|
||||
'content' => $instance_data['content'],
|
||||
'status' => 0,
|
||||
'current_step' => 0,
|
||||
'create_time' => date('Y-m-d H:i:s'),
|
||||
'create_by' => $adminInfo['id'],
|
||||
'create_name' => $adminInfo['username'],
|
||||
]);
|
||||
foreach ($process->steps as $index => $step) {
|
||||
$approver_id = $step['approver_id'] ?? 0;
|
||||
if ($index == 0) {
|
||||
if ($step['approver_type'] == 3) {
|
||||
$approve_data = $this->_vali([
|
||||
'approver_id.require' => '请指定审核人!',
|
||||
]);
|
||||
$approver_id = $approve_data['approver_id'];
|
||||
}
|
||||
}
|
||||
ApprovalStep::create([
|
||||
'instance_id' => $instance->id,
|
||||
'step_number' => $index,
|
||||
'approver_type' => $step['approver_type'],
|
||||
'approver_id' => $approver_id,
|
||||
'status' => 0,
|
||||
]);
|
||||
}
|
||||
$ticket->verify_pid = $instance->id;
|
||||
$ticket->save();
|
||||
ApprovalInstance::mk()->commit();
|
||||
} catch (HttpResponseException $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
throw $e;
|
||||
} catch (\Exception $e) {
|
||||
ApprovalInstance::mk()->rollback();
|
||||
$this->error("创建失败");
|
||||
}
|
||||
$this->success('创建成功!');
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->process = $process;
|
||||
$this->step_index = -1;
|
||||
$this->current_step = $process->steps[0];
|
||||
$this->users = SystemUser::query()->field('id,username,nickname')->select();
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
public function verify_ticket_create()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'ticket_id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$ticket = TicketTicket::query()->with(['repair_process'])->append(['imgs_arr', 'type_name'])->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
||||
$staffs = InspectionStaff::query()->field('id,name,phone')->select();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$adminInfo = $this->request->session('user');
|
||||
$instance_data = $this->_vali([
|
||||
'staff_id.require'=>'请指定维修人员!',
|
||||
]);
|
||||
$view = $ticket->verifys()->save([
|
||||
'staff_id'=>$instance_data['staff_id'],
|
||||
'status'=>0,
|
||||
'create_by'=>$adminInfo['id'],
|
||||
]);
|
||||
$this->success('创建成功!', $view);
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->staffs = $staffs;
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function my() {
|
||||
$this->title = '待我审核';
|
||||
$this->type_list = TicketType::getList();
|
||||
$this->user_id = $this->request->session('user')['id'];
|
||||
TicketTicket::mQuery()->layTable(function () {
|
||||
|
||||
}, function (QueryHelper $query) {
|
||||
$query->like(['title|content|contact_name|ticket_address|contact_phone#keyword'])
|
||||
->dateBetween(['create_at'])
|
||||
->equal(['status', 'type_id']);
|
||||
$query->whereIn("id", ApprovalStep::query()->where(['approver_id' => $this->user_id, 'status' => 0, 'approver_type' => 1, 'instance.status' => 0])->field("oid")->select())
|
||||
->append(['imgs_arr', 'source_type_name', 'type_name', 'last_reply'])->with('approval');
|
||||
});
|
||||
}
|
||||
|
||||
public function comment()
|
||||
{
|
||||
$data = $this->_vali([
|
||||
'id.require'=>'请指定工单ID!',
|
||||
]);
|
||||
$ticket = TicketTicketInter::query()->with(['user_shares'])->where('id', '=', $data['id'])->findOrEmpty();
|
||||
if ($ticket->isEmpty()) {
|
||||
$this->error('未找到工单信息');
|
||||
}
|
||||
if (!$ticket->user_shares || sizeof($ticket->user_shares) == 0) {
|
||||
$this->error("该工单无需评论");
|
||||
}
|
||||
if ($this->request->isPost()) {
|
||||
$adminInfo = $this->request->session('user');
|
||||
$comment_data = $this->_vali([
|
||||
'content.require'=>'请输入评论内容!',
|
||||
]);
|
||||
TicketTicket::mk()->startTrans();
|
||||
try {
|
||||
foreach ($ticket->user_shares as $share) {
|
||||
$share->logs()->save([
|
||||
'op_name' => $adminInfo["username"],
|
||||
'content' => $comment_data['content'],
|
||||
'result' => "后台用户反馈",
|
||||
]);
|
||||
}
|
||||
TicketTicket::mk()->commit();
|
||||
} catch (\Exception $e) {
|
||||
TicketTicket::mk()->rollback();
|
||||
$this->error("保存失败");
|
||||
}
|
||||
} else {
|
||||
$this->vo = $ticket;
|
||||
$this->ticket = $ticket;
|
||||
$this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user