PcIssue.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Validation\ValidationException;
  6. use Exception;
  7. use App\Models\PcIssue as PcIssueModel;
  8. class PcIssue extends Controller
  9. {
  10. /**
  11. * @api {get} /admin/pcIssue 极速28
  12. * @apiGroup 极速28
  13. *
  14. * @apiUse result
  15. * @apiUse header
  16. * @apiVersion 1.0.0
  17. *
  18. * @apiParam {int} [page=1]
  19. * @apiParam {int} [limit=10]
  20. * @apiParam {string} [issue_no] 期号
  21. */
  22. public function index()
  23. {
  24. try {
  25. $search = request()->validate([
  26. 'page' => ['nullable', 'integer', 'min:1'],
  27. 'limit' => ['nullable', 'integer', 'min:1'],
  28. 'issue_no' => ['nullable', 'string'],
  29. ]);
  30. $page = request()->input('page', 1);
  31. $limit = request()->input('limit', 15);
  32. $result['total'] = PcIssueModel::where(PcIssueModel::getWhere($search))->count();
  33. $result['data'] = PcIssueModel::where(PcIssueModel::getWhere($search))
  34. ->orderByDesc('id')->forPage($page, $limit)->get();
  35. } catch (ValidationException $e) {
  36. return $this->error(HttpStatus::CUSTOM_ERROR, $e->validator->errors()->first());
  37. } catch (Exception $e) {
  38. return $this->error(intval($e->getCode()));
  39. }
  40. return $this->success($result);
  41. }
  42. }