This commit is contained in:
466
plugins/addon/example/model/IdcsmartTicketDeliveryModel.php
Normal file
466
plugins/addon/example/model/IdcsmartTicketDeliveryModel.php
Normal file
@@ -0,0 +1,466 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use addon\idcsmart_ticket\logic\IdcsmartTicketLogic;
|
||||
use app\common\model\HostModel;
|
||||
use app\common\model\SupplierModel;
|
||||
use app\common\model\UpstreamHostModel;
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2024-06-213
|
||||
*/
|
||||
class IdcsmartTicketDeliveryModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_delivery';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'product_id' => 'int',
|
||||
'ticket_type_id' => 'int',
|
||||
'blocked_words' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
public $isAdmin = false;
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 工单传递规则列表
|
||||
* @desc 工单传递规则列表
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @return array list - 工单传递规则列表
|
||||
* @return int list[].id - 规则ID
|
||||
* @return int list[].product_name - 商品名称
|
||||
* @return int list[].type_name - 类型名称
|
||||
* @return int list[].blocked_words - 屏蔽词,逗号分隔
|
||||
*/
|
||||
public function ticketDeliveryList($param)
|
||||
{
|
||||
$list = $this->alias('td')
|
||||
->field('td.id,p.name product_name,tt.name type_name,td.blocked_words,td.product_id,td.ticket_type_id')
|
||||
->leftJoin('product p','td.product_id=p.id')
|
||||
->leftJoin('addon_idcsmart_ticket_type tt','td.ticket_type_id=tt.id')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'list' => $list
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 工单传递规则详情
|
||||
* @desc 工单传递规则详情
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单传递规则ID required
|
||||
* @return object ticket_delivery - 工单传递规则详情
|
||||
* @return int ticket_delivery.product_id - 商品ID
|
||||
* @return string ticket_delivery.ticket_type_id - 类型ID
|
||||
* @return string ticket_delivery.blocked_words - 屏蔽词,逗号分隔
|
||||
*/
|
||||
public function indexTicketDelivery($id)
|
||||
{
|
||||
$ticketDelivery = $this->field('id,product_id,ticket_type_id,blocked_words')->find($id);
|
||||
|
||||
$data = [
|
||||
'ticket_delivery' => $ticketDelivery
|
||||
];
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message'),'data'=>$data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 创建工单传递规则
|
||||
* @desc 创建工单传递规则
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_type_id - 工单类型ID required
|
||||
* @param array product_ids - 商品ID数组 required
|
||||
* @param string blocked_words - 屏蔽词
|
||||
*/
|
||||
public function createTicketDelivery($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$insertAll = [];
|
||||
|
||||
foreach ($param['product_ids'] as $productId){
|
||||
$insertAll[] = [
|
||||
'product_id' => $productId,
|
||||
'ticket_type_id' => $param['ticket_type_id'],
|
||||
'blocked_words' => $param['blocked_words'],
|
||||
'create_time' => time(),
|
||||
];
|
||||
}
|
||||
|
||||
$this->insertAll($insertAll);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 编辑工单传递规则
|
||||
* @desc 编辑工单传递规则
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单传递规则ID required
|
||||
* @param int product_id - 商品ID required
|
||||
* @param string blocked_words - 屏蔽词
|
||||
*/
|
||||
public function updateTicketDelivery($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$this->update([
|
||||
'product_id' => $param['product_id'],
|
||||
'ticket_type_id' => $param['ticket_type_id'],
|
||||
'blocked_words' => $param['blocked_words'],
|
||||
'update_time' => time(),
|
||||
],['id' => $param['id']]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 删除工单传递规则
|
||||
* @desc 删除工单传递规则
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单传递规则ID required
|
||||
*/
|
||||
public function deleteTicketDelivery($id)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$this->where('id',$id)->delete();
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-13
|
||||
* @title 工单传递
|
||||
* @desc 工单传递
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int host_id - 产品ID required
|
||||
* @param int ticket_id - 工单ID required
|
||||
*/
|
||||
public function delivery($param)
|
||||
{
|
||||
if (!isset($param['host_id']) || empty($param['host_id'])){
|
||||
return ['status'=>400,'msg'=>lang_plugins('param_error')];
|
||||
}
|
||||
|
||||
if (!isset($param['ticket_id']) || empty($param['ticket_id'])){
|
||||
return ['status'=>400,'msg'=>lang_plugins('param_error')];
|
||||
}
|
||||
|
||||
$HostModel = new HostModel();
|
||||
$host = $HostModel->find($param['host_id']);
|
||||
if (empty($host)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_host_is_not_exist')];
|
||||
}
|
||||
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($param['ticket_id']);
|
||||
if (empty($ticket)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_is_not_exist')];
|
||||
}
|
||||
|
||||
$UpstreamHostModel = new UpstreamHostModel();
|
||||
$upstreamHost = $UpstreamHostModel->where('host_id',$param['host_id'])->find();
|
||||
if (empty($upstreamHost)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_upstream_host_is_not_exist')];
|
||||
}
|
||||
|
||||
$IdcsmartTicketUpstreamModel = new IdcsmartTicketUpstreamModel();
|
||||
$ticketUpstream = $IdcsmartTicketUpstreamModel->where('ticket_id',$param['ticket_id'])->find();
|
||||
if (!empty($ticketUpstream)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_has_deliveried')];
|
||||
}
|
||||
|
||||
// 规则只验证前台
|
||||
if (!$this->isAdmin){
|
||||
$delivery = $this->where('product_id',$host['product_id'])
|
||||
->where('ticket_type_id',$ticket['ticket_type_id'])
|
||||
->find();
|
||||
if (empty($delivery)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_delivery_rule_error')];
|
||||
}
|
||||
|
||||
if (!empty($delivery['blocked_words'])){
|
||||
$blockedWords = explode(',',$delivery['blocked_words']);
|
||||
foreach ($blockedWords as $blockedWord){
|
||||
if (strpos($ticket['title'],$blockedWord)!==false){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_delivery_rule_blocked_words_error')];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$config = IdcsmartTicketLogic::getDefaultConfig();
|
||||
|
||||
// 1、有文件,先传文件
|
||||
$SupplierModel = new SupplierModel();
|
||||
$supplier = $SupplierModel->find($upstreamHost['supplier_id']);
|
||||
$attachmentsUpstream = [];
|
||||
if (!empty($ticket['attachment'])){
|
||||
$attachments = explode(',',$ticket['attachment']);
|
||||
foreach ($attachments as $attachment){
|
||||
$result = IdcsmartTicketLogic::idcsmartApiCurlUploadFile($upstreamHost['supplier_id'],$config['ticket_upload'],$attachment);
|
||||
if ($result['status']!=200){
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_delivery_upload_fail_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_delivery_upload_fail',['{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
if (isset($result['data']['save_name']) && !empty($result['data']['save_name'])){
|
||||
$attachmentsUpstream[] = $result['data']['save_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2、取附件,传递工单
|
||||
$token = generate_signature(['title'=>$ticket['title'],'content'=>$ticket['content'],'downstream_ticket_id'=>$ticket['id']],AUTHCODE,'idcsmart_ticket')['signature'];
|
||||
$result = idcsmart_api_curl($upstreamHost['supplier_id'],'console/v1/ticket',[
|
||||
'is_downstream' => 1,
|
||||
'downstream_delivery' => $config['downstream_delivery']??0,
|
||||
'downstream_source' => 'IdcsmartTicket',
|
||||
'downstream_url' => request()->domain(),
|
||||
'downstream_token' => $token,
|
||||
'downstream_ticket_id' => $ticket['id'],
|
||||
'title' => $ticket['title'],
|
||||
'content' => htmlspecialchars_decode($ticket['content']),
|
||||
'host_ids' => [$upstreamHost['upstream_host_id']], // 传递上游产品ID
|
||||
'ticket_type_id' => 0,
|
||||
'attachment' => $attachmentsUpstream,
|
||||
],30,'POST','json');
|
||||
|
||||
// 3、记录日志
|
||||
if ($result['status']==200){
|
||||
// 更新本地token,与传递给上游的一致
|
||||
$ticket->save([
|
||||
'token' => $token
|
||||
]);
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_delivery_success_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_delivery_success',['{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
|
||||
}else{
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_delivery_fail_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_delivery_fail',['{host_id}'=>$param['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-18
|
||||
* @title 工单回复传递
|
||||
* @desc 工单回复传递
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID required
|
||||
* @param int ticket_reply_id - 工单回复ID required
|
||||
*/
|
||||
public function deliveryReply($param)
|
||||
{
|
||||
$IdcsmartTicketUpstreamModel = new IdcsmartTicketUpstreamModel();
|
||||
$ticketUpstream = $IdcsmartTicketUpstreamModel->where('ticket_id',$param['ticket_id'])->find();
|
||||
if (empty($ticketUpstream)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_has_not_deliveried_not_reply')];
|
||||
}
|
||||
if ($ticketUpstream['delivery_status']==0){
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_status_is_terminate_admin',['{admin}'=>request()->admin_name,'{ticket_reply_id}'=>$param['ticket_reply_id'],'{host_id}'=>$ticketUpstream['host_id'],'{reason}'=>lang_plugins('ticket_delivery_status_is_terminate')]),'addon_idcsmart_ticket',$param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_status_is_terminate',['{ticket_reply_id}'=>$param['ticket_reply_id'],'{host_id}'=>$ticketUpstream['host_id'],'{reason}'=>lang_plugins('ticket_delivery_status_is_terminate')]),'addon_idcsmart_ticket',$param['ticket_id']);
|
||||
}
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_delivery_status_is_terminate')];
|
||||
}
|
||||
|
||||
$UpstreamHostModel = new UpstreamHostModel();
|
||||
$upstreamHost = $UpstreamHostModel->where('host_id',$ticketUpstream['host_id'])->find();
|
||||
if (empty($upstreamHost)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_upstream_host_is_not_exist')];
|
||||
}
|
||||
|
||||
$IdcsmartTicketReplyModel = new IdcsmartTicketReplyModel();
|
||||
$ticketReply = $IdcsmartTicketReplyModel->find($param['ticket_reply_id']??0);
|
||||
|
||||
// 1、有文件,先传文件
|
||||
$config = IdcsmartTicketLogic::getDefaultConfig();
|
||||
$SupplierModel = new SupplierModel();
|
||||
$supplier = $SupplierModel->find($upstreamHost['supplier_id']);
|
||||
$attachmentsUpstream = [];
|
||||
if (!empty($ticketReply['attachment'])){
|
||||
$attachments = explode(',',$ticketReply['attachment']);
|
||||
foreach ($attachments as $attachment){
|
||||
$result = IdcsmartTicketLogic::idcsmartApiCurlUploadFile($upstreamHost['supplier_id'],$config['ticket_upload'],$attachment);
|
||||
if ($result['status']!=200){
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_upload_fail_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_upload_fail',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
if (isset($result['data']['save_name']) && !empty($result['data']['save_name'])){
|
||||
$attachmentsUpstream[] = $result['data']['save_name'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2、取附件,传递工单回复
|
||||
$result = idcsmart_api_curl($upstreamHost['supplier_id'],"console/v1/ticket/{$ticketUpstream['upstream_ticket_id']}/reply",[
|
||||
'is_downstream' => 1,
|
||||
// 'downstream_delivery' => $config['downstream_delivery'], // 是否显示【下游传递】
|
||||
// 'downstream_source' => 'IdcsmartTicket',
|
||||
// 'downstream_url' => request()->domain(),
|
||||
// 'downstream_token' => generate_signature(['content'=>$ticketReply['content']],AUTHCODE,'idcsmart_ticket')['signature'],
|
||||
'downstream_ticket_reply_id' => $ticketReply['id'],
|
||||
'content' => htmlspecialchars_decode($ticketReply['content']),
|
||||
'attachment' => $attachmentsUpstream,
|
||||
],30,'POST','json');
|
||||
// 3、记录日志
|
||||
if ($result['status']==200){
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_success_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_success',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
}else{
|
||||
if ($this->isAdmin){
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_fail_admin',['{admin}'=>request()->admin_name,'{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_reply_delivery_fail',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{ticket_reply_id}'=>$param['ticket_reply_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-18
|
||||
* @title 催单传递
|
||||
* @desc 催单传递
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID required
|
||||
*/
|
||||
public function deliveryUrge($param)
|
||||
{
|
||||
$IdcsmartTicketUpstreamModel = new IdcsmartTicketUpstreamModel();
|
||||
$ticketUpstream = $IdcsmartTicketUpstreamModel->where('ticket_id',$param['ticket_id'])->find();
|
||||
if (empty($ticketUpstream)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_has_not_deliveried_not_reply')];
|
||||
}
|
||||
if ($ticketUpstream['delivery_status']==0){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_delivery_status_is_terminate')];
|
||||
}
|
||||
|
||||
$UpstreamHostModel = new UpstreamHostModel();
|
||||
$upstreamHost = $UpstreamHostModel->where('host_id',$ticketUpstream['host_id'])->find();
|
||||
if (empty($upstreamHost)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_upstream_host_is_not_exist')];
|
||||
}
|
||||
|
||||
$SupplierModel = new SupplierModel();
|
||||
$supplier = $SupplierModel->find($upstreamHost['supplier_id']);
|
||||
$result = idcsmart_api_curl($upstreamHost['supplier_id'],"console/v1/ticket/{$ticketUpstream['upstream_ticket_id']}/urge",[
|
||||
'is_downstream' => 1,
|
||||
],30,'PUT','json');
|
||||
// 记录日志
|
||||
if ($result['status']==200){
|
||||
active_log(lang_plugins('log_ticket_urge_delivery_success',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_urge_delivery_fail',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2024-06-18
|
||||
* @title 关闭工单传递
|
||||
* @desc 关闭工单传递
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID required
|
||||
*/
|
||||
public function deliveryClose($param)
|
||||
{
|
||||
$IdcsmartTicketUpstreamModel = new IdcsmartTicketUpstreamModel();
|
||||
$ticketUpstream = $IdcsmartTicketUpstreamModel->where('ticket_id',$param['ticket_id'])->find();
|
||||
if (empty($ticketUpstream)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_has_not_deliveried_not_reply')];
|
||||
}
|
||||
if ($ticketUpstream['delivery_status']==0){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_delivery_status_is_terminate')];
|
||||
}
|
||||
|
||||
$UpstreamHostModel = new UpstreamHostModel();
|
||||
$upstreamHost = $UpstreamHostModel->where('host_id',$ticketUpstream['host_id'])->find();
|
||||
if (empty($upstreamHost)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_upstream_host_is_not_exist')];
|
||||
}
|
||||
|
||||
$SupplierModel = new SupplierModel();
|
||||
$supplier = $SupplierModel->find($upstreamHost['supplier_id']);
|
||||
$result = idcsmart_api_curl($upstreamHost['supplier_id'],"console/v1/ticket/{$ticketUpstream['upstream_ticket_id']}/close",[
|
||||
'is_downstream' => 1,
|
||||
],30,'PUT','json');
|
||||
// 记录日志
|
||||
if ($result['status']==200){
|
||||
active_log(lang_plugins('log_ticket_close_delivery_success',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}else{
|
||||
active_log(lang_plugins('log_ticket_close_delivery_fail',['{host_id}'=>$ticketUpstream['host_id'],'{ticket_id}'=>$param['ticket_id'],'{upstream}'=>$supplier['name'],'{reason}'=>$result['msg']]), 'addon_idcsmart_ticket', $param['ticket_id']);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
25
plugins/addon/example/model/IdcsmartTicketForwardModel.php
Normal file
25
plugins/addon/example/model/IdcsmartTicketForwardModel.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2025-05-20
|
||||
*/
|
||||
class IdcsmartTicketForwardModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_forward';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'ticket_id' => 'int',
|
||||
'admin_id' => 'int',
|
||||
'forward_admin_id' => 'int',
|
||||
'ticket_type_id' => 'int',
|
||||
'notes' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
}
|
||||
20
plugins/addon/example/model/IdcsmartTicketHostLinkModel.php
Normal file
20
plugins/addon/example/model/IdcsmartTicketHostLinkModel.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketHostLinkModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_host_link';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'ticket_id' => 'int',
|
||||
'host_id' => 'int',
|
||||
];
|
||||
|
||||
}
|
||||
2141
plugins/addon/example/model/IdcsmartTicketModel.php
Normal file
2141
plugins/addon/example/model/IdcsmartTicketModel.php
Normal file
File diff suppressed because it is too large
Load Diff
225
plugins/addon/example/model/IdcsmartTicketNotesModel.php
Normal file
225
plugins/addon/example/model/IdcsmartTicketNotesModel.php
Normal file
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use addon\idcsmart_ticket\logic\IdcsmartTicketLogic;
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketNotesModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_notes';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'ticket_id' => 'int',
|
||||
'content' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
'admin_id' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单备注列表
|
||||
* @desc 工单备注列表
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID
|
||||
* @return array list - 工单备注列表
|
||||
* @return int list[].id - ID
|
||||
* @return string list[].content - 工单备注
|
||||
* @return int list[].create_time - 创建时间
|
||||
* @return int list[].update_time - 更新时间
|
||||
* @return string list[].name - 管理员名称
|
||||
*/
|
||||
public function ticketNotesList($param)
|
||||
{
|
||||
$ticketId = $param['ticket_id']??0;
|
||||
|
||||
$list = $this->alias('tn')
|
||||
->field('tn.id,tn.ticket_id,tn.content,tn.create_time,tn.update_time,a.name')
|
||||
->leftJoin('admin a','a.id=tn.admin_id')
|
||||
->where('tn.ticket_id',$ticketId)
|
||||
->select()
|
||||
->toArray();
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message'),'data'=>['list'=>$list]];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单备注详情
|
||||
* @desc 工单备注详情
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单备注ID
|
||||
* @return int id - ID
|
||||
* @return string content - 工单备注
|
||||
* @return int create_time - 创建时间
|
||||
* @return int update_time - 更新时间
|
||||
* @return string name - 管理员名称
|
||||
*/
|
||||
public function ticketNotesIndex($param)
|
||||
{
|
||||
$ticketNotes = $this->alias('tn')
|
||||
->field('tn.id,tn.ticket_id,tn.content,tn.create_time,tn.update_time,a.name')
|
||||
->leftJoin('admin a','a.id=tn.admin_id')
|
||||
->where('tn.id',intval($param['id']))
|
||||
->find();
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'ticket_status' => $ticketNotes?:(object)[]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 创建工单备注
|
||||
* @desc 创建工单备注
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID
|
||||
* @param string content - 工单备注
|
||||
*/
|
||||
public function ticketNotesCreate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketId = $param['ticket_id']??0;
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($ticketId);
|
||||
if (empty($ticket)){
|
||||
throw new \Exception(lang_plugins('ticket_is_not_exist'));
|
||||
}
|
||||
|
||||
if (!IdcsmartTicketLogic::checkUpstreamTicket($ticketId)){
|
||||
throw new \Exception(lang_plugins('ticket_upstream_cannot_operate'));
|
||||
}
|
||||
|
||||
$this->insert([
|
||||
'ticket_id' => $param['ticket_id']??0,
|
||||
'content' => $param['content']??'',
|
||||
'admin_id' => get_admin_id(),
|
||||
'create_time' =>time()
|
||||
]);
|
||||
|
||||
active_log(lang_plugins('ticket_log_admin_create_ticket_notes', ['{admin}'=>'admin#'.get_admin_id().'#' .request()->admin_name.'#','{ticket_id}'=>'ticket#'.$ticket->id .'#'.$ticket->ticket_num .'#','{content}'=>$param['content']??'']), 'addon_idcsmart_ticket', $ticket->id);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 编辑工单备注
|
||||
* @desc 编辑工单备注
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID
|
||||
* @param int id - 工单备注ID
|
||||
* @param string content - 工单备注
|
||||
*/
|
||||
public function ticketNotesUpdate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketId = $param['ticket_id']??0;
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($ticketId);
|
||||
if (empty($ticket)){
|
||||
throw new \Exception(lang_plugins('ticket_is_not_exist'));
|
||||
}
|
||||
|
||||
if (!IdcsmartTicketLogic::checkUpstreamTicket($ticketId)){
|
||||
throw new \Exception(lang_plugins('ticket_upstream_cannot_operate'));
|
||||
}
|
||||
|
||||
$ticketNotes = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketNotes)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_notes_is_not_exist'));
|
||||
}
|
||||
|
||||
$ticketNotes->save([
|
||||
'ticket_id' => $param['ticket_id']??0,
|
||||
'content' => $param['content']??'',
|
||||
'admin_id' => get_admin_id(),
|
||||
'update_time' =>time()
|
||||
]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 删除工单备注
|
||||
* @desc 删除工单备注
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int ticket_id - 工单ID
|
||||
* @param int id - 工单备注ID
|
||||
*/
|
||||
public function ticketNotesDelete($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketId = $param['ticket_id']??0;
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($ticketId);
|
||||
if (empty($ticket)){
|
||||
throw new \Exception(lang_plugins('ticket_is_not_exist'));
|
||||
}
|
||||
|
||||
if (!IdcsmartTicketLogic::checkUpstreamTicket($ticketId)){
|
||||
throw new \Exception(lang_plugins('ticket_upstream_cannot_operate'));
|
||||
}
|
||||
|
||||
$ticketNotes = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketNotes)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_notes_is_not_exist'));
|
||||
}
|
||||
|
||||
$ticketNotes->delete();
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
152
plugins/addon/example/model/IdcsmartTicketPrereplyModel.php
Normal file
152
plugins/addon/example/model/IdcsmartTicketPrereplyModel.php
Normal file
@@ -0,0 +1,152 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketPrereplyModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_prereply';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'content' => 'string',
|
||||
];
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单预设回复列表
|
||||
* @desc 工单预设回复列表
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @return array list - 工单预设回复列表
|
||||
* @return int list[].id - ID
|
||||
* @return string list[].content - 内容
|
||||
*/
|
||||
public function ticketPrereplyList()
|
||||
{
|
||||
$list = $this->select()
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'list' => $list
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单预设回复详情
|
||||
* @desc 工单预设回复详情
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单预设回复ID
|
||||
* @return int id - ID
|
||||
* @return string content - 内容
|
||||
*/
|
||||
public function ticketPrereplyIndex($param)
|
||||
{
|
||||
$ticketPrereply = $this->find($param['id']);
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'ticket_prereply' => $ticketPrereply?:(object)[]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 创建工单预设回复
|
||||
* @desc 创建工单预设回复
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param string content - 内容
|
||||
*/
|
||||
public function ticketPrereplyCreate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$this->insert([
|
||||
'content' => $param['content']??''
|
||||
]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 编辑工单预设回复
|
||||
* @desc 编辑工单预设回复
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单预设回复ID
|
||||
* @param string content - 内容
|
||||
*/
|
||||
public function ticketPrereplyUpdate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketPrereply = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketPrereply)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_prereply_is_not_exist'));
|
||||
}
|
||||
$ticketPrereply->save([
|
||||
'content' => $param['content']??''
|
||||
]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 删除工单预设回复
|
||||
* @desc 删除工单预设回复
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单预设回复ID
|
||||
*/
|
||||
public function ticketPrereplyDelete($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketPrereply = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketPrereply)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_prereply_is_not_exist'));
|
||||
}
|
||||
$ticketPrereply->delete();
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>lang_plugins('error_message')];
|
||||
}
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
155
plugins/addon/example/model/IdcsmartTicketReplyModel.php
Normal file
155
plugins/addon/example/model/IdcsmartTicketReplyModel.php
Normal file
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use addon\idcsmart_ticket\logic\IdcsmartTicketLogic;
|
||||
use app\admin\model\AdminModel;
|
||||
use app\common\model\ClientModel;
|
||||
use think\Exception;
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketReplyModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_reply';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'ticket_id' => 'int',
|
||||
'type' => 'string',
|
||||
'rel_id' => 'int',
|
||||
'content' => 'string',
|
||||
'attachment' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
'is_downstream' => 'int',
|
||||
'downstream_ticket_reply_id' => 'int',
|
||||
'upstream_ticket_reply_id' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 时间 2022-09-23
|
||||
* @title 修改工单回复
|
||||
* @desc 修改工单回复
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单回复ID required
|
||||
* @param int content - 内容 required
|
||||
*/
|
||||
public function ticketReplyUpdate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketReply = $this->where('id',$param['id'])->find();
|
||||
if (empty($ticketReply)){
|
||||
throw new \Exception(lang_plugins('ticket_reply_is_not_exist'));
|
||||
}
|
||||
|
||||
if (!IdcsmartTicketLogic::checkUpstreamTicket($ticketReply['ticket_id'])){
|
||||
throw new \Exception(lang_plugins('ticket_upstream_cannot_operate'));
|
||||
}
|
||||
|
||||
$ticketReply->save([
|
||||
'content'=>$param['content']??'',
|
||||
'update_time'=>time()
|
||||
]);
|
||||
|
||||
# 记录日志
|
||||
$ticketId = $ticketReply['ticket_id'];
|
||||
if ($ticketReply['type']=='Admin'){
|
||||
$AdminModel = new AdminModel();
|
||||
$admin = $AdminModel->find($ticketReply['rel_id']);
|
||||
$name = $admin['name'];
|
||||
}else{
|
||||
$ClientModel = new ClientModel();
|
||||
$client = $ClientModel->find($ticketReply['rel_id']);
|
||||
$name = $client['username'];
|
||||
}
|
||||
|
||||
active_log(lang_plugins('ticket_log_admin_update_ticket_reply', ['{admin}'=>'admin#'.request()->admin_id.'#' .request()->admin_name.'#','{name}'=>$name]), 'addon_idcsmart_ticket', $ticketId);
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($ticketReply['ticket_id']);
|
||||
|
||||
IdcsmartTicketLogic::pushTicketReply($ticket,$ticketReply,$param);
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-09-23
|
||||
* @title 删除工单回复
|
||||
* @desc 删除工单回复
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单回复ID required
|
||||
*/
|
||||
public function ticketReplyDelete($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketReply = $this->where('id',$param['id'])->find();
|
||||
if (empty($ticketReply)){
|
||||
throw new \Exception(lang_plugins('ticket_reply_is_not_exist'));
|
||||
}
|
||||
if (!IdcsmartTicketLogic::checkUpstreamTicket($ticketReply['ticket_id'])){
|
||||
throw new \Exception(lang_plugins('ticket_upstream_cannot_operate'));
|
||||
}
|
||||
$ticketReply->delete();
|
||||
# 记录日志
|
||||
$ticketId = $ticketReply['ticket_id'];
|
||||
if ($ticketReply['type']=='Admin'){
|
||||
$AdminModel = new AdminModel();
|
||||
$admin = $AdminModel->find($ticketReply['rel_id']);
|
||||
$name = $admin['name'];
|
||||
}else{
|
||||
$ClientModel = new ClientModel();
|
||||
$client = $ClientModel->find($ticketReply['rel_id']);
|
||||
$name = $client['username'];
|
||||
}
|
||||
active_log(lang_plugins('ticket_log_admin_delete_ticket_reply', ['{admin}'=>'admin#'.request()->admin_id.'#' .request()->admin_name.'#','{name}'=>$name]), 'addon_idcsmart_ticket', $ticketId);
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
$IdcsmartTicketModel = new IdcsmartTicketModel();
|
||||
$ticket = $IdcsmartTicketModel->find($ticketReply['ticket_id']);
|
||||
|
||||
IdcsmartTicketLogic::pushTicketReplyDelete($ticket,$ticketReply,$param);
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* @时间 2024-12-09
|
||||
* @title 获取工单管理员最后回复时间
|
||||
* @desc 获取工单管理员最后回复时间,没回复返回0
|
||||
* @author hh
|
||||
* @version v1
|
||||
* @param int $id - 工单ID
|
||||
* @return int
|
||||
*/
|
||||
public function getAdminLastReplyTime($id)
|
||||
{
|
||||
$lastReplyTime = $this
|
||||
->where('ticket_id', $id)
|
||||
->where('type', 'Admin')
|
||||
->order('id', 'desc')
|
||||
->value('create_time');
|
||||
|
||||
return $lastReplyTime ?? 0;
|
||||
}
|
||||
|
||||
}
|
||||
196
plugins/addon/example/model/IdcsmartTicketStatusModel.php
Normal file
196
plugins/addon/example/model/IdcsmartTicketStatusModel.php
Normal file
@@ -0,0 +1,196 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketStatusModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_status';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'color' => 'string',
|
||||
'status' => 'int',
|
||||
'default' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单状态列表
|
||||
* @desc 工单状态列表
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @return array list - 工单状态列表
|
||||
* @return int list[].id - ID
|
||||
* @return string list[].name - 工单状态
|
||||
* @return string list[].color - 状态颜色
|
||||
* @return int list[].status - 完结状态:1完结,0未完结
|
||||
* @return int list[].default - 是否默认状态:0否,1是,默认状态无法修改删除
|
||||
*/
|
||||
public function ticketStatusList()
|
||||
{
|
||||
$list = $this->field('id,name,color,status,default')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'list' => $list
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 工单状态详情
|
||||
* @desc 工单状态详情
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单状态ID
|
||||
* @return int id - ID
|
||||
* @return string name - 工单状态
|
||||
* @return string color - 状态颜色
|
||||
* @return int status - 完结状态:1完结,0未完结
|
||||
*/
|
||||
public function ticketStatusIndex($param)
|
||||
{
|
||||
$ticketStatus = $this->field('id,name,color,status')
|
||||
->where('id',intval($param['id']))
|
||||
->find();
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
'data' => [
|
||||
'ticket_status' => $ticketStatus?:(object)[]
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 创建工单状态
|
||||
* @desc 创建工单状态
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param string name - 工单状态ID
|
||||
* @param string color - 状态颜色
|
||||
* @param int status - 完结状态:1完结,0未完结
|
||||
*/
|
||||
public function ticketStatusCreate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$this->insert([
|
||||
'name' => $param['name'],
|
||||
'color' => $param['color'],
|
||||
'status' => $param['status']??0,
|
||||
'create_time' =>time()
|
||||
]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 编辑工单状态
|
||||
* @desc 编辑工单状态
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单状态ID
|
||||
* @param string name - 工单状态ID
|
||||
* @param string color - 状态颜色
|
||||
* @param int status - 完结状态:1完结,0未完结
|
||||
*/
|
||||
public function ticketStatusUpdate($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketStatus = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketStatus)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_status_is_not_exist'));
|
||||
}
|
||||
|
||||
if ($ticketStatus['default']==1){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_status_cannot_update'));
|
||||
}
|
||||
|
||||
$ticketStatus->save([
|
||||
'name' => $param['name'],
|
||||
'color' => $param['color'],
|
||||
'status' => $param['status']??0,
|
||||
'update_time' =>time()
|
||||
]);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-10-21
|
||||
* @title 删除工单状态
|
||||
* @desc 删除工单状态
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单状态ID
|
||||
*/
|
||||
public function ticketStatusDelete($param)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
$ticketStatus = $this->find($param['id']);
|
||||
|
||||
if (empty($ticketStatus)){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_status_is_not_exist'));
|
||||
}
|
||||
|
||||
if ($ticketStatus['default']==1){
|
||||
throw new \Exception(lang_plugins('ticket_ticket_status_cannot_delete'));
|
||||
}
|
||||
|
||||
$ticketStatus->delete();
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return [
|
||||
'status' => 200,
|
||||
'msg' => lang_plugins('success_message'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use app\admin\model\AdminRoleModel;
|
||||
use think\db\Query;
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketTypeAdminLinkModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_type_admin_link';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'ticket_type_id' => 'int',
|
||||
'admin_id' => 'int',
|
||||
];
|
||||
|
||||
}
|
||||
253
plugins/addon/example/model/IdcsmartTicketTypeModel.php
Normal file
253
plugins/addon/example/model/IdcsmartTicketTypeModel.php
Normal file
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use app\admin\model\AdminRoleModel;
|
||||
use think\db\Query;
|
||||
use think\Model;
|
||||
use app\admin\model\AdminModel;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2022-06-20
|
||||
*/
|
||||
class IdcsmartTicketTypeModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_type';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'name' => 'string',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
];
|
||||
|
||||
public $isAdmin = false;
|
||||
|
||||
/**
|
||||
* 时间 2022-10-24
|
||||
* @title 工单部门
|
||||
* @desc 工单部门
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @return array list - 工单部门列表
|
||||
* @return int list[].id - 工单部门ID
|
||||
* @return string list[].name - 工单部门名称
|
||||
*/
|
||||
public function typeDepartment()
|
||||
{
|
||||
$departments = $this
|
||||
->field('id,name')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$data = [
|
||||
'list' => $departments
|
||||
];
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message'),'data'=>$data];
|
||||
}
|
||||
/**
|
||||
* 时间 2022-06-21
|
||||
* @title 工单部门列表
|
||||
* @desc 工单部门列表
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @return array list - 工单部门列表
|
||||
* @return int list[].id - 工单部门ID
|
||||
* @return int list[].name - 工单部门名称
|
||||
* @return int list[].admin[].id - 管理员ID
|
||||
* @return string list[].admin[].name - 管理员名称
|
||||
*/
|
||||
public function typeTicket($param)
|
||||
{
|
||||
if ($this->isAdmin){
|
||||
$ticketTypes = $this->alias('tt')
|
||||
->field('tt.id,tt.name')
|
||||
// ->where($where)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$admin = IdcsmartTicketTypeAdminLinkModel::alias('al')
|
||||
->field('al.ticket_type_id,a.id,a.name')
|
||||
->join('admin a', 'al.admin_id=a.id')
|
||||
->select()
|
||||
->toArray();
|
||||
$adminArr = [];
|
||||
foreach($admin as $v){
|
||||
$tid = $v['ticket_type_id'];
|
||||
unset($v['ticket_type_id']);
|
||||
$adminArr[$tid][] = $v;
|
||||
}
|
||||
|
||||
foreach($ticketTypes as $k=>$v){
|
||||
$ticketTypes[$k]['admin'] = $adminArr[$v['id']] ?? [];
|
||||
}
|
||||
}else{
|
||||
$ticketTypes = $this->alias('tt')
|
||||
->field('tt.id,tt.name')
|
||||
->select()
|
||||
->toArray();
|
||||
}
|
||||
|
||||
$data = [
|
||||
'list' => $ticketTypes
|
||||
];
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message'),'data'=>$data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-06-21
|
||||
* @title 工单部门详情
|
||||
* @desc 工单部门详情
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单部门ID required
|
||||
* @return object ticket_type - 工单部门详情
|
||||
* @return int ticket_type.id - 工单部门ID
|
||||
* @return string ticket_type.name - 工单部门名称
|
||||
* @return int admin[].id - 管理员ID
|
||||
* @return string admin[].name - 管理员名称
|
||||
*/
|
||||
public function indexTicketType($id)
|
||||
{
|
||||
$ticketType = $this->field('id,name')->find($id);
|
||||
if (empty($ticketType)){
|
||||
return ['status'=>400,'msg'=>lang_plugins('ticket_type_is_not_exist')];
|
||||
}
|
||||
|
||||
$admin = IdcsmartTicketTypeAdminLinkModel::alias('al')
|
||||
->field('a.id,a.name')
|
||||
->join('admin a', 'al.admin_id=a.id')
|
||||
->where('al.ticket_type_id', $id)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$ticketType->admin = $admin;
|
||||
|
||||
$data = [
|
||||
'ticket_type' => $ticketType
|
||||
];
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message'),'data'=>$data];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-06-21
|
||||
* @title 创建工单部门
|
||||
* @desc 创建工单部门
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param string name - 工单部门名称 required
|
||||
* @param array admin_id - 管理员ID required
|
||||
*/
|
||||
public function createTicketType($param)
|
||||
{
|
||||
$IdcsmartTicketTypeAdminLinkModel = new IdcsmartTicketTypeAdminLinkModel();
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ticketType = $this->create([
|
||||
'name' => $param['name'],
|
||||
'create_time' => time()
|
||||
]);
|
||||
|
||||
$link = [];
|
||||
foreach($param['admin_id'] as $v){
|
||||
$link[] = [
|
||||
'ticket_type_id' => $ticketType->id,
|
||||
'admin_id' => $v
|
||||
];
|
||||
}
|
||||
$IdcsmartTicketTypeAdminLinkModel->insertAll($link);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('success_message')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-06-21
|
||||
* @title 编辑工单部门
|
||||
* @desc 编辑工单部门
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单部门ID required
|
||||
* @param string name - 工单部门名称 required
|
||||
* @param array admin_id - 管理员ID required
|
||||
*/
|
||||
public function updateTicketType($param)
|
||||
{
|
||||
$IdcsmartTicketTypeAdminLinkModel = new IdcsmartTicketTypeAdminLinkModel();
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ticketType = $this->find($param['id']);
|
||||
if (empty($ticketType)){
|
||||
throw new \Exception(lang_plugins('ticket_type_is_not_exist'));
|
||||
}
|
||||
|
||||
$ticketType->save([
|
||||
'name' => $param['name'],
|
||||
'update_time' =>time()
|
||||
]);
|
||||
|
||||
$link = [];
|
||||
foreach($param['admin_id'] as $v){
|
||||
$link[] = [
|
||||
'ticket_type_id' => $ticketType->id,
|
||||
'admin_id' => $v
|
||||
];
|
||||
}
|
||||
IdcsmartTicketTypeAdminLinkModel::where('ticket_type_id', $param['id'])->delete();
|
||||
$IdcsmartTicketTypeAdminLinkModel->insertAll($link);
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('update_success')];
|
||||
}
|
||||
|
||||
/**
|
||||
* 时间 2022-06-21
|
||||
* @title 删除工单部门
|
||||
* @desc 删除工单部门
|
||||
* @author wyh
|
||||
* @version v1
|
||||
* @param int id - 工单部门ID required
|
||||
*/
|
||||
public function deleteTicketType($id)
|
||||
{
|
||||
$this->startTrans();
|
||||
|
||||
try{
|
||||
|
||||
$ticketType = $this->field('id,name')->find($id);
|
||||
if (empty($ticketType)){
|
||||
throw new \Exception(lang_plugins('ticket_type_is_not_exist'));
|
||||
}
|
||||
|
||||
# TODO 是否可以随意删除
|
||||
$ticketType->delete();
|
||||
IdcsmartTicketTypeAdminLinkModel::where('ticket_type_id', $id)->delete();
|
||||
|
||||
$this->commit();
|
||||
}catch (\Exception $e){
|
||||
$this->rollback();
|
||||
return ['status'=>400,'msg'=>$e->getMessage()];
|
||||
}
|
||||
|
||||
return ['status'=>200,'msg'=>lang_plugins('delete_success')];
|
||||
}
|
||||
|
||||
}
|
||||
26
plugins/addon/example/model/IdcsmartTicketUpstreamModel.php
Normal file
26
plugins/addon/example/model/IdcsmartTicketUpstreamModel.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
namespace addon\idcsmart_ticket\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/*
|
||||
* @author wyh
|
||||
* @time 2024-06-17
|
||||
*/
|
||||
class IdcsmartTicketUpstreamModel extends Model
|
||||
{
|
||||
protected $name = 'addon_idcsmart_ticket_upstream';
|
||||
|
||||
# 设置字段信息
|
||||
protected $schema = [
|
||||
'id' => 'int',
|
||||
'host_id' => 'int',
|
||||
'upstream_host_id' => 'int',
|
||||
'ticket_id' => 'int',
|
||||
'upstream_ticket_id' => 'int',
|
||||
'create_time' => 'int',
|
||||
'update_time' => 'int',
|
||||
'delivery_status' => 'int',
|
||||
];
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user