Просмотр исходного кода

返现明细登记失败不再回滚充值,改记 share 日志

推荐人返现明细登记返回 skipped 或异常时,之前会抛异常导致被邀请人整笔充值回滚。
现改为记录到新增的 share 日志通道(storage/logs/share/commission.log),本金和返现照常入账,漏登明细可用 share:backfill-commissions 补记。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
doge 1 день назад
Родитель
Сommit
45c07f4735
2 измененных файлов с 21 добавлено и 7 удалено
  1. 14 7
      app/Services/BalanceLogService.php
  2. 7 0
      config/logging.php

+ 14 - 7
app/Services/BalanceLogService.php

@@ -12,6 +12,7 @@ use App\Models\Level;
 use App\Models\RechargeChannelGroup;
 use App\Models\UserLogin;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Log;
 
 // 余额额变动记录
 class BalanceLogService extends BaseService
@@ -220,13 +221,19 @@ class BalanceLogService extends BaseService
                                 $wallet->save();
                                 $rebate = BalanceLogService::addLog($agent_member_id, $add_amount, $before, $wallet->available_balance,
                                     '充值返现', $related_id, '被邀请人:'.$memberId."充值金额为:{$remark_amount}");
-                                $record = (new ShareCommissionRecorder())->record($rebate, [
-                                    'invitee_user_id' => $user->id,
-                                    'base_amount' => $amount,
-                                    'rate' => $rate,
-                                ]);
-                                if ($record['status'] === 'skipped') {
-                                    throw new \RuntimeException('返现佣金明细登记失败:' . $record['reason']);
+                                // The detail record is bookkeeping only: a failure must never roll back
+                                // the invitee's deposit or the promoter's paid rebate. Backfill repairs it later.
+                                try {
+                                    $record = (new ShareCommissionRecorder())->record($rebate, [
+                                        'invitee_user_id' => $user->id,
+                                        'base_amount' => $amount,
+                                        'rate' => $rate,
+                                    ]);
+                                    if ($record['status'] === 'skipped') {
+                                        Log::channel('share')->error('返现佣金明细登记失败', ['balance_log_id' => $rebate->id, 'reason' => $record['reason']]);
+                                    }
+                                } catch (\Throwable $e) {
+                                    Log::channel('share')->error('返现佣金明细登记异常', ['balance_log_id' => $rebate->id, 'exception' => $e]);
                                 }
                             });
                         }

+ 7 - 0
config/logging.php

@@ -82,6 +82,13 @@ return [
             'level' => 'error',
             'days' => 90,
         ],
+        'share' => [
+            'driver' => 'daily',
+            'path' => storage_path('logs/share/commission.log'),
+            'level' => env('LOG_LEVEL', 'debug'),
+            'days' => 90,
+            'permission' => 0664,
+        ],
 
         'slack' => [
             'driver' => 'slack',