MemberValidator.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. 'password' => 'required',
  20. ];
  21. // 当前模型所有错误提示信息
  22. public static $msgs = [
  23. 'required' => ':attribute不能为空',
  24. 'string' => ':attribute必须是字符串',
  25. 'min' => ':attribute长度不能小于:min位',
  26. 'max' => ':attribute长度不能大于:max位',
  27. 'exists' => ':attribute不存在',
  28. 'rule' => ':attribute格式不正确',
  29. ];
  30. // 当前模型所有验证字段
  31. public static $fields = [
  32. 'id' => 'ID',
  33. 'avatar' => '头像',
  34. 'gender' => '性别',
  35. 'nickname' => '昵称',
  36. 'mobile' => '手机号码',
  37. 'email' => '邮箱地址',
  38. 'new_email' => '新邮箱地址',
  39. 'new_mobile' => '新手机号码',
  40. 'password' => '登录密码',
  41. 'pay_password' => '交易密码',
  42. 'to_user_id' => '转账用户ID号',
  43. 'invite_code' => '邀请码',
  44. 'scene' => '验证码类型',
  45. 'coin_type' => '账户类型',
  46. 'code' => '验证码',
  47. ];
  48. // 当前模型所有验证场景
  49. public static $scenes = [
  50. 'info'=> ['id'],
  51. 'save'=> ['mobile','nickname','gender'],
  52. 'sms'=> ['mobile','scene'],
  53. 'mobile_login'=> ['mobile','code'],
  54. 'email_login'=> ['email','code'],
  55. 'email_register'=> ['email','code'],
  56. 'mobile_register'=> ['mobile','code'],
  57. 'email'=> ['email','scene'],
  58. 'email_password_login'=> ['email','password'],
  59. 'mobile_password_login'=> ['mobile','password'],
  60. 'recharge'=> ['usdt'],
  61. 'transfer'=> ['money','coin_type','to_user_id'],
  62. 'withdraw'=> ['money','coin_type'],
  63. 'trade'=> ['pay_password','code'],
  64. 'modify_email'=> ['email','new_email'],
  65. 'modify_mobile'=> ['mobile','new_mobile'],
  66. 'modify_password'=> ['password'],
  67. 'reset_password'=> ['password'],
  68. 'modify'=> ['nickname','gender'],
  69. 'wallet'=> ['trc_url','code']
  70. ];
  71. /**
  72. * 验证
  73. * @param $request
  74. * @param string $scene
  75. * @return int|mixed
  76. */
  77. public static function check($request, $scene=''){
  78. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  79. return $validator->checkParams($request, $scene);
  80. }
  81. }