Issue.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Http\Controllers\admin;
  3. use App\Constants\HttpStatus;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\IssueService;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Validation\ValidationException;
  8. use Exception;
  9. class Issue extends Controller
  10. {
  11. /**
  12. * @description: 分页数据
  13. * @return {*}
  14. */
  15. function index()
  16. {
  17. try {
  18. request()->validate([
  19. 'issue_no' => ['nullable', 'string'],
  20. 'id' => ['nullable', 'string'],
  21. 'status' => ['nullable', 'string'],
  22. ]);
  23. $search = request()->all();
  24. $result = IssueService::paginate($search);
  25. } catch (ValidationException $e) {
  26. return $this->error(HttpStatus::VALIDATION_FAILED, $e->validator->errors()->first());
  27. } catch (Exception $e) {
  28. return $this->error(intval($e->getCode()));
  29. }
  30. return $this->success($result);
  31. }
  32. /**
  33. * @description: 修改|新增
  34. * @return {*}
  35. */
  36. public function store()
  37. {
  38. // try {
  39. $params = request()->all();
  40. $validator = [
  41. 'issue_no' => 'required|string|max:50|alpha_dash|unique:issues,issue_no',
  42. 'winning_numbers' => 'nullable|string|max:100',
  43. 'status' => 'nullable|string',
  44. ];
  45. request()->validate($validator);
  46. $ret = IssueService::submit($params);
  47. if ($ret['code'] == IssueService::NOT) {
  48. return $this->error($ret['code'], $ret['msg']);
  49. }
  50. // } catch (ValidationException $e) {
  51. // return $this->error(HttpStatus::VALIDATION_FAILED, '', $e->errors());
  52. // } catch (Exception $e) {
  53. // return $this->error(intval($e->getCode()));
  54. // }
  55. return $this->success([], $ret['msg']);
  56. }
  57. }