工单分类
This commit is contained in:
@@ -2,3 +2,25 @@
|
||||
/**
|
||||
* Here is your custom functions.
|
||||
*/
|
||||
|
||||
use support\exception\BusinessException;
|
||||
|
||||
/**
|
||||
* 获取配置
|
||||
*/
|
||||
function getConfig($filePath = null)
|
||||
{
|
||||
// 构建文件路径
|
||||
$config_file = app_path($filePath);
|
||||
// 检查文件是否存在
|
||||
if (!file_exists($config_file)) {
|
||||
return [];
|
||||
}
|
||||
// 包含文件并获取返回的数组
|
||||
$config = include $config_file;
|
||||
// 验证是否为数组
|
||||
if (!is_array($config)) {
|
||||
return [];
|
||||
}
|
||||
return $config;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
// 定义所有需要多语言支持的实体
|
||||
'entities' => [
|
||||
'ticket_categorie' => [
|
||||
'translation_model' => \app\ticket\model\TicketCategorieTranslation::class,
|
||||
'foreign_key' => 'categorie_id',
|
||||
],
|
||||
],
|
||||
|
||||
// 默认支持的目标语种列表
|
||||
'locales' => ['zh','en','ru','ar'],
|
||||
];
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace app\queue\translation\jobs;
|
||||
|
||||
use support\Log;
|
||||
use app\queue\translation\service\TranslatorClient;
|
||||
|
||||
class TranslationJob
|
||||
{
|
||||
protected $config = [];
|
||||
protected array $payload;
|
||||
|
||||
public function __construct(array $payload)
|
||||
{
|
||||
$this->config = getConfig('/queue/translation/config/trans.php');
|
||||
$this->payload = $payload;
|
||||
}
|
||||
|
||||
public function handle(): void
|
||||
{
|
||||
$cfgAll = $this->config['entities'];
|
||||
$pt = $this->payload;
|
||||
$type = $pt['entityType'];
|
||||
$id = $pt['entityId'];
|
||||
$locale = $pt['locale'];
|
||||
$sourceLocale = $pt['sourceLocale'];
|
||||
$sourceFields = $pt['sourceFields'];
|
||||
$clientFields = $pt['clientFields'];
|
||||
|
||||
if (! isset($cfgAll[$type])) {
|
||||
Log::warning("TranslationJob: 未配置实体 {$type}");
|
||||
return;
|
||||
}
|
||||
|
||||
$cfg = $cfgAll[$type];
|
||||
$modelClass = $cfg['translation_model'];
|
||||
$foreignKey = $cfg['foreign_key'];
|
||||
|
||||
// 决定采用前端提供、源语种还是第三方翻译
|
||||
if (! empty($clientFields)) {
|
||||
$fields = $clientFields;
|
||||
} elseif ($locale === $sourceLocale) {
|
||||
$fields = $sourceFields;
|
||||
} else {
|
||||
$translator = new TranslatorClient();
|
||||
$fields = [];
|
||||
foreach ($sourceFields as $key => $text) {
|
||||
$fields[$key] = $translator->translate($text, $sourceLocale, $locale);
|
||||
}
|
||||
}
|
||||
|
||||
// 写库
|
||||
try {
|
||||
$modelClass::updateOrCreate(
|
||||
[
|
||||
$foreignKey => $id,
|
||||
'locale' => $locale,
|
||||
],
|
||||
array_merge($fields, ['locale' => $locale])
|
||||
);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error("TranslationJob 保存失败: {$type}#{$id} locale={$locale}: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\translation\queue;
|
||||
|
||||
use support\Log;
|
||||
use Webman\RedisQueue\Consumer;
|
||||
use app\queue\translation\jobs\TranslationJob;
|
||||
|
||||
class Translation implements Consumer
|
||||
{
|
||||
// 要消费的队列名
|
||||
public $queue = 'transTask';
|
||||
|
||||
// 连接名,对应 plugin/webman/redis-queue/redis.php 里的连接`
|
||||
public $connection = 'default';
|
||||
|
||||
// 消费
|
||||
public function consume($data)
|
||||
{
|
||||
try {
|
||||
// 无需反序列化
|
||||
// var_export($data); // 输出 ['to' => 'tom@gmail.com', 'content' => 'hello']
|
||||
|
||||
$job = new TranslationJob($data);
|
||||
$job->handle();
|
||||
} catch (\Throwable $e) {
|
||||
Log::error("TranslationService 异步任务异常: ".$e->getMessage());
|
||||
}
|
||||
}
|
||||
// 消费失败回调
|
||||
/*
|
||||
$package = [
|
||||
'id' => 1357277951, // 消息ID
|
||||
'time' => 1709170510, // 消息时间
|
||||
'delay' => 0, // 延迟时间
|
||||
'attempts' => 2, // 消费次数
|
||||
'queue' => 'send-mail', // 队列名
|
||||
'data' => ['to' => 'tom@gmail.com', 'content' => 'hello'], // 消息内容
|
||||
'max_attempts' => 5, // 最大重试次数
|
||||
'error' => '错误信息' // 错误信息
|
||||
]
|
||||
*/
|
||||
public function onConsumeFailure(\Throwable $e, $package)
|
||||
{
|
||||
echo "consume failure\n";
|
||||
echo $e->getMessage() . "\n";
|
||||
// 无需反序列化
|
||||
var_export($package);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
namespace app\queue\translation\service;
|
||||
|
||||
// use Webman\RedisQueue\Client;
|
||||
use Webman\RedisQueue\Redis;
|
||||
|
||||
class TranslationService
|
||||
{
|
||||
|
||||
// 配置
|
||||
protected $config = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->config = getConfig('/queue/translation/config/trans.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步排队所有语种的翻译任务
|
||||
*
|
||||
* @param string $entityType 实体名,如 'vehicle'
|
||||
* @param int $entityId 主表 ID
|
||||
* @param string $sourceLocale 源语种,如 'zh'
|
||||
* @param array $sourceFields 源语种字段 ['name'=>…,'condition_desc'=>…]
|
||||
* @param array $clientFields 前端已传翻译 ['en'=>[...], …]
|
||||
*/
|
||||
public function queueTranslations(string $entityType, int $entityId, string $sourceLocale, array $sourceFields, array $clientFields = []): void
|
||||
{
|
||||
foreach ($this->config['locales'] as $locale) {
|
||||
$payload = [
|
||||
'entityType' => $entityType,
|
||||
'entityId' => $entityId,
|
||||
'locale' => $locale,
|
||||
'sourceLocale' => $sourceLocale,
|
||||
'sourceFields' => $sourceFields,
|
||||
'clientFields' => $clientFields[$locale] ?? [],
|
||||
];
|
||||
Redis::send('transTask', $payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
namespace app\queue\translation\service;
|
||||
|
||||
use app\queue\utils\XunfeiFanyi;
|
||||
use support\Log;
|
||||
|
||||
class TranslatorClient
|
||||
{
|
||||
|
||||
// protected string $endpoint;
|
||||
// protected string $apiKey;
|
||||
|
||||
// public function __construct()
|
||||
// {
|
||||
// $this->endpoint = env('TRANSLATION_API_URL');
|
||||
// $this->apiKey = env('TRANSLATION_API_KEY');
|
||||
// }
|
||||
|
||||
/**
|
||||
* 翻译文本
|
||||
* @throws \RuntimeException
|
||||
*/
|
||||
public function translate(string $text, string $from = 'cn', string $to = 'ru'): string
|
||||
{
|
||||
try {
|
||||
$xunfei = new XunfeiFanyi();
|
||||
$rst_dst = $xunfei->fanyi($text, $from, $to);
|
||||
if ($rst_dst) {
|
||||
return $rst_dst["trans_result"]["dst"];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
} catch (\Throwable $e) {
|
||||
Log::error("TranslatorClient 错误: ".$e->getMessage());
|
||||
throw new \RuntimeException('翻译服务调用失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\utils;
|
||||
|
||||
class Translat
|
||||
{
|
||||
/**
|
||||
* 从$data中提取出源文本字段,并从$data里删除它们
|
||||
*/
|
||||
public static function extractSourceFields(array &$data,array $translat): array
|
||||
{
|
||||
$source = [];
|
||||
foreach ($translat as $field) {
|
||||
if (array_key_exists($field, $data)) {
|
||||
$source[$field] = $data[$field];
|
||||
unset($data[$field]);
|
||||
}
|
||||
}
|
||||
return $source;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace app\queue\utils;
|
||||
|
||||
|
||||
class XunfeiFanyi
|
||||
{
|
||||
|
||||
protected $error = "";
|
||||
|
||||
public function tocurl($url, $header, $content)
|
||||
{
|
||||
$ch = curl_init();
|
||||
if(substr($url,0,5)=='https'){
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
|
||||
curl_setopt($ch, CURLOPT_SSLVERSION, 1);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
if (is_array($header)) {
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
||||
}
|
||||
curl_setopt($ch, CURLOPT_POST, true);
|
||||
if (!empty($content)) {
|
||||
if (is_array($content)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($content));
|
||||
} else if (is_string($content)) {
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $content);
|
||||
}
|
||||
}
|
||||
$response = curl_exec($ch);
|
||||
$error=curl_error($ch);
|
||||
//var_dump($error);
|
||||
if($error){
|
||||
die($error);
|
||||
}
|
||||
$header = curl_getinfo($ch);
|
||||
curl_close($ch);
|
||||
$data = array('header' => $header,'body' => $response);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function xfyun($text = "中华人民共和国于1949年成立", $from = "cn", $to = "en")
|
||||
{
|
||||
//在控制台-我的应用-机器翻译获取
|
||||
$app_id = "3d46198c";
|
||||
//在控制台-我的应用-机器翻译获取
|
||||
$api_sec = "ZWY2MmUyNjJjYmFkOTFlYTVmYWVhMGYy";
|
||||
//在控制台-我的应用-机器翻译获取
|
||||
$api_key = "b6d805f240176ecaea85130cb5f2bca1";
|
||||
// 机器翻译接口地址
|
||||
$url = "https://ntrans.xfyun.cn/v2/ots";
|
||||
//body组装
|
||||
// $text = "中华人民共和国于1949年成立";//待翻译文本
|
||||
$body = json_encode($this->getBody($app_id, $from, $to, $text));
|
||||
|
||||
// 组装http请求头
|
||||
$date =gmdate('D, d M Y H:i:s') . ' GMT';
|
||||
|
||||
$digestBase64 = "SHA-256=".base64_encode(hash("sha256", $body, true));
|
||||
$builder = sprintf("host: %s
|
||||
date: %s
|
||||
POST /v2/ots HTTP/1.1
|
||||
digest: %s", "ntrans.xfyun.cn", $date, $digestBase64);
|
||||
// echo($builder);
|
||||
$sha = base64_encode(hash_hmac("sha256", $builder, $api_sec, true));
|
||||
|
||||
$authorization = sprintf("api_key=\"%s\", algorithm=\"%s\", headers=\"%s\", signature=\"%s\"", $api_key,"hmac-sha256",
|
||||
"host date request-line digest", $sha);
|
||||
|
||||
$header = [
|
||||
"Authorization: ".$authorization,
|
||||
'Content-Type: application/json',
|
||||
'Accept: application/json,version=1.0',
|
||||
'Host: ntrans.xfyun.cn',
|
||||
'Date: ' .$date,
|
||||
'Digest: '.$digestBase64
|
||||
];
|
||||
$response = $this->tocurl($url, $header, $body);
|
||||
|
||||
// var_dump($response['body']);
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
public function getBody($app_id, $from, $to, $text)
|
||||
{
|
||||
$common_param = [
|
||||
'app_id' => $app_id
|
||||
];
|
||||
|
||||
$business = [
|
||||
'from' => $from,
|
||||
'to' => $to,
|
||||
];
|
||||
|
||||
$data = [
|
||||
"text" => base64_encode($text)
|
||||
];
|
||||
|
||||
return $body = [
|
||||
'common' => $common_param,
|
||||
'business' => $business,
|
||||
'data' => $data
|
||||
];
|
||||
}
|
||||
|
||||
// 翻译
|
||||
public function fanyi($text = "", $from = "", $to = "")
|
||||
{
|
||||
try {
|
||||
$res = $this->xfyun($text, $from, $to);
|
||||
$data = json_decode($res["body"], true);
|
||||
if ($data["code"] === 0) {
|
||||
return $data["data"]["result"];
|
||||
} else {
|
||||
$this->error = $data["message"];
|
||||
return false;
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
$this->error = $th->getMessage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 异常
|
||||
public function error()
|
||||
{
|
||||
return $this->error;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\controller;
|
||||
|
||||
use app\ticket\service\CategorieService;
|
||||
use support\Request;
|
||||
|
||||
class CategorieController extends BaseController
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = (new CategorieService())->list($request->all());
|
||||
return $this->success($this->page($result));
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function getAll(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = (new CategorieService())->getAll($request->all());
|
||||
return $this->success($result);
|
||||
} catch (\Throwable $e) {
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public function add(Request $request)
|
||||
{
|
||||
try {
|
||||
return (new CategorieService())->add($request->all())
|
||||
? $this->success()
|
||||
: $this->error();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage().' '.$th->getLine().' '.$th->getFile());
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(Request $request)
|
||||
{
|
||||
try {
|
||||
$result = (new CategorieService())->edit($request->all());
|
||||
return $result
|
||||
? $this->success($result)
|
||||
: $this->error();
|
||||
} catch (\Throwable $th) {
|
||||
return $this->error($th->getMessage().' '.$th->getLine().' '.$th->getFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\logic;
|
||||
|
||||
use app\ticket\model\TicketCategorie;
|
||||
use support\Log;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class CategorieLogic
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
$where = [];
|
||||
$size = $params['size'] ?? 10;
|
||||
$current = $params['current'] ?? 1;
|
||||
return TicketCategorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current);
|
||||
}
|
||||
|
||||
public function getAll($params)
|
||||
{
|
||||
$where = [];
|
||||
$where[] = ['status', '=', 1];
|
||||
return TicketCategorie::with('translation')->where($where)->get();
|
||||
}
|
||||
|
||||
public function add(array $data)
|
||||
{
|
||||
try {
|
||||
return TicketCategorie::create($data);
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('分类创建失败', [
|
||||
'data' => $data,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw new BusinessException($e->getMessage().'分类创建失败,请稍后重试', 500);
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $data)
|
||||
{
|
||||
try {
|
||||
$categorie = TicketCategorie::updateOrCreate(['id' => $data['id']], $data);
|
||||
return $categorie;
|
||||
} catch (\Throwable $e) {
|
||||
Log::error('分类编辑失败', [
|
||||
'data' => $data,
|
||||
'error' => $e->getMessage()
|
||||
]);
|
||||
throw new BusinessException($e->getMessage().'分类编辑失败,请稍后重试', 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,15 @@ class TicketLogic
|
||||
public function list($params)
|
||||
{
|
||||
$where = [];
|
||||
if(!empty($params['categorie_id'])){
|
||||
$where[] = ['categorie_id', '=', $params['categorie_id']];
|
||||
}
|
||||
if(!empty($params['status'])){
|
||||
$where[] = ['status', '=', $params['status']];
|
||||
}
|
||||
$size = $params['size'];
|
||||
$current = $params['current'];
|
||||
return Ticket::with('attachments')->where($where)->paginate($size, ['*'], 'page', $current);
|
||||
return Ticket::with('attachments')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current);
|
||||
}
|
||||
public function add(array $data)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* ticket_categorie 工单分类表
|
||||
* @property integer $id 主键
|
||||
* @property string $name 分类名称
|
||||
* @property string $description 分类描述
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
*/
|
||||
class TicketCategorie extends Model
|
||||
{
|
||||
protected $connection = 'mysql';
|
||||
protected $table = 'ticket_categorie';
|
||||
protected $primaryKey = 'id';
|
||||
public $timestamps = true;
|
||||
protected $dateFormat = 'U';
|
||||
protected $dates = ['created_at', 'updated_at'];
|
||||
protected $casts = [
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
|
||||
/**
|
||||
* 单条翻译
|
||||
*/
|
||||
public function translation()
|
||||
{
|
||||
return $this->hasOne(TicketCategorieTranslation::class, 'categorie_id')->where('locale', locale());
|
||||
}
|
||||
|
||||
/**
|
||||
* 多条翻译
|
||||
*/
|
||||
public function translations()
|
||||
{
|
||||
return $this->hasMany(TicketCategorieTranslation::class, 'categorie_id');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\model;
|
||||
|
||||
use support\Model;
|
||||
|
||||
/**
|
||||
* ticket_categorie_translation 工单分类多语言表
|
||||
* @property integer $id 主键
|
||||
* @property integer $categorie_id 分类ID
|
||||
* @property string $locale 语言
|
||||
* @property string $name 分类名称
|
||||
* @property string $description 分类描述
|
||||
* @property string $created_at 创建时间
|
||||
* @property string $updated_at 更新时间
|
||||
*/
|
||||
class TicketCategorieTranslation extends Model
|
||||
{
|
||||
protected $connection = 'mysql';
|
||||
protected $table = 'ticket_categorie_translation';
|
||||
protected $primaryKey = 'id';
|
||||
public $timestamps = true;
|
||||
protected $dateFormat = 'U';
|
||||
protected $dates = ['created_at', 'updated_at'];
|
||||
protected $casts = [
|
||||
'updated_at' => 'datetime:Y-m-d H:i:s',
|
||||
'created_at' => 'datetime:Y-m-d H:i:s',
|
||||
];
|
||||
protected $fillable = [
|
||||
'categorie_id',
|
||||
'locale',
|
||||
'name',
|
||||
'description',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
namespace app\ticket\service;
|
||||
|
||||
use app\queue\translation\service\TranslationService;
|
||||
use app\queue\utils\Translat;
|
||||
use app\ticket\logic\CategorieLogic;
|
||||
use support\Db;
|
||||
use support\exception\BusinessException;
|
||||
|
||||
class CategorieService
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
$result = (new CategorieLogic())->list($params);
|
||||
|
||||
foreach ($result as $key => &$value) {
|
||||
$value['name'] = isset($item['translation']) ? $item['translation']['name'] : '';
|
||||
unset($value['translation']);
|
||||
}
|
||||
unset($value);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getAll($params)
|
||||
{
|
||||
$result = (new CategorieLogic())->getAll($params);
|
||||
foreach ($result as $key => &$value) {
|
||||
$value['name'] =isset($item['translation']) ? $item['translation']['name'] : '';
|
||||
unset($value['translation']);
|
||||
}
|
||||
unset($value);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public $translatFields = ['name'];
|
||||
|
||||
public function add(array $data)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$sourceLocale = locale();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
$result = (new CategorieLogic())->add($data);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'ticket_categorie',
|
||||
$result->id,
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
|
||||
Db::commit();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
public function edit(array $data)
|
||||
{
|
||||
try {
|
||||
Db::beginTransaction();
|
||||
$sourceLocale = locale();
|
||||
$traitsourceFields = Translat::extractSourceFields($data, $this->translatFields);
|
||||
|
||||
$result = (new CategorieLogic())->edit($data);
|
||||
|
||||
(new TranslationService())->queueTranslations(
|
||||
'ticket_categorie',
|
||||
$data['id'],
|
||||
$sourceLocale,
|
||||
$traitsourceFields
|
||||
);
|
||||
Db::commit();
|
||||
return $result;
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,8 @@ class ConversationService
|
||||
{
|
||||
public function list($params)
|
||||
{
|
||||
// $locale = locale();
|
||||
$locale = 'zh';
|
||||
$locale = locale();
|
||||
// $locale = 'zh';
|
||||
$ticket_status = $locale == 'zh'? Constants::TICKET_STATUS_ZH:Constants::TICKET_STATUS_EN;
|
||||
// $ticket_status = Constants::TICKET_STATUS_ZH;
|
||||
// $params['locale'] = locale();
|
||||
@@ -30,7 +30,6 @@ class ConversationService
|
||||
try {
|
||||
return (new ConversationLogic())->add($data);
|
||||
} catch (\Throwable $e) {
|
||||
Db::rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ class TicketService
|
||||
throw new BusinessException('工单不存在');
|
||||
}
|
||||
if($data['status'] == $ticket->status){
|
||||
throw new BusinessException('状态未修改');
|
||||
throw new BusinessException(trans('status_not_modified'));
|
||||
}
|
||||
|
||||
// if(!in_array($ticket->status, [Constants::TICKET_STATUS['PENDING'], Constants::TICKET_STATUS['CONFIRM']])
|
||||
|
||||
+3
-1
@@ -39,7 +39,9 @@
|
||||
"league/oauth2-server": "^9.2",
|
||||
"topthink/think-validate": "^3.0",
|
||||
"shopwwi/webman-filesystem": "1.1",
|
||||
"shopwwi/filesystem-oss": "^1.0"
|
||||
"shopwwi/filesystem-oss": "^1.0",
|
||||
"webman/redis-queue": "^1.3",
|
||||
"symfony/translation": "^7.3"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-event": "For better performance. "
|
||||
|
||||
Generated
+129
-2
@@ -4,7 +4,7 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "7421030f864dacf31b06378e1045d034",
|
||||
"content-hash": "acb636fcb8774558a04bd674f9f95f55",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aliyuncs/oss-sdk-php",
|
||||
@@ -5365,7 +5365,13 @@
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/translation/zipball/4aba29076a29a3aa667e09b791e5f868973a8667",
|
||||
"reference": "4aba29076a29a3aa667e09b791e5f868973a8667",
|
||||
"shasum": ""
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=8.2",
|
||||
@@ -6147,6 +6153,43 @@
|
||||
},
|
||||
"time": "2025-03-14T03:52:14+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webman/redis-queue",
|
||||
"version": "v1.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/webman-php/redis-queue.git",
|
||||
"reference": "6fd491b19acb006d60931724aa2577a046ccb612"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/webman-php/redis-queue/zipball/6fd491b19acb006d60931724aa2577a046ccb612",
|
||||
"reference": "6fd491b19acb006d60931724aa2577a046ccb612",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"workerman/redis-queue": "^1.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Webman\\RedisQueue\\": "./src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"description": "Redis message queue plugin for webman.",
|
||||
"support": {
|
||||
"issues": "https://github.com/webman-php/redis-queue/issues",
|
||||
"source": "https://github.com/webman-php/redis-queue/tree/v1.3.1"
|
||||
},
|
||||
"time": "2024-02-28T07:21:52+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/coroutine",
|
||||
"version": "v1.1.3",
|
||||
@@ -6186,6 +6229,90 @@
|
||||
},
|
||||
"time": "2025-02-17T03:34:21+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/redis",
|
||||
"version": "v2.0.4",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/walkor/redis.git",
|
||||
"reference": "82b398c5bdd5d683a3458aaf645b159b7b39b84e"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/walkor/redis/zipball/82b398c5bdd5d683a3458aaf645b159b7b39b84e",
|
||||
"reference": "82b398c5bdd5d683a3458aaf645b159b7b39b84e",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7",
|
||||
"workerman/workerman": "^4.1.0||^5.0.0"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Workerman\\Redis\\": "./src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"homepage": "http://www.workerman.net",
|
||||
"support": {
|
||||
"issues": "https://github.com/walkor/redis/issues",
|
||||
"source": "https://github.com/walkor/redis/tree/v2.0.4"
|
||||
},
|
||||
"time": "2025-04-05T07:45:12+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/redis-queue",
|
||||
"version": "v1.2.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/walkor/redis-queue.git",
|
||||
"reference": "75dbf7ed2ea228c45dc0df82c0fea35879b715d0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/walkor/redis-queue/zipball/75dbf7ed2ea228c45dc0df82c0fea35879b715d0",
|
||||
"reference": "75dbf7ed2ea228c45dc0df82c0fea35879b715d0",
|
||||
"shasum": "",
|
||||
"mirrors": [
|
||||
{
|
||||
"url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
|
||||
"preferred": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.0",
|
||||
"workerman/redis": "^1.0||^2.0",
|
||||
"workerman/workerman": ">=4.0.20"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Workerman\\RedisQueue\\": "./src"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "Message queue system written in PHP based on workerman and backed by Redis.",
|
||||
"homepage": "http://www.workerman.net",
|
||||
"support": {
|
||||
"issues": "https://github.com/walkor/redis-queue/issues",
|
||||
"source": "https://github.com/walkor/redis-queue/tree/v1.2.1"
|
||||
},
|
||||
"time": "2025-01-02T09:21:45+00:00"
|
||||
},
|
||||
{
|
||||
"name": "workerman/webman-framework",
|
||||
"version": "v2.1.2",
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
<?php
|
||||
return [
|
||||
'enable' => true,
|
||||
];
|
||||
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
use Webman\RedisQueue\Command\MakeConsumerCommand;
|
||||
|
||||
return [
|
||||
MakeConsumerCommand::class
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is part of webman.
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* For full copyright and license information, please see the MIT-LICENSE.txt
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @author walkor<walkor@workerman.net>
|
||||
* @copyright walkor<walkor@workerman.net>
|
||||
* @link http://www.workerman.net/
|
||||
* @license http://www.opensource.org/licenses/mit-license.php MIT License
|
||||
*/
|
||||
|
||||
return [
|
||||
'default' => [
|
||||
'handlers' => [
|
||||
[
|
||||
'class' => Monolog\Handler\RotatingFileHandler::class,
|
||||
'constructor' => [
|
||||
runtime_path() . '/logs/redis-queue/queue.log',
|
||||
7, //$maxFiles
|
||||
Monolog\Logger::DEBUG,
|
||||
],
|
||||
'formatter' => [
|
||||
'class' => Monolog\Formatter\LineFormatter::class,
|
||||
'constructor' => [null, 'Y-m-d H:i:s', true],
|
||||
],
|
||||
]
|
||||
],
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
return [
|
||||
'consumer' => [
|
||||
'handler' => Webman\RedisQueue\Process\Consumer::class,
|
||||
'count' => getenv('REDIS_QUEUE_PROCESS_COUNT'), // 可以设置多进程同时消费
|
||||
'constructor' => [
|
||||
// 消费者类目录
|
||||
// 'consumer_dir' => app_path() . '/queue/redis'
|
||||
'consumer_dir' => app_path() . getenv('REDIS_QUEUE_CONSUMER_DIR')
|
||||
]
|
||||
]
|
||||
];
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
return [
|
||||
'default' => [
|
||||
// 'host' => 'redis://127.0.0.1:6379',
|
||||
'host' => getenv('REDIS_QUEUE_HOST'),
|
||||
'options' => [
|
||||
'auth' => getenv('REDIS_QUEUE_AUTH'), // 密码,字符串类型,可选参数
|
||||
'db' => getenv('REDIS_QUEUE_DB'), // 数据库
|
||||
'prefix' => getenv('REDIS_QUEUE_PREFIX'), // key 前缀
|
||||
'max_attempts' => getenv('REDIS_QUEUE_MAX_ATTEMPTS'), // 消费失败后,重试次数
|
||||
'retry_seconds' => getenv('REDIS_QUEUE_RETRY_SECONDS'), // 重试间隔,单位秒
|
||||
],
|
||||
// Connection pool, supports only Swoole or Swow drivers.
|
||||
'pool' => [
|
||||
'max_connections' => 5,
|
||||
'min_connections' => 1,
|
||||
'wait_timeout' => 3,
|
||||
'idle_timeout' => 60,
|
||||
'heartbeat_interval' => 50,
|
||||
]
|
||||
],
|
||||
];
|
||||
@@ -50,5 +50,11 @@ Route::group('/ticket', function () {
|
||||
Route::any('/conversation/edit', [app\ticket\controller\ConversationController::class, 'edit']);
|
||||
Route::any('/conversation/list', [app\ticket\controller\ConversationController::class, 'index']);
|
||||
|
||||
//工单分类
|
||||
Route::any('/categorie/add', [app\ticket\controller\CategorieController::class, 'add']);
|
||||
Route::any('/categorie/edit', [app\ticket\controller\CategorieController::class, 'edit']);
|
||||
Route::any('/categorie/list', [app\ticket\controller\CategorieController::class, 'index']);
|
||||
Route::any('/categorie/getAll', [app\ticket\controller\CategorieController::class, 'getAll']);
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'status_not_modified' => 'الوضع لم يتغير',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'status_not_modified' => 'status not modified',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'status_not_modified' => 'Статус не изменен',
|
||||
];
|
||||
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'status_not_modified' => '状态未修改',
|
||||
];
|
||||
Reference in New Issue
Block a user