This commit is contained in:
2026-01-05 14:33:21 +08:00
commit ee348b4925
451 changed files with 39954 additions and 0 deletions
+82
View File
@@ -0,0 +1,82 @@
<?php
namespace app\ticket\logic;
use app\common\model\UserTokenLog;
use app\common\model\Systems;
use app\common\model\User;
use app\common\model\UserSn;
use app\common\utils\Jwt;
use app\ticket\model\Attachment;
use app\ticket\model\Ticket;
use support\Redis;
use support\exception\BusinessException;
use support\Log;
class AttachmentLogic
{
public function adds(array $data,int $ticket_id,int $user_id)
{
try {
foreach ($data as $k=>$v){
$v['ticket_id'] = $ticket_id;
$v['user_id'] = $user_id;
$res = Attachment::create($v);
}
return $res;
} catch (\Throwable $e) {
Log::error('工单创建失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('工单创建失败,请稍后重试', 500);
}
}
public function edit(array $data,int $ticket_id,int $user_id)
{
try {
$attachmentsId = [];
foreach ($data as $k=>$v){
$v['ticket_id'] = $ticket_id;
$v['user_id'] = $user_id;
if(!empty($v['id'])){ //修改附件
$attachmentId = $v['id'];
$attachmentsId[] = $attachmentId;
// $v_res = Attachment::update($attachmentId, $v);
$v_res = Attachment::updateOrCreate(['id' => $v['id']],$v);
if (!$v_res) {
throw new BusinessException('附件保存失败');
}
} else { //新增附件
unset($v['id']);
$v_res = Attachment::create($v);
if (!$v_res) {
throw new BusinessException('附件创建失败');
}
$vId = $v_res->id;
$attachmentsId[] = $vId;
}
}
//删除本次没有出现的附件
$res = Attachment::whereNotIn('id', $attachmentsId)->where('ticket_id',$ticket_id)->delete();
return $res;
} catch (\Throwable $e) {
Log::error('工单编辑(附件)失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('工单编辑失败,请稍后重试', 500);
}
}
public static function generateSimpleTicketNo(): string
{
$date = date('Ymd'); // 日期
$prefix = 'GD'; // 前缀
$random = strtoupper(substr(md5(uniqid()), 0, 5)); // 5位随机字母数字
return $prefix . $date . '-' . $random; // 如 GD20240702-AB3X9Z
}
}
+74
View File
@@ -0,0 +1,74 @@
<?php
namespace app\ticket\logic;
use app\ticket\model\Categorie;
use support\Log;
use support\exception\BusinessException;
class CategorieLogic
{
public function list($params)
{
$where = [];
$size = $params['size'] ?? 10;
$current = $params['current'] ?? 1;
return Categorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current);
}
public function getAll($params)
{
$where = [];
$where[] = ['status', '=', 1];
return Categorie::with('translation')->where($where)->get();
}
public function find($id)
{
return Categorie::with(['translation' => function ($query) {
$query->where('locale', locale());
}])->where('status', 1)
->find($id);
}
public function add(array $data)
{
try {
return Categorie::create($data);
} catch (\Throwable $e) {
Log::error('分类创建失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('分类创建失败,请稍后重试', 500);
}
}
public function edit(array $data)
{
try {
$categorie = Categorie::updateOrCreate(['id' => $data['id']], $data);
return $categorie;
} catch (\Throwable $e) {
Log::error('分类编辑失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('分类编辑失败,请稍后重试', 500);
}
}
public function delete(int $id)
{
try {
$categorie = Categorie::where(['id'=>$id])->delete();
return $categorie;
} catch (\Throwable $e) {
Log::error('分类删除失败', [
'id' => $id,
'error' => $e->getMessage()
]);
throw new BusinessException('分类删除失败,请稍后重试', 500);
}
}
}
+60
View File
@@ -0,0 +1,60 @@
<?php
namespace app\ticket\logic;
use app\ticket\model\Conversation;
use support\Log;
use support\exception\BusinessException;
class ConversationLogic
{
public function list($params)
{
$where = [];
if (!empty($params['ticket_id'])) {
$where['ticket_id'] = $params['ticket_id'];
}
$size = $params['size'] ?? 10;
$current = $params['current'] ?? 1;
return Conversation::where($where)->paginate($size, ['*'], 'page', $current);
}
public function add(array $data)
{
try {
return Conversation::create($data);
} catch (\Throwable $e) {
Log::error('会话创建失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('会话创建失败,请稍后重试', 500);
}
}
public function edit(array $data)
{
try {
$conversation = Conversation::updateOrCreate(['id' => $data['id']], $data);
return $conversation;
} catch (\Throwable $e) {
Log::error('会话编辑失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('会话编辑失败,请稍后重试', 500);
}
}
/**
* 获取工单最新一条记录
* @param array $data
* @return Conversation|\Illuminate\Database\Eloquent\Model|object|null
*/
public function firstByTicket(int $ticketId)
{
$conversation = Conversation::where('ticket_id',$ticketId)
->orderBy('id','desc')
->first();
return $conversation;
}
}
+77
View File
@@ -0,0 +1,77 @@
<?php
namespace app\ticket\logic;
use app\common\model\UserTokenLog;
use app\common\model\Systems;
use app\common\model\User;
use app\common\model\UserSn;
use app\common\utils\Jwt;
use app\ticket\model\Ticket;
use support\Redis;
use support\exception\BusinessException;
use support\Log;
class TicketLogic
{
public function list($params)
{
$where = [];
if(!empty($params['categorie_id'])){
$where[] = ['categorie_id', '=', $params['categorie_id']];
}
if(!empty($params['user_id'])){
$where[] = ['user_id', '=', $params['user_id']];
}
if(!empty($params['status'])){
$where[] = ['status', '=', $params['status']];
}
$size = $params['size']??10;
$current = $params['current']??1;
return Ticket::with('attachments')->with('categorie')->with('categorie.translation')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current);
}
public function add(array $data)
{
$data['status'] = 1;
$data['code'] = self::generateSimpleTicketNo();
try {
return Ticket::create($data);
} catch (\Throwable $e) {
Log::error('工单创建失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('工单创建失败,请稍后重试', 500);
}
}
public function edit(array $data)
{
try {
unset($data['code']);
$ticket = Ticket::updateOrCreate(['id' => $data['id']],$data);
return $ticket;
} catch (\Throwable $e) {
Log::error('工单编辑失败', [
'data' => $data,
'error' => $e->getMessage()
]);
throw new BusinessException('工单编辑失败,请稍后重试', 500);
}
}
public function find(int $id)
{
$ticket = Ticket::find($id);
return $ticket;
}
public static function generateSimpleTicketNo(): string
{
$date = date('Ymd'); // 日期
$prefix = 'GD'; // 前缀
$random = strtoupper(substr(md5(uniqid()), 0, 5)); // 5位随机字母数字
return $prefix . $date . '-' . $random; // 如 GD20240702-AB3X9Z
}
}