Files
portal-api/app/Http/Controllers/Api/Admin/Customer/Concerns/ManagesCustomerBilling.php
T
baodev0andClaude Opus 5.5 94614d9cb3 feat: khởi tạo/huỷ domain Plesk qua job, gửi mail hoá đơn qua queue, đính kèm triển khai
- ProvisionDnsDomainJob/SuspendDnsDomainJob: tạo domain admin lên Plesk, huỷ = suspend (is_created=3)
- Khách xem zone DNS được gán ở /dich-vu/domain, quản lý bản ghi A/AAAA/CNAME/TXT/MX/SRV
- send-mail hoá đơn đẩy SendInvoiceMailJob, preview + sửa nội dung, ghi mail.order_id
- invoice_attachments.type (payment_proof/deployment)
- CacheService xoá theo SCAN pattern, Redis không persistent mặc định
- Backfill transactions.public_code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 09:56:18 +07:00

98 lines
3.6 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\Customer\Concerns;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
trait ManagesCustomerBilling
{
public function getInvoices(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getInvoices($uuid)]);
}
public function updateInvoice(string $uuid, int $invoiceId, Request $request): JsonResponse
{
$data = $request->validate([
'invoice_number' => 'nullable|string|max:50',
'status' => 'nullable|integer|in:1,2,3,4,5',
'payment_method' => 'nullable|in:transfer,balance',
'date' => 'nullable|date',
'due_date' => 'nullable|date',
'date_paid' => 'nullable|date',
'note' => 'nullable|string',
'sub_total' => 'nullable|integer|min:0',
'tax' => 'nullable|integer|min:0',
'total' => 'nullable|integer|min:0',
]);
$invoice = $this->billingService->updateInvoice($uuid, $invoiceId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật hóa đơn', 'data' => $invoice]);
}
public function getTransactions(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getTransactions($uuid)]);
}
public function updateTransaction(string $uuid, int $transactionId, Request $request): JsonResponse
{
$data = $request->validate([
'trans' => 'nullable|string|max:255',
'note' => 'nullable|string',
'type' => 'nullable|string|max:50',
'amount' => 'nullable|integer',
]);
$transaction = $this->billingService->updateTransaction($uuid, $transactionId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật giao dịch', 'data' => $transaction]);
}
public function createTransaction(string $uuid, Request $request): JsonResponse
{
$data = $request->validate([
'trans' => 'nullable|string|max:255',
'note' => 'nullable|string',
'amount' => 'required|integer|min:0',
'status' => 'nullable|integer|in:0,1,2',
]);
$transaction = $this->billingService->createTransaction($uuid, $data, $request->user()?->id);
return response()->json(['error' => false, 'message' => 'Đã thêm giao dịch', 'data' => $transaction], 201);
}
public function deleteTransaction(string $uuid, int $transactionId): JsonResponse
{
$this->billingService->deleteTransaction($uuid, $transactionId);
return response()->json(['error' => false, 'message' => 'Đã xoá giao dịch']);
}
public function getOrders(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getOrders($uuid)]);
}
public function updateOrder(string $uuid, int $orderId, Request $request): JsonResponse
{
$data = $request->validate([
'order_num' => 'nullable|string|max:255',
'status' => 'nullable|integer|in:0,1,2,3',
'payment_method' => 'nullable|in:transfer,balance',
'date' => 'nullable|date',
'sub_total' => 'nullable|integer|min:0',
'discount_amount' => 'nullable|integer|min:0',
'total' => 'nullable|integer|min:0',
'note' => 'nullable|string|max:5000',
]);
$order = $this->billingService->updateOrder($uuid, $orderId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật đơn hàng', 'data' => $order]);
}
}