mirror of
https://github.com/lkddi/Xboard.git
synced 2026-04-27 14:17:28 +08:00
fix: ticket reply_status semantics, N+1 query, and admin reply auto-reopen
This commit is contained in:
@@ -39,6 +39,9 @@ class Ticket extends Model
|
||||
self::STATUS_CLOSED => '关闭'
|
||||
];
|
||||
|
||||
const REPLY_STATUS_WAITING = 0;
|
||||
const REPLY_STATUS_REPLIED = 1;
|
||||
|
||||
public function user(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(User::class, 'user_id', 'id');
|
||||
|
||||
@@ -29,6 +29,7 @@ class TicketMessage extends Model
|
||||
];
|
||||
|
||||
protected $appends = ['is_from_user', 'is_from_admin'];
|
||||
protected $hidden = ['ticket'];
|
||||
|
||||
/**
|
||||
* 关联的工单
|
||||
@@ -43,7 +44,7 @@ class TicketMessage extends Model
|
||||
*/
|
||||
public function getIsFromUserAttribute(): bool
|
||||
{
|
||||
return $this->ticket->user_id === $this->user_id;
|
||||
return $this->ticket && $this->ticket->user_id === $this->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -51,6 +52,6 @@ class TicketMessage extends Model
|
||||
*/
|
||||
public function getIsFromAdminAttribute(): bool
|
||||
{
|
||||
return $this->ticket->user_id !== $this->user_id;
|
||||
return $this->ticket && $this->ticket->user_id !== $this->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user