|
|
@@ -11,6 +11,7 @@ use App\Services\WalletService;
|
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Http\Request;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
+use Illuminate\Support\Facades\Log;
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
use Exception;
|
|
|
use App\Models\Rebate as RebateModel;
|
|
|
@@ -54,6 +55,7 @@ class Rebate extends Controller
|
|
|
}
|
|
|
RebateService::BibiReturn($rebate, $rebate->effective_betting_amount);
|
|
|
DB::commit();
|
|
|
+ $this->logGrantNotice((int) $rebate->id);
|
|
|
} catch (ValidationException $e) {
|
|
|
DB::rollBack();
|
|
|
return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
|
|
|
@@ -63,4 +65,26 @@ class Rebate extends Controller
|
|
|
}
|
|
|
return $this->success();
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ private function logGrantNotice(int $id): void
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $reward = DB::table('rebates')->where('id', $id)->first(['id', 'member_id', 'date', 'amount', 'status', 'grant_time']);
|
|
|
+ $credits = DB::table('balance_logs')->where('change_type', '笔笔返')->where('related_id', $id)
|
|
|
+ ->where('member_id', $reward->member_id)->get(['id', 'amount']);
|
|
|
+ $requests = $credits->map(fn ($credit) => 'reward-payout:balance-log:' . $credit->id)->all();
|
|
|
+ $messages = DB::table('site_messages')->where('sender_id', 0)->whereIn('request_id', $requests)->pluck('id', 'request_id');
|
|
|
+ Log::info('manual_rebate_notice_diagnostic', [
|
|
|
+ 'reward' => (array) $reward,
|
|
|
+ 'credits' => $credits->map(fn ($credit) => ['ledger_id' => $credit->id, 'amount' => $credit->amount,
|
|
|
+ 'message_id' => $messages['reward-payout:balance-log:' . $credit->id] ?? null])->all(),
|
|
|
+ 'message_count' => $messages->count(),
|
|
|
+ 'table_prefix' => DB::connection()->getTablePrefix(),
|
|
|
+ ]);
|
|
|
+ } catch (\Throwable $e) {
|
|
|
+ // Diagnostics run after commit and must never turn a completed payout into an error response.
|
|
|
+ try { Log::error('manual_rebate_notice_diagnostic_failed', ['reward_id' => $id, 'exception_class' => get_class($e)]); }
|
|
|
+ catch (\Throwable $ignored) {}
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|