refactor:拆分 API 路由与请求校验,统一 final 类和代码风格
This commit is contained in:
44
app/Http/Requests/Admin/AdminLoginRequest.php
Normal file
44
app/Http/Requests/Admin/AdminLoginRequest.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员登录请求。
|
||||
*
|
||||
* @see LoginController
|
||||
*/
|
||||
final class AdminLoginRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'account' => ['required', 'string', 'min:2', 'max:64', 'regex:/^[a-zA-Z0-9._-]+$/u'],
|
||||
'password' => ['required', 'string', 'max:256'],
|
||||
'captcha_key' => ['required', 'string', 'uuid'],
|
||||
'captcha_code' => ['required', 'string', 'max:32'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function attributes(): array
|
||||
{
|
||||
return [
|
||||
'account' => 'account',
|
||||
'password' => 'password',
|
||||
'captcha_key' => 'captcha_key',
|
||||
'captcha_code' => 'captcha_code',
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Admin/AdminPlayerTicketItemsRequest.php
Normal file
30
app/Http/Requests/Admin/AdminPlayerTicketItemsRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员查看玩家注单列表请求。
|
||||
*
|
||||
* @see AdminPlayerTicketItemsIndexController
|
||||
*/
|
||||
final class AdminPlayerTicketItemsRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'page' => ['sometimes', 'integer', 'min:1'],
|
||||
'per_page' => ['sometimes', 'integer', 'min:1', 'max:50'],
|
||||
'draw_no' => ['sometimes', 'nullable', 'string', 'max:32'],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Requests/Admin/AdminUserPermissionSyncRequest.php
Normal file
29
app/Http/Requests/Admin/AdminUserPermissionSyncRequest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员用户权限同步请求。
|
||||
*
|
||||
* @see AdminUserPermissionSyncController
|
||||
*/
|
||||
final class AdminUserPermissionSyncRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'permissions' => ['required', 'array'],
|
||||
'permissions.*' => ['string', 'max:128'],
|
||||
];
|
||||
}
|
||||
}
|
||||
29
app/Http/Requests/Admin/AdminUserRoleSyncRequest.php
Normal file
29
app/Http/Requests/Admin/AdminUserRoleSyncRequest.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员用户角色同步请求。
|
||||
*
|
||||
* @see AdminUserRoleSyncController
|
||||
*/
|
||||
final class AdminUserRoleSyncRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'role_slugs' => ['required', 'array', 'min:1'],
|
||||
'role_slugs.*' => ['string', 'max:64', 'distinct', 'exists:admin_roles,slug'],
|
||||
];
|
||||
}
|
||||
}
|
||||
59
app/Http/Requests/Admin/AdminUserStoreRequest.php
Normal file
59
app/Http/Requests/Admin/AdminUserStoreRequest.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员用户创建请求。
|
||||
*
|
||||
* @see AdminUserStoreController
|
||||
*/
|
||||
final class AdminUserStoreRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare the data for validation.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$username = $this->input('username');
|
||||
if (is_string($username)) {
|
||||
$this->merge([
|
||||
'username' => Str::lower(trim($username)),
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->input('email') === '') {
|
||||
$this->merge([
|
||||
'email' => null,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'username' => ['required', 'string', 'min:2', 'max:64', 'regex:/^[a-zA-Z0-9._-]+$/u', 'unique:admin_users,username'],
|
||||
'nickname' => ['required', 'string', 'max:128'],
|
||||
'email' => ['nullable', 'string', 'email', 'max:255'],
|
||||
'password' => ['required', 'string', 'min:8', 'max:256'],
|
||||
'status' => ['sometimes', 'integer', 'in:0,1'],
|
||||
'role_slugs' => ['required', 'array', 'min:1'],
|
||||
'role_slugs.*' => ['string', 'max:64', 'distinct', 'exists:admin_roles,slug'],
|
||||
];
|
||||
}
|
||||
}
|
||||
41
app/Http/Requests/Admin/AdminUserUpdateRequest.php
Normal file
41
app/Http/Requests/Admin/AdminUserUpdateRequest.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 管理员用户更新请求。
|
||||
*
|
||||
* @see AdminUserUpdateController
|
||||
*/
|
||||
final class AdminUserUpdateRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->input('email') === '') {
|
||||
$this->merge(['email' => null]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
$adminUser = $this->route('admin_user');
|
||||
|
||||
return [
|
||||
'nickname' => ['sometimes', 'string', 'max:128'],
|
||||
'email' => ['sometimes', 'nullable', 'string', 'email', 'max:255', Rule::unique('admin_users', 'email')->ignore($adminUser?->id)],
|
||||
'password' => ['sometimes', 'nullable', 'string', 'min:8', 'max:256'],
|
||||
'status' => ['sometimes', 'integer', Rule::in([0, 1])],
|
||||
];
|
||||
}
|
||||
}
|
||||
30
app/Http/Requests/Admin/ReconcileJobStoreRequest.php
Normal file
30
app/Http/Requests/Admin/ReconcileJobStoreRequest.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 对账任务创建请求。
|
||||
*
|
||||
* @see ReconcileJobStoreController
|
||||
*/
|
||||
final class ReconcileJobStoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'date_from' => ['required', 'date_format:Y-m-d'],
|
||||
'date_to' => ['required', 'date_format:Y-m-d', 'after_or_equal:date_from'],
|
||||
'player_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
];
|
||||
}
|
||||
}
|
||||
31
app/Http/Requests/Admin/ReportJobStoreRequest.php
Normal file
31
app/Http/Requests/Admin/ReportJobStoreRequest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 报表任务创建请求。
|
||||
*
|
||||
* @see ReportJobStoreController
|
||||
*/
|
||||
final class ReportJobStoreRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'report_type' => ['required', 'string', 'max:64'],
|
||||
'parameters' => ['sometimes', 'array'],
|
||||
'parameters.date_from' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
'parameters.date_to' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
];
|
||||
}
|
||||
}
|
||||
37
app/Http/Requests/Admin/TransferOrderListRequest.php
Normal file
37
app/Http/Requests/Admin/TransferOrderListRequest.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 转账单列表查询请求。
|
||||
*
|
||||
* @see TransferOrderListController
|
||||
*/
|
||||
final class TransferOrderListRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'page' => ['sometimes', 'integer', 'min:1'],
|
||||
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||
'size' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||
'player_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
'player_account' => ['sometimes', 'nullable', 'string', 'max:128'],
|
||||
'transfer_no' => ['sometimes', 'nullable', 'string', 'max:96'],
|
||||
'external_ref_no' => ['sometimes', 'nullable', 'string', 'max:96'],
|
||||
'created_from' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
'created_to' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
'status' => ['sometimes', 'nullable', 'string', 'max:256'],
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Requests/Admin/WalletTransactionListRequest.php
Normal file
38
app/Http/Requests/Admin/WalletTransactionListRequest.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Admin;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
/**
|
||||
* 钱包流水列表查询请求。
|
||||
*
|
||||
* @see WalletTransactionListController
|
||||
*/
|
||||
final class WalletTransactionListRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, array<int, mixed>>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'page' => ['sometimes', 'integer', 'min:1'],
|
||||
'per_page' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||
'size' => ['sometimes', 'integer', 'min:1', 'max:100'],
|
||||
'player_id' => ['sometimes', 'nullable', 'integer', 'min:1'],
|
||||
'player_account' => ['sometimes', 'nullable', 'string', 'max:128'],
|
||||
'txn_no' => ['sometimes', 'nullable', 'string', 'max:96'],
|
||||
'external_ref_no' => ['sometimes', 'nullable', 'string', 'max:96'],
|
||||
'created_from' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
'created_to' => ['sometimes', 'nullable', 'date_format:Y-m-d'],
|
||||
'biz_type' => ['sometimes', 'nullable', 'string', 'max:64'],
|
||||
'status' => ['sometimes', 'nullable', 'string', 'max:128'],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests\Ticket;
|
||||
|
||||
class TicketPlaceRequest extends TicketPreviewRequest
|
||||
final class TicketPlaceRequest extends TicketPreviewRequest
|
||||
{
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace App\Http\Requests\Ticket;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TicketPreviewRequest extends FormRequest
|
||||
final class TicketPreviewRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
|
||||
@@ -7,7 +7,7 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
/**
|
||||
* 转入 / 转出共用请求体:最小货币单位金额、幂等键、可选币种。
|
||||
*/
|
||||
class WalletTransferRequest extends FormRequest
|
||||
final class WalletTransferRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user