Ken 1 settimana fa
parent
commit
5bb6b4b503
1 ha cambiato i file con 14 aggiunte e 3 eliminazioni
  1. 14 3
      app/Http/Controllers/admin/Wallet.php

+ 14 - 3
app/Http/Controllers/admin/Wallet.php

@@ -9,6 +9,7 @@ use App\Services\BalanceLogService;
 use App\Services\RechargeService;
 use App\Services\RechargeService;
 use App\Services\TopUpService;
 use App\Services\TopUpService;
 use Exception;
 use Exception;
+use Illuminate\Support\Facades\Cache;
 
 
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Validation\ValidationException;
 use Illuminate\Validation\ValidationException;
@@ -80,15 +81,25 @@ class Wallet extends Controller
             $remark = request()->input('remark');
             $remark = request()->input('remark');
 
 
 
 
-            $wallet = WalletModel::where('member_id', $memberId)
-                ->first();
+            $wallet = WalletModel::where('member_id', $memberId)->first();
             if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
             if (!$wallet) throw new Exception('用户不存在', HttpStatus::CUSTOM_ERROR);
-
             $available_balance = bcadd($wallet->available_balance, $amount, 10);
             $available_balance = bcadd($wallet->available_balance, $amount, 10);
             $changeType = ($amount > 0 ? "人工充值" : "人工扣款");
             $changeType = ($amount > 0 ? "人工充值" : "人工扣款");
             BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $available_balance, $changeType, null, $remark);
             BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $available_balance, $changeType, null, $remark);
             $wallet->available_balance = $available_balance;
             $wallet->available_balance = $available_balance;
             $wallet->save();
             $wallet->save();
+
+            $key = 'api_request_' . md5($memberId . json_encode([
+                        'amount' => $amount,
+                        'remark' => $remark,
+                        'change_type' => $changeType
+                    ]));
+            if (Cache::has($key)) {
+                return response()->json(['message' => '请求太频繁,请稍后再试。'], 429);
+            }
+            Cache::put($key, true, 3);
+
+
             DB::commit();
             DB::commit();
         } catch (ValidationException $e) {
         } catch (ValidationException $e) {
             DB::rollBack();
             DB::rollBack();