工单列表

This commit is contained in:
2025-07-04 15:04:29 +08:00
parent b70fc6c4f8
commit 388747634a
7 changed files with 22 additions and 12 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ return [
// 定义所有需要多语言支持的实体 // 定义所有需要多语言支持的实体
'entities' => [ 'entities' => [
'ticket_categorie' => [ 'ticket_categorie' => [
'translation_model' => \app\ticket\model\TicketCategorieTranslation::class, 'translation_model' => \app\ticket\model\CategorieTranslation::class,
'foreign_key' => 'categorie_id', 'foreign_key' => 'categorie_id',
], ],
], ],
+6 -6
View File
@@ -2,7 +2,7 @@
namespace app\ticket\logic; namespace app\ticket\logic;
use app\ticket\model\TicketCategorie; use app\ticket\model\Categorie;
use support\Log; use support\Log;
use support\exception\BusinessException; use support\exception\BusinessException;
@@ -13,20 +13,20 @@ class CategorieLogic
$where = []; $where = [];
$size = $params['size'] ?? 10; $size = $params['size'] ?? 10;
$current = $params['current'] ?? 1; $current = $params['current'] ?? 1;
return TicketCategorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current); return Categorie::with('translation')->where($where)->paginate($size, ['*'], 'page', $current);
} }
public function getAll($params) public function getAll($params)
{ {
$where = []; $where = [];
$where[] = ['status', '=', 1]; $where[] = ['status', '=', 1];
return TicketCategorie::with('translation')->where($where)->get(); return Categorie::with('translation')->where($where)->get();
} }
public function add(array $data) public function add(array $data)
{ {
try { try {
return TicketCategorie::create($data); return Categorie::create($data);
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::error('分类创建失败', [ Log::error('分类创建失败', [
'data' => $data, 'data' => $data,
@@ -39,7 +39,7 @@ class CategorieLogic
public function edit(array $data) public function edit(array $data)
{ {
try { try {
$categorie = TicketCategorie::updateOrCreate(['id' => $data['id']], $data); $categorie = Categorie::updateOrCreate(['id' => $data['id']], $data);
return $categorie; return $categorie;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::error('分类编辑失败', [ Log::error('分类编辑失败', [
@@ -53,7 +53,7 @@ class CategorieLogic
public function delete(int $id) public function delete(int $id)
{ {
try { try {
$categorie = TicketCategorie::where(['id'=>$id])->delete(); $categorie = Categorie::where(['id'=>$id])->delete();
return $categorie; return $categorie;
} catch (\Throwable $e) { } catch (\Throwable $e) {
Log::error('分类删除失败', [ Log::error('分类删除失败', [
+1 -1
View File
@@ -25,7 +25,7 @@ class TicketLogic
} }
$size = $params['size']; $size = $params['size'];
$current = $params['current']; $current = $params['current'];
return Ticket::with('attachments')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current); return Ticket::with('attachments')->with('categorie')->with('categorie.translation')->where($where)->orderBy('id','desc')->paginate($size, ['*'], 'page', $current);
} }
public function add(array $data) public function add(array $data)
{ {
@@ -14,7 +14,7 @@ use support\Model;
* @property string $updated_at 更新时间 * @property string $updated_at 更新时间
* @property string $deleted_at 删除时间 * @property string $deleted_at 删除时间
*/ */
class TicketCategorie extends Model class Categorie extends Model
{ {
use SoftDeletes; use SoftDeletes;
protected $connection = 'mysql'; protected $connection = 'mysql';
@@ -37,7 +37,7 @@ class TicketCategorie extends Model
*/ */
public function translation() public function translation()
{ {
return $this->hasOne(TicketCategorieTranslation::class, 'categorie_id')->where('locale', locale()); return $this->hasOne(CategorieTranslation::class, 'categorie_id')->where('locale', locale());
} }
/** /**
@@ -45,6 +45,10 @@ class TicketCategorie extends Model
*/ */
public function translations() public function translations()
{ {
return $this->hasMany(TicketCategorieTranslation::class, 'categorie_id'); return $this->hasMany(CategorieTranslation::class, 'categorie_id');
}
public function ticket(){
return $this->hasOne(Ticket::class, 'categorie_id', 'id');
} }
} }
@@ -14,7 +14,7 @@ use support\Model;
* @property string $created_at 创建时间 * @property string $created_at 创建时间
* @property string $updated_at 更新时间 * @property string $updated_at 更新时间
*/ */
class TicketCategorieTranslation extends Model class CategorieTranslation extends Model
{ {
protected $connection = 'mysql'; protected $connection = 'mysql';
protected $table = 'ticket_categorie_translation'; protected $table = 'ticket_categorie_translation';
+4
View File
@@ -70,4 +70,8 @@ class Ticket extends Model
public function attachments(){ public function attachments(){
return $this->hasMany(Attachment::class, 'ticket_id', 'id'); return $this->hasMany(Attachment::class, 'ticket_id', 'id');
} }
public function categorie(){
return $this->belongsTo(Categorie::class, 'categorie_id', 'id');
}
} }
+2
View File
@@ -18,6 +18,8 @@ class TicketService
{ {
$res = (new TicketLogic())->list($params); $res = (new TicketLogic())->list($params);
foreach ($res as $k => &$v) { foreach ($res as $k => &$v) {
$v['categorie']['name'] = isset($v['categorie']['translation']) ? $v['categorie']['translation']['name'] : '';
unset($v['categorie']['translation']);
foreach ($v['attachments'] as &$attachments) { foreach ($v['attachments'] as &$attachments) {
$attachments['storage_path_full'] = (new \app\common\service\OssService())->generatePrivateUrl($attachments['storage_path']); $attachments['storage_path_full'] = (new \app\common\service\OssService())->generatePrivateUrl($attachments['storage_path']);
} }