- VmProvisionException/VmProvisionRefund xử lý lỗi cấp phát VM - QueueJobInspector + QueueMonitorController xem chi tiết job - Thêm service uuid cho ticket, thời lượng cho activity_logs - Migration chuẩn hoá RAM addon sang MB, trạng thái deleting cho snapshot Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
96 lines
2.5 KiB
PHP
96 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Traits\LogsActivity;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Collection;
|
|
|
|
class Ticket extends Model
|
|
{
|
|
use HasFactory, LogsActivity;
|
|
|
|
public const UNRESOLVED_STATUSES = ['open', 'pending'];
|
|
|
|
public const STATUS_LABELS = [
|
|
'open' => 'Mở',
|
|
'pending' => 'Đang xử lý',
|
|
'resolved' => 'Đã giải quyết',
|
|
'closed' => 'Đã đóng',
|
|
];
|
|
|
|
public const PRIORITY_LABELS = [
|
|
'low' => 'Thấp',
|
|
'medium' => 'Trung bình',
|
|
'high' => 'Cao',
|
|
];
|
|
|
|
public const ROOM_LABELS = [
|
|
'technical' => 'Kỹ thuật',
|
|
'sales' => 'Bán hàng',
|
|
];
|
|
|
|
protected $table = 'ticket';
|
|
|
|
protected $fillable = [
|
|
'uuid',
|
|
'ticket_num',
|
|
'subject',
|
|
'customer_id',
|
|
'service_uuid',
|
|
'description',
|
|
'status',
|
|
'room',
|
|
'data',
|
|
'gallery',
|
|
];
|
|
|
|
protected $casts = [
|
|
'gallery' => 'array',
|
|
];
|
|
|
|
public function priority(): ?string
|
|
{
|
|
$data = is_string($this->data) ? json_decode($this->data, true) : $this->data;
|
|
|
|
return is_array($data) ? ($data['priority'] ?? null) : null;
|
|
}
|
|
|
|
/**
|
|
* @return Collection<int, array{from: ?string, to: string, causer_type: ?string, causer_name: ?string, created_at: mixed}>
|
|
*/
|
|
public function statusHistory(): Collection
|
|
{
|
|
return ActivityLog::query()
|
|
->where('subject_type', self::class)
|
|
->where('subject_id', $this->id)
|
|
->whereIn('event', ['created', 'updated'])
|
|
->whereNotNull('new_values->status')
|
|
->latest('id')
|
|
->get(['old_values', 'new_values', 'causer_type', 'causer_name', 'created_at'])
|
|
->map(fn (ActivityLog $log) => [
|
|
'from' => $log->old_values['status'] ?? null,
|
|
'to' => $log->new_values['status'],
|
|
'causer_type' => $log->causer_type,
|
|
'causer_name' => $log->causer_name,
|
|
'created_at' => $log->created_at,
|
|
]);
|
|
}
|
|
|
|
public function roomLabel(): ?string
|
|
{
|
|
return $this->room ? (self::ROOM_LABELS[$this->room] ?? $this->room) : null;
|
|
}
|
|
|
|
public function customer()
|
|
{
|
|
return $this->belongsTo(\App\Models\Customer::class);
|
|
}
|
|
|
|
public function reply()
|
|
{
|
|
return $this->hasMany(\App\Models\TicketReply::class,'ticket_id','id');
|
|
}
|
|
}
|