MemberValidator.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. 'pay_password' => '交易密码',
  41. 'to_user_id' => '转账用户ID号',
  42. 'invite_code' => '邀请码',
  43. 'scene' => '验证码类型',
  44. 'coin_type' => '账户类型',
  45. 'code' => '验证码',
  46. 'password' => '密码',
  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'=> ['nickname','gender'],
  67. 'wallet'=> ['email','trc_url','code']
  68. ];
  69. /**
  70. * 验证
  71. * @param $request
  72. * @param string $scene
  73. * @return int|mixed
  74. */
  75. public static function check($request, $scene=''){
  76. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  77. return $validator->checkParams($request, $scene);
  78. }
  79. }