WorkOrderRequest.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. namespace App\Http\Requests\WorkOrder;
  3. use App\Traits\RequestApiFormValidation;
  4. use Illuminate\Foundation\Http\FormRequest;
  5. use Illuminate\Support\Facades\Route;
  6. class WorkOrderRequest extends FormRequest
  7. {
  8. use RequestApiFormValidation;
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. *
  12. * @return bool
  13. */
  14. public function authorize()
  15. {
  16. return true;
  17. }
  18. /**
  19. * Get the validation rules that apply to the request.
  20. *
  21. * @return array
  22. */
  23. public function rules()
  24. {
  25. $routeName = Route::currentRouteName();
  26. switch ($routeName ){
  27. case 'workOrder.damagedApi':
  28. return $this->damagedApiRule();
  29. case 'worKOrder.workOrder.interceptApi':
  30. return $this->interceptApiRule();
  31. default:
  32. return [];
  33. }
  34. }
  35. public function messages(): array
  36. {
  37. $routeName = Route::currentRouteName();
  38. switch ($routeName ){
  39. case 'workOrder.damagedApi':
  40. return $this->damagedApiMessage();
  41. case 'worKOrder.workOrder.interceptApi':
  42. return $this->interceptApiMessage();
  43. default:
  44. return [];
  45. }
  46. }
  47. public function damagedApiRule(): array
  48. {
  49. return [
  50. 'order_no' => 'required|string',
  51. 'packageImages' => 'required|array',
  52. 'commodityImages' => 'required|array',
  53. 'dealImages' => 'required|array',
  54. ];
  55. }
  56. public function damagedApiMessage(): array
  57. {
  58. return [
  59. 'order_no.required' => '未指定订单',
  60. 'order_no.string' => '订单数据格式不正确',
  61. 'packageImages.required' => '未上传外包装图片',
  62. 'packageImages.array' => '外包装图片按数组格式上传',
  63. 'commodityImages.required' => '未上传内物图片',
  64. 'commodityImages.array' => '内物图片按数组格式上传',
  65. 'dealImages.required' => '未上传交易图片',
  66. 'dealImages.array' => '交易图片按数组格式上传',
  67. ];
  68. }
  69. public function interceptApiRule():array
  70. {
  71. return [
  72. 'orderNos' => 'required|array',
  73. 'remark' => 'string',
  74. ];
  75. }
  76. public function interceptApiMessage(): array
  77. {
  78. return [
  79. 'orderNos.required' => '参数异常',
  80. 'orderNos.array' => '参数异常',
  81. 'remark.string' => '参数异常',
  82. ];
  83. }
  84. }