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.

109 lines
3.2 KiB

6 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class UserRechargeRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'user_id' => 'required|integer',
  9. 'money' => ['required','regex:/^\d{0,10}(\.\d{0,2})?$/'],
  10. 'pay_time' => 'required|integer',
  11. 'pay_type' => 'integer|between:0,3',
  12. 'pay_money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'],
  13. 'trade_no' => 'max:30',
  14. 'status' => 'integer|between:0,3',
  15. 'created_at' => 'required|integer',
  16. 'updated_at' => 'integer',
  17. 'recharge_sn' => 'required|max:60',
  18. ];
  19. //总的自定义错误信息
  20. protected $messages = [
  21. 'id.required' => 'ID必填',
  22. 'id.integer' => 'ID必须为数字',
  23. 'user_id.required' => '用户ID必填',
  24. 'user_id.integer' => '用户ID必须为数字',
  25. 'money.required' => '充值金额必填',
  26. 'money.regex' => '充值金额格式不正确,只能带2位小数的数字',
  27. 'pay_time.required' => '充值时间必填',
  28. 'pay_time.integer' => '充值时间格式不正确',
  29. 'pay_type.integer' => '充值类型必须为数字',
  30. 'pay_type.between' => '充值类型:1微信,2支付宝',
  31. 'pay_money.regex' => '实付金额格式不正确,只能带2位小数的数字',
  32. 'trade_no.max' => '支付流水号不能超过30个字符',
  33. 'status.integer' => '充值状态必须为数字',
  34. 'status.between' => '充值状态:0未处理,1已完成,2失败',
  35. 'created_at.required' => '添加时间必填',
  36. 'created_at.integer' => '添加时间格式不正确',
  37. 'updated_at.integer' => '更新时间格式不正确',
  38. 'recharge_sn.required' => '支付订单号必填',
  39. 'recharge_sn.max' => '支付订单号不能超过60个字符',
  40. ];
  41. //场景验证规则
  42. protected $scene = [
  43. 'add' => ['user_id', 'money', 'recharge_sn', 'des'],
  44. 'edit' => ['user_id', 'money', 'recharge_sn', 'des'],
  45. 'del' => ['id'],
  46. ];
  47. /**
  48. * Determine if the user is authorized to make this request.
  49. *
  50. * @return bool
  51. */
  52. public function authorize()
  53. {
  54. return true; //修改为true
  55. }
  56. /**
  57. * Get the validation rules that apply to the request.
  58. *
  59. * @return array
  60. */
  61. public function rules()
  62. {
  63. return $this->rules;
  64. }
  65. /**
  66. * 获取被定义验证规则的错误消息.
  67. *
  68. * @return array
  69. */
  70. public function messages()
  71. {
  72. return $this->messages;
  73. }
  74. //获取场景验证规则
  75. public function getSceneRules($name, $fields = null)
  76. {
  77. $res = array();
  78. if(!isset($this->scene[$name]))
  79. {
  80. return false;
  81. }
  82. $scene = $this->scene[$name];
  83. if($fields != null && is_array($fields))
  84. {
  85. $scene = $fields;
  86. }
  87. foreach($scene as $k=>$v)
  88. {
  89. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  90. }
  91. return $res;
  92. }
  93. //获取场景验证规则自定义错误信息
  94. public function getSceneRulesMessages()
  95. {
  96. return $this->messages;
  97. }
  98. }