AdminValidate.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\admin\validate;
  3. class AdminValidate extends BaseValidate
  4. {
  5. /**
  6. * 设置校验规则
  7. * @var string[]
  8. */
  9. protected $rule = [
  10. 'id' => 'require',
  11. 'username' => 'require|min:1',
  12. 'nickname' => 'require|min:1',
  13. 'is_kefu' => 'require|in:0,1',
  14. 'password' => 'min:6',
  15. 'phone' => 'length:0,20',
  16. 'email' => 'email',
  17. 'sex' => 'require|in:0,1,2',
  18. 'role_id' => 'integer',
  19. 'department_id' => 'integer',
  20. 'remark' => 'length:0,100',
  21. 'old_password' => 'require|length:6,20',
  22. 'password_confirmation' => 'require|length:6,20|confirm:password',
  23. 'avatar' => 'length:0,200',
  24. ];
  25. /**
  26. * 参数描述
  27. * @var string[]
  28. */
  29. protected $field = [
  30. 'id' => 'id',
  31. 'username' => '账号',
  32. 'nickname' => '昵称',
  33. 'is_kefu' => '是否是客服',
  34. 'password' => '密码',
  35. 'phone' => '手机号',
  36. 'email' => '邮箱',
  37. 'sex' => '性别',
  38. 'role_id' => '角色ID',
  39. 'department_id' => '部门ID',
  40. 'remark' => '备注',
  41. 'old_password' => '旧密码',
  42. 'password' => '新密码',
  43. 'password_confirmation' => '确认密码',
  44. 'avatar' => '头像',
  45. ];
  46. /**
  47. * @notes 添加场景
  48. */
  49. public function sceneAdd()
  50. {
  51. return $this->only(['username', 'nickname', 'is_kefu', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark','avatar']);
  52. }
  53. /**
  54. * @notes 编辑场景
  55. */
  56. public function sceneEdit()
  57. {
  58. return $this->only(['id','username', 'nickname', 'is_kefu', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark','avatar']);
  59. }
  60. public function sceneDel()
  61. {
  62. return $this->only(['id']);
  63. }
  64. public function scenePassword()
  65. {
  66. return $this->only(['old_password','password','password_confirmation']);
  67. }
  68. public function sceneLogin()
  69. {
  70. return $this->only(['username','password']);
  71. }
  72. }