You've already forked guangan
462 lines
18 KiB
PHP
462 lines
18 KiB
PHP
<?php
|
|
|
|
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\TicketRepair;
|
|
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;
|
|
|
|
/**
|
|
* 内部工单管理
|
|
*/
|
|
class TicketInter extends Controller
|
|
{
|
|
/**
|
|
* 工单列表
|
|
* @auth true
|
|
* @menu true
|
|
* @return void
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\DbException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->title = '工单中心';
|
|
$this->type_list = TicketType::getList();
|
|
$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', 'type_name', 'last_reply'])->with(['user_shares', 'views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process']);
|
|
});
|
|
}
|
|
|
|
public function _form_filter(&$data)
|
|
{
|
|
if ($this->request->isPost()) {
|
|
$data['user_id'] = 0;
|
|
}
|
|
ApprovalInstance::query()->where('oid', '=', $data['id'])->delete();
|
|
$data['status'] = -1;
|
|
}
|
|
|
|
/**
|
|
* 查看工单
|
|
* @auth true
|
|
* @menu true
|
|
* @return void
|
|
*/
|
|
public function detail()
|
|
{
|
|
$this->title = '工单详情';
|
|
['id' => $id] = $this->_vali(['id.require' => '请指定工单ID!']);
|
|
$this->vo = TicketTicketInter::mk()->with(['user_shares', 'views', 'repairs', 'verifys', 'view_process', 'repair_process', 'verify_process'])->append(['imgs_arr', 'type_name'])->find($id);
|
|
$this->ticket = $this->vo;
|
|
$this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 审核页面
|
|
* @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 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'=>'请指定维修人员!',
|
|
'kj_user_id.default'=>'0',
|
|
]);
|
|
$staff = InspectionStaff::query()->where('id', '=', $instance_data['staff_id'])->findOrEmpty();
|
|
if ($staff->isEmpty()) {
|
|
$this->error('未找到维修人员信息');
|
|
}
|
|
$view = $ticket->repairs()->save([
|
|
'staff_id'=>$instance_data['staff_id'],
|
|
'status'=>0,
|
|
'create_id'=>$adminInfo['id'],
|
|
]);
|
|
$staff->messages()->save([
|
|
'status'=>0,
|
|
'title'=>'您有新的维修工单需要处理',
|
|
'content'=>'您有新的维修工单需要处理,请及时处理。',
|
|
]);
|
|
$ticket->kj_user_id = $instance_data['kj_user_id'];
|
|
$this->success('创建成功!', $view);
|
|
} else {
|
|
$this->vo = $ticket;
|
|
$this->staffs = $staffs;
|
|
$this->users = SystemUser::query()->field('id,username,nickname')->select();
|
|
$this->fetch();
|
|
}
|
|
}
|
|
|
|
|
|
public function repair_ticket_modify()
|
|
{
|
|
$data = $this->_vali([
|
|
'ticket_id.require'=>'请指定工单ID!',
|
|
]);
|
|
$repair = TicketRepair::query()->where('id', '=', $data['ticket_id'])->findOrEmpty();
|
|
if ($repair->isEmpty()) {
|
|
$this->error('未找到工单信息');
|
|
}
|
|
if ($repair->ticket === null) {
|
|
$this->error('未找到主工单信息');
|
|
}
|
|
if ($repair->status === 1) {
|
|
$this->error('该工单已维修完成,无法操作!');
|
|
}
|
|
$adminInfo = $this->request->session('user');
|
|
if ($repair->ticket->kj_user_id != $adminInfo['id']) {
|
|
$this->error('您不是该工单的控价人员,无法操作!');
|
|
}
|
|
if ($this->request->isPost()) {
|
|
|
|
} else {
|
|
$this->vo = $repair;
|
|
$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_id' => $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_id'=>$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();
|
|
}
|
|
}
|
|
|
|
} |