IndexAdminCreditLedgerRequest.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace App\Http\Requests\V3;
  3. use App\Models\CreditLedgerEntry;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Validation\Rule;
  6. /**
  7. * `GET /v3/admin/credit-ledger` 的入参:积分流水。按账号查时 account_type 与 account_id 必须一起给
  8. * (设备 id 由客户端填,可能与某个用户 uid 相同,只按 id 查会把两种账号混在一起)。
  9. */
  10. class IndexAdminCreditLedgerRequest extends FormRequest
  11. {
  12. public function authorize(): bool
  13. {
  14. return true;
  15. }
  16. /**
  17. * @return array<string, array<int, mixed>>
  18. */
  19. public function rules(): array
  20. {
  21. return [
  22. 'filter.account_type' => ['required_with:filter.account_id', 'in:user,guest'],
  23. 'filter.account_id' => ['sometimes', 'uuid'],
  24. 'filter.kind' => ['sometimes', Rule::in(CreditLedgerEntry::KINDS)],
  25. 'filter.bucket' => ['sometimes', Rule::in(CreditLedgerEntry::BUCKETS)],
  26. 'filter.source' => ['sometimes', 'in:reading,editing,agent_run,admin'],
  27. 'filter.from' => ['sometimes', 'date_format:Y-m-d'],
  28. 'filter.to' => ['sometimes', 'date_format:Y-m-d', 'after_or_equal:filter.from'],
  29. 'page' => ['integer', 'min:1'],
  30. 'per_page' => ['integer', 'min:1', 'max:100'],
  31. ];
  32. }
  33. }