This commit is contained in:
2024-12-05 10:55:08 +08:00
parent 1fc0caafe5
commit 1b80b6ffd5
4 changed files with 74 additions and 1 deletions

View File

@ -60,4 +60,69 @@ class Ticket extends Auth
$ticket->save();
$this->success("工单创建成功", $ticket);
}
public function list()
{
$status = $this->request->get('status', null);
$query = TicketTicket::query(); // ->where(['fz_user_id'=>$this->staff->id])
if ($status) {
$query->where('staff_status', $status);
}
$pageData = $query->paginate();
$this->success('获取工单列表', $pageData);
}
public function info()
{
$id = $this->request->get('id');
$ticket = TicketTicket::query()
// ->where(['fz_user_id'=>$this->staff->id])
->with(['verify', 'repair'])->findOrEmpty($id);
if ($ticket->isEmpty()) $this->error('工单不存在');
$this->success('获取工单详情', $ticket);
}
public function verify()
{
$id = $this->request->get('id');
/** @var TicketTicket $ticket */
$ticket = TicketTicket::query()->where(['fz_user_id'=>$this->staff->id])->findOrEmpty($id);
if ($ticket->isEmpty()) $this->error('工单不存在');
$data = $this->_vali([
'content.require' => '现场核实内容不能为空',
'imgs.default' => '',
'work_days.default' => '',
]);
$ticket->verify()->save([
'staff_id' => $this->staff->id,
'content' => $data['content'],
'imgs' => $data['imgs'],
'work_days' => $data['work_days']
]);
// 已现场核实
$ticket->staff_status = 1;
$ticket->save();
$this->success('工单现场核实成功');
}
public function repair()
{
$id = $this->request->get('id');
/** @var TicketTicket $ticket */
$ticket = TicketTicket::query()->where(['fz_user_id'=>$this->staff->id])->findOrEmpty($id);
if ($ticket->isEmpty()) $this->error('工单不存在');
$data = $this->_vali([
'content.require' => '维修内容不能为空',
'imgs.default' => '',
]);
$ticket->repair()->save([
'staff_id' => $this->staff->id,
'content' => $data['content'],
'imgs' => $data['imgs'],
]);
// 已维修
$ticket->staff_status = 2;
$ticket->save();
$this->success('工单维修成功');
}
}

View File

@ -7,6 +7,7 @@ use think\admin\Model;
class TicketRepair extends Model
{
protected $append = ['imgs_arr'];
public function ticket()
{
return $this->belongsTo(TicketTicket::class, 'ticket_id');

View File

@ -2,11 +2,12 @@
namespace plugin\ticket\model;
use plugin\inspection\model\InspectionStaff;
use think\admin\Model;
class TicketTicket extends Model
{
protected $append = ['status_text', 'type_name', 'dept_name'];
protected $append = ['status_text', 'type_name', 'dept_name', 'imgs_arr'];
protected $globalScope = ['unConf'];
protected $table = 'ticket_ticket';
public function type()
@ -105,6 +106,11 @@ class TicketTicket extends Model
return $this->belongsTo(TicketDept::class, 'dept_id');
}
public function fzUser()
{
return $this->belongsTo(InspectionStaff::class, 'fz_user_id');
}
public function verify()
{
return $this->hasMany(TicketVerify::class, 'ticket_id')->order('create_at', 'desc');

View File

@ -7,6 +7,7 @@ use think\admin\Model;
class TicketVerify extends Model
{
protected $append = ['imgs_arr'];
public function ticket()
{
return $this->belongsTo(TicketTicket::class, 'ticket_id');