改进 响应
This commit is contained in:
parent
ae8fc8be25
commit
8a9044bb60
@ -18,9 +18,9 @@ public function moduleResponse($response, int $status = 200): JsonResponse
|
|||||||
200 => $this->success($response),
|
200 => $this->success($response),
|
||||||
201 => $this->created($response),
|
201 => $this->created($response),
|
||||||
204 => $this->noContent(),
|
204 => $this->noContent(),
|
||||||
400 => $this->badRequest(),
|
400 => $this->badRequest($response),
|
||||||
401 => $this->serviceUnavailable(),
|
401 => $this->serviceUnavailable(),
|
||||||
403 => $this->forbidden(),
|
403 => $this->forbidden($response),
|
||||||
404 => $this->notFound($response),
|
404 => $this->notFound($response),
|
||||||
405 => $this->methodNotAllowed(),
|
405 => $this->methodNotAllowed(),
|
||||||
429 => $this->tooManyRequests(),
|
429 => $this->tooManyRequests(),
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
use Illuminate\Http\JsonResponse;
|
use Illuminate\Http\JsonResponse;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Http\Response;
|
use Illuminate\Http\Response;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
|
|
||||||
class ModuleController extends Controller
|
class ModuleController extends Controller
|
||||||
@ -23,15 +24,6 @@ public function call(Request $request, Module $module)
|
|||||||
|
|
||||||
$method = Str::lower($request->method());
|
$method = Str::lower($request->method());
|
||||||
|
|
||||||
// 如果 method 为 post, 检查用户余额
|
|
||||||
if ($method == 'post') {
|
|
||||||
$user = auth()->user();
|
|
||||||
|
|
||||||
if ($user->balance < 1) {
|
|
||||||
return $this->error('账户余额不足,请保证账户余额至少有 1 元。');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$response = $module->request($method, $path, $request->all());
|
$response = $module->request($method, $path, $request->all());
|
||||||
|
|
||||||
if ($response['json'] === null && $response['body'] !== null) {
|
if ($response['json'] === null && $response['body'] !== null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user