Files
portal-api/app/Http/Controllers/Api/Client/Service/ServiceRenewalHistoryController.php
baodev0andClaude Sonnet 5.5 b44a88bb52 feat(service): huỷ dịch vụ, SSL, đổi mật khẩu hosting, lịch sử thanh toán theo hình thức
- Lịch sử thanh toán hoá đơn trả thêm `method` (tự động gia hạn / số dư / admin / chuyển khoản / hoàn tiền), bỏ đuôi `(method)` khỏi ghi chú
- `DnsServer::panelUrl()` = https://<domain>/ dùng cho email cấp hosting và nút Plesk của khách
- Order item trả thêm `uuid`/`type` của dịch vụ để FE dẫn tới trang quản lý
- Yêu cầu huỷ dịch vụ, chứng chỉ SSL, lịch sử gia hạn, đổi mật khẩu hosting cho khách

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 16:40:24 +07:00

44 lines
1.7 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Client\Service;
use App\Http\Controllers\Controller;
use App\Models\ActivityLog;
use App\Models\Service;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ServiceRenewalHistoryController extends Controller
{
private const CAUSER_LABELS = [
'customer' => 'Bạn',
'admin' => 'Nhân viên hỗ trợ',
'system' => 'Tự động gia hạn',
];
public function __invoke(Request $request, string $uuid): JsonResponse
{
$service = Service::where('uuid', $uuid)->where('customer_id', $request->user()->id)->firstOrFail();
$items = ActivityLog::where('subject_type', Service::class)
->where('subject_id', $service->id)
->where('event', 'renewed')
->latest('id')
->limit(100)
->get(['causer_type', 'old_values', 'new_values', 'created_at'])
->map(fn (ActivityLog $log) => [
'renewed_at' => $log->created_at?->toISOString(),
'months' => (int) ($log->new_values['months'] ?? 0),
'amount' => (int) ($log->new_values['amount'] ?? 0),
'invoice_number' => $log->new_values['invoice_number'] ?? null,
'paid_by' => ($log->new_values['payment_method'] ?? null) === 'balance' ? 'Số dư tài khoản' : 'Thanh toán khác',
'old_expires_at' => $log->old_values['expires_at'] ?? null,
'new_expires_at' => $log->new_values['expires_at'] ?? null,
'by' => self::CAUSER_LABELS[$log->causer_type] ?? self::CAUSER_LABELS['system'],
])
->values();
return response()->json(['error' => false, 'data' => $items]);
}
}