MemberValidator.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Validator;
  3. class MemberValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'avatar' => 'required',
  9. 'nickname' => 'required',
  10. 'email' => 'required|email',
  11. 'mobile' => 'required|mobile',
  12. 'code' => 'required',
  13. 'invite_code' => 'required',
  14. 'scene' => 'required',
  15. 'pay_password' => 'required',
  16. 'gender' => 'required',
  17. 'coin_type' => 'required',
  18. 'to_user_id' => 'required',
  19. ];
  20. // 当前模型所有错误提示信息
  21. public static $msgs = [
  22. 'required' => ':attribute不能为空',
  23. 'string' => ':attribute必须是字符串',
  24. 'min' => ':attribute长度不能小于:min位',
  25. 'max' => ':attribute长度不能大于:max位',
  26. 'exists' => ':attribute不存在',
  27. 'rule' => ':attribute格式不正确',
  28. ];
  29. // 当前模型所有验证字段
  30. public static $fields = [
  31. 'id' => 'ID',
  32. 'avatar' => '头像',
  33. 'gender' => '性别',
  34. 'nickname' => '昵称',
  35. 'mobile' => '手机号码',
  36. 'email' => '邮箱地址',
  37. 'pay_password' => '交易密码',
  38. 'to_user_id' => '转账用户ID号',
  39. 'invite_code' => '邀请码',
  40. 'scene' => '验证码类型',
  41. 'coin_type' => '账户类型',
  42. 'code' => '验证码',
  43. ];
  44. // 当前模型所有验证场景
  45. public static $scenes = [
  46. 'info'=> ['id'],
  47. 'save'=> ['mobile','nickname','gender'],
  48. 'sms'=> ['mobile','scene'],
  49. 'mobile_login'=> ['mobile','code'],
  50. 'email_login'=> ['email','code'],
  51. 'email_register'=> ['email','code'],
  52. 'mobile_register'=> ['mobile','code'],
  53. 'email'=> ['email','scene'],
  54. 'recharge'=> ['usdt'],
  55. 'transfer'=> ['money','coin_type','to_user_id'],
  56. 'withdraw'=> ['money','coin_type'],
  57. 'trade'=> ['pay_password','code'],
  58. 'modify_email'=> ['email','new_email'],
  59. 'modify'=> ['nickname','gender'],
  60. 'wallet'=> ['email','trc_url','code']
  61. ];
  62. /**
  63. * 验证
  64. * @param $request
  65. * @param string $scene
  66. * @return int|mixed
  67. */
  68. public static function check($request, $scene=''){
  69. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  70. return $validator->checkParams($request, $scene);
  71. }
  72. }