|
|
@@ -9,6 +9,7 @@ use App\Services\BalanceLogService;
|
|
|
use App\Services\RechargeService;
|
|
|
use App\Services\TopUpService;
|
|
|
use Exception;
|
|
|
+use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Validation\ValidationException;
|
|
|
@@ -80,15 +81,25 @@ class Wallet extends Controller
|
|
|
$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);
|
|
|
-
|
|
|
$available_balance = bcadd($wallet->available_balance, $amount, 10);
|
|
|
$changeType = ($amount > 0 ? "人工充值" : "人工扣款");
|
|
|
BalanceLogService::addLog($memberId, $amount, $wallet->available_balance, $available_balance, $changeType, null, $remark);
|
|
|
$wallet->available_balance = $available_balance;
|
|
|
$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();
|
|
|
} catch (ValidationException $e) {
|
|
|
DB::rollBack();
|