You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.4 KiB

7 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class UserWithdrawRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'user_id' => 'required|integer',
  9. 'add_time' => 'required|integer',
  10. 'money' => ['required','regex:/^\d{0,10}(\.\d{0,2})?$/'],
  11. 'name' => 'max:30',
  12. 'status' => 'integer|between:0,5',
  13. 'note' => 'max:250',
  14. 're_note' => 'max:250',
  15. 'bank_name' => 'max:30',
  16. 'bank_place' => 'max:150',
  17. 'account' => 'required|max:30',
  18. 'method' => 'required|max:20',
  19. 'delete_time' => 'integer',
  20. ];
  21. //总的自定义错误信息
  22. protected $messages = [
  23. 'id.required' => 'ID必填',
  24. 'id.integer' => 'ID必须为数字',
  25. 'user_id.required' => '用户ID必填',
  26. 'user_id.integer' => '用户ID必须为数字',
  27. 'add_time.required' => '添加时间必填',
  28. 'add_time.integer' => '添加时间格式不正确',
  29. 'money.required' => '提现金额必填',
  30. 'money.regex' => '提现金额格式不正确,只能带2位小数的数字',
  31. 'name.max' => '姓名不能超过30个字符',
  32. 'status.integer' => '状态必须是数字',
  33. 'status.between' => '状态 0未处理,1处理中,2成功,3取消,4拒绝',
  34. 'note.max' => '用户备注不能超过250个字符',
  35. 're_note.max' => '回复信息不能超过250个字符',
  36. 'bank_name.max' => '银行名称不能超过30个字符',
  37. 'bank_place.max' => '开户行不能超过150个字符',
  38. 'account.required' => '提现账号必填',
  39. 'account.max' => '支付宝账号或者银行卡号不能超过30个字符',
  40. 'method.required' => '提现方式必填',
  41. 'method.max' => '提现方式不能超过20个字符',
  42. 'delete_time.integer' => '删除时间格式不正确',
  43. ];
  44. //场景验证规则
  45. protected $scene = [
  46. 'add' => ['user_id', 'money', 'name', 'note', 'bank_name', 'bank_place', 'account', 'method'],
  47. 'edit' => ['user_id', 'money', 'name', 'note', 'bank_name', 'bank_place', 'account', 'method'],
  48. 'del' => ['id'],
  49. ];
  50. /**
  51. * Determine if the user is authorized to make this request.
  52. *
  53. * @return bool
  54. */
  55. public function authorize()
  56. {
  57. return true; //修改为true
  58. }
  59. /**
  60. * Get the validation rules that apply to the request.
  61. *
  62. * @return array
  63. */
  64. public function rules()
  65. {
  66. return $this->rules;
  67. }
  68. /**
  69. * 获取被定义验证规则的错误消息.
  70. *
  71. * @return array
  72. */
  73. public function messages()
  74. {
  75. return $this->messages;
  76. }
  77. //获取场景验证规则
  78. public function getSceneRules($name, $fields = null)
  79. {
  80. $res = array();
  81. if(!isset($this->scene[$name]))
  82. {
  83. return false;
  84. }
  85. $scene = $this->scene[$name];
  86. if($fields != null && is_array($fields))
  87. {
  88. $scene = $fields;
  89. }
  90. foreach($scene as $k=>$v)
  91. {
  92. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  93. }
  94. return $res;
  95. }
  96. //获取场景验证规则自定义错误信息
  97. public function getSceneRulesMessages()
  98. {
  99. return $this->messages;
  100. }
  101. }