feat: add idempotency support for settlement adjustments and payments, fix rebate handling
- Added idempotency_key parameter to settlement bill adjustment and payment endpoints to prevent duplicate operations - Fixed player rebate profile updates to preserve existing values when only one field is modified - Moved wallet player validation earlier in AdminPlayerStoreController to prevent unnecessary processing - Enhanced extra rebate calculation to include 'in_bill' and 'settled' statuses in AgentP
This commit is contained in:
@@ -22,11 +22,34 @@ final class SettlementPaymentService
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array{method?: string|null, proof?: string|null, remark?: string|null} $meta
|
||||
* @param array{method?: string|null, proof?: string|null, remark?: string|null, idempotency_key?: string|null} $meta
|
||||
*/
|
||||
public function recordPayment(int $billId, int $amount, int $adminUserId, array $meta = []): void
|
||||
{
|
||||
DB::transaction(function () use ($billId, $amount, $adminUserId, $meta): void {
|
||||
$idempotencyKey = $meta['idempotency_key'] ?? null;
|
||||
|
||||
if ($idempotencyKey !== null && $idempotencyKey !== '') {
|
||||
$existing = DB::table('payment_records')
|
||||
->where('settlement_bill_id', $billId)
|
||||
->where('idempotency_key', $idempotencyKey)
|
||||
->first();
|
||||
if ($existing !== null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
DB::transaction(function () use ($billId, $amount, $adminUserId, $meta, $idempotencyKey): void {
|
||||
if ($idempotencyKey !== null && $idempotencyKey !== '') {
|
||||
$existing = DB::table('payment_records')
|
||||
->where('settlement_bill_id', $billId)
|
||||
->where('idempotency_key', $idempotencyKey)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if ($existing !== null) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$bill = DB::table('settlement_bills')->where('id', $billId)->lockForUpdate()->first();
|
||||
if ($bill === null) {
|
||||
throw new \InvalidArgumentException('bill_not_found');
|
||||
@@ -63,6 +86,7 @@ final class SettlementPaymentService
|
||||
'method' => $meta['method'] ?? null,
|
||||
'proof' => $meta['proof'] ?? null,
|
||||
'remark' => $meta['remark'] ?? null,
|
||||
'idempotency_key' => $idempotencyKey,
|
||||
'status' => 'confirmed',
|
||||
'created_by' => $adminUserId,
|
||||
'confirmed_by' => $adminUserId,
|
||||
|
||||
Reference in New Issue
Block a user