feat: nạp tiền thủ công mã 30 phút, gia hạn trừ số dư, đồng bộ domain từ Plesk
- Nạp tiền: mã thanh toán sống 30 phút (ManualDepositDraft), khôi phục/huỷ mã, lệnh dọn mã hết hạn; total_pending chỉ tính giao dịch đã nộp chứng từ, admin duyệt/từ chối/xoá giao dịch - Gia hạn dịch vụ: phát hành invoice gia hạn trên order gốc và trừ số dư ngay - Đồng bộ domain từ Plesk theo server, ServiceOrderRecorder tạo order/invoice cho dịch vụ admin dựng - Danh sách dịch vụ trả field theo loại (service_plan, dns_records_count), đếm dịch vụ theo loại Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10af41c5cf
commit
c5115b52dd
@@ -137,8 +137,7 @@ class AdminTransactionController extends Controller
|
||||
$creditEarned = Customer::creditFor($received);
|
||||
$customer->total += $received;
|
||||
$customer->credit += $creditEarned;
|
||||
// Trừ pending theo số khách khai — đó chính là số đã được giữ chỗ lúc tạo yêu cầu.
|
||||
$customer->total_pending = max(0, $customer->total_pending - $declared);
|
||||
$this->releasePending($customer, $transaction, $declared);
|
||||
$customer->save();
|
||||
|
||||
Log::create([
|
||||
@@ -158,7 +157,7 @@ class AdminTransactionController extends Controller
|
||||
'type' => 'deposit_success',
|
||||
'title' => 'Nạp tiền thành công',
|
||||
'body' => 'Giao dịch ' . $transaction->public_code . ' đã được duyệt.',
|
||||
'link' => '/lich-su-giao-dich/' . $transaction->id,
|
||||
'link' => '/lich-su-giao-dich/' . $transaction->uuid,
|
||||
'data' => [
|
||||
'transaction_uuid' => $transaction->uuid,
|
||||
'amount' => $received,
|
||||
@@ -231,7 +230,7 @@ class AdminTransactionController extends Controller
|
||||
$transaction->update(['status' => TransactionStatus::FAILED->value]);
|
||||
|
||||
$customer = Customer::where('id', $transaction->customer_id)->lockForUpdate()->first();
|
||||
$customer->total_pending = max(0, $customer->total_pending - $transaction->amount);
|
||||
$this->releasePending($customer, $transaction, (int) $transaction->amount);
|
||||
$customer->save();
|
||||
|
||||
Log::create([
|
||||
@@ -288,6 +287,57 @@ class AdminTransactionController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function destroy(string $uuid): JsonResponse
|
||||
{
|
||||
$transaction = DB::transaction(function () use ($uuid) {
|
||||
$transaction = Transaction::where('uuid', $uuid)
|
||||
->where('type', 'manual')
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
|
||||
if (! $transaction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ((int) $transaction->status === TransactionStatus::PENDING->value) {
|
||||
$customer = Customer::where('id', $transaction->customer_id)->lockForUpdate()->first();
|
||||
if ($customer) {
|
||||
$this->releasePending($customer, $transaction, (int) $transaction->amount);
|
||||
$customer->save();
|
||||
}
|
||||
}
|
||||
|
||||
$transaction->delete();
|
||||
|
||||
Log::create([
|
||||
'agent' => 'admin',
|
||||
'client_ip' => request()->ip(),
|
||||
'description' => sprintf(
|
||||
'Admin xoá giao dịch nạp tiền thủ công %s: %s VNĐ (%s)',
|
||||
$transaction->public_code,
|
||||
number_format($transaction->amount),
|
||||
TransactionStatus::from((int) $transaction->status)->label(),
|
||||
),
|
||||
'customer_id' => $transaction->customer_id,
|
||||
]);
|
||||
|
||||
return $transaction;
|
||||
});
|
||||
|
||||
if (! $transaction) {
|
||||
return response()->json(['error' => true, 'message' => 'Giao dịch không tồn tại'], 404);
|
||||
}
|
||||
|
||||
return response()->json(['error' => false, 'message' => 'Đã xoá giao dịch']);
|
||||
}
|
||||
|
||||
private function releasePending(Customer $customer, Transaction $transaction, int $amount): void
|
||||
{
|
||||
if ($transaction->proof_image) {
|
||||
$customer->total_pending = max(0, $customer->total_pending - $amount);
|
||||
}
|
||||
}
|
||||
|
||||
public function proofImage(Transaction $transaction, int $index = 0)
|
||||
{
|
||||
abort_unless($transaction->proof_image, 404);
|
||||
|
||||
Reference in New Issue
Block a user