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.

145 lines
5.6 KiB

7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
7 years ago
6 years ago
6 years ago
6 years ago
7 years ago
6 years ago
7 years ago
  1. <?php
  2. namespace App\Http\Requests;
  3. class UserRequest extends BaseRequest
  4. {
  5. //总的验证规则
  6. protected $rules = [
  7. 'id' => 'required|integer',
  8. 'email' => 'max:60',
  9. 'user_name' => 'required|max:60',
  10. 'password' => 'required|max:50',
  11. 'pay_password' => 'max:50',
  12. 'head_img' => 'max:255',
  13. 'sex' => 'integer|between:0,2',
  14. 'birthday' => 'date_format:"Y-m-d"',
  15. 'commission' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'],
  16. 'money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'],
  17. 'frozen_money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'],
  18. 'point' => 'integer',
  19. 'rank_points' => 'integer',
  20. 'address_id' => 'integer',
  21. 'add_time' => 'integer',
  22. 'user_rank' => 'integer|between:0,99999',
  23. 'parent_id' => 'integer',
  24. 'nickname' => 'max:30',
  25. 'mobile' => 'max:20',
  26. 'status' => 'integer|between:0,5',
  27. 'group_id' => 'integer|between:0,99999',
  28. 'updated_at' => 'integer',
  29. 'signin_time' => 'date_format:"Y-m-d H:i:s"',
  30. 'openid' => 'max:100',
  31. 'unionid' => 'max:128',
  32. 'push_id' => 'max:30',
  33. 'refund_account' => 'max:30',
  34. 'refund_name' => 'max:20',
  35. 'consumption_money' => ['regex:/^\d{0,10}(\.\d{0,2})?$/'],
  36. ];
  37. //总的自定义错误信息
  38. protected $messages = [
  39. 'id.required' => 'ID必填',
  40. 'id.integer' => 'ID必须为数字',
  41. 'email.max' => 'email不能大于60个字符',
  42. 'user_name.required' => '用户名必填',
  43. 'user_name.max' => '用户名不能大于60个字符',
  44. 'password.required' => '密码必填',
  45. 'password.max' => '密码不能大于50个字符',
  46. 'pay_password.max' => '支付密码不能大于50个字符',
  47. 'head_img.max' => '头像不能大于255个字符',
  48. 'sex.integer' => '性别必须为数字',
  49. 'sex.between' => '性别1男2女',
  50. 'birthday.date_format' => '生日格式不正确',
  51. 'commission.regex' => '累积佣金格式不正确,累积佣金只能带2位小数的数字',
  52. 'money.regex' => '用户余额格式不正确,用户余额只能带2位小数的数字',
  53. 'frozen_money.regex' => '用户冻结资金格式不正确,用户冻结资金只能带2位小数的数字',
  54. 'point.integer' => '用户积分必须为数字',
  55. 'rank_points.integer' => '会员等级积分必须为数字',
  56. 'address_id.integer' => '默认收货地址ID必须为数字',
  57. 'add_time.integer' => '注册时间必须为数字',
  58. 'user_rank.integer' => '用户等级必须为数字',
  59. 'user_rank.between' => '用户等级只能1-99999',
  60. 'parent_id.integer' => '推荐人ID必须为数字',
  61. 'nickname.max' => '昵称不能大于30个字符',
  62. 'mobile.max' => '手机号不能大于20个字符',
  63. 'status.integer' => '用户状态必须为数字',
  64. 'status.between' => '用户状态 1正常状态 2 删除至回收站 3锁定',
  65. 'group_id.integer' => '分组必须为数字',
  66. 'group_id.between' => '分组只能1-99999',
  67. 'updated_at.integer' => '更新时间必须为数字',
  68. 'signin_time.date_format' => '签到时间格式不正确',
  69. 'openid.max' => 'openid不能大于100个字符',
  70. 'unionid.max' => 'unionid不能大于120个字符',
  71. 'push_id.max' => 'push_id不能大于30个字符',
  72. 'refund_account.max' => '退款账户不能大于30个字符',
  73. 'refund_name.max' => '退款姓名不能大于20个字符',
  74. 'consumption_money.regex' => '累计消费金额格式不正确,只能带2位小数的数字',
  75. ];
  76. //场景验证规则
  77. protected $scene = [
  78. 'add' => ['email', 'user_name', 'password', 'pay_password', 'head_img', 'sex', 'birthday', 'commission', 'money', 'frozen_money', 'point', 'rank_points', 'address_id', 'add_time', 'user_rank', 'parent_id', 'nickname', 'mobile', 'status', 'group_id', 'updated_at', 'signin_time', 'openid', 'unionid', 'push_id', 'refund_account', 'refund_name', 'consumption_money'],
  79. 'edit' => ['email', 'head_img', 'sex', 'birthday', 'address_id', 'nickname', 'updated_at', 'refund_account', 'refund_name'],
  80. 'wx_register' => ['email', 'user_name', 'password', 'pay_password', 'head_img', 'add_time', 'parent_id', 'nickname', 'mobile', 'group_id', 'openid', 'unionid', 'push_id'],
  81. 'del' => ['id'],
  82. ];
  83. /**
  84. * Determine if the user is authorized to make this request.
  85. *
  86. * @return bool
  87. */
  88. public function authorize()
  89. {
  90. return true; //修改为true
  91. }
  92. /**
  93. * Get the validation rules that apply to the request.
  94. *
  95. * @return array
  96. */
  97. public function rules()
  98. {
  99. return $this->rules;
  100. }
  101. /**
  102. * 获取被定义验证规则的错误消息.
  103. *
  104. * @return array
  105. */
  106. public function messages()
  107. {
  108. return $this->messages;
  109. }
  110. //获取场景验证规则
  111. public function getSceneRules($name, $fields = null)
  112. {
  113. $res = array();
  114. if(!isset($this->scene[$name]))
  115. {
  116. return false;
  117. }
  118. $scene = $this->scene[$name];
  119. if($fields != null && is_array($fields))
  120. {
  121. $scene = $fields;
  122. }
  123. foreach($scene as $k=>$v)
  124. {
  125. if(isset($this->rules[$v])){$res[$v] = $this->rules[$v];}
  126. }
  127. return $res;
  128. }
  129. //获取场景验证规则自定义错误信息
  130. public function getSceneRulesMessages()
  131. {
  132. return $this->messages;
  133. }
  134. }