Admin.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\validate;
  3. use think\Validate;
  4. class Admin extends Validate
  5. {
  6. protected $failException = true;
  7. protected $rule = [
  8. 'username' => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:admin',
  9. 'nickname' => 'require',
  10. 'password' => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
  11. 'email' => 'email|unique:admin',
  12. 'mobile' => 'mobile|unique:admin',
  13. 'group_arr' => 'require|array',
  14. 'openid' => 'require|unique:admin,openid^unionid',
  15. 'change_mobile' => 'require|mobile',
  16. 'change_email' => 'email',
  17. ];
  18. /**
  19. * 验证提示信息
  20. * @var array
  21. */
  22. protected $message = [];
  23. /**
  24. * 字段描述
  25. */
  26. protected $field = [
  27. ];
  28. /**
  29. * 验证场景
  30. */
  31. protected $scene = [
  32. 'add' => ['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'],
  33. 'wechat' => ['opendid',"unionid"]
  34. ];
  35. /**
  36. * 验证场景-前台自己修改自己资料
  37. */
  38. public function sceneInfo()
  39. {
  40. return $this->only(['nickname', 'password', 'email', 'mobile'])
  41. ->remove('password', 'require');
  42. }
  43. public function sceneWxEdit(){
  44. return $this->only(["nickname","change_mobile","change_email","avatar"]);
  45. }
  46. /**
  47. * 验证场景-编辑资料
  48. */
  49. public function sceneEdit()
  50. {
  51. return $this->only(['username', 'nickname', 'password', 'email', 'mobile', 'group_arr'])
  52. ->remove('password', 'require');
  53. }
  54. public function __construct()
  55. {
  56. $this->field = [
  57. 'username' => __('Username'),
  58. 'nickname' => __('Nickname'),
  59. 'password' => __('Password'),
  60. 'email' => __('Email'),
  61. 'change_email' => __('Email'),
  62. 'mobile' => __('Mobile'),
  63. 'change_mobile' => __('Mobile'),
  64. 'group_arr' => __('Group Name Arr'),
  65. ];
  66. $this->message = array_merge($this->message, [
  67. 'username.regex' => __('Please input correct username'),
  68. 'password.regex' => __('Please input correct password')
  69. ]);
  70. parent::__construct();
  71. }
  72. }