AdminValidate.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. ];
  24. /**
  25. * 参数描述
  26. * @var string[]
  27. */
  28. protected $field = [
  29. 'id' => 'id',
  30. 'username' => '账号',
  31. 'nickname' => '昵称',
  32. 'is_kefu' => '是否是客服',
  33. 'password' => '密码',
  34. 'phone' => '手机号',
  35. 'email' => '邮箱',
  36. 'sex' => '性别',
  37. 'role_id' => '角色ID',
  38. 'department_id' => '部门ID',
  39. 'remark' => '备注',
  40. 'old_password' => '旧密码',
  41. 'password' => '新密码',
  42. 'password_confirmation' => '确认密码',
  43. ];
  44. /**
  45. * @notes 添加场景
  46. */
  47. public function sceneAdd()
  48. {
  49. return $this->only(['username', 'nickname', 'is_kefu', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark']);
  50. }
  51. /**
  52. * @notes 编辑场景
  53. */
  54. public function sceneEdit()
  55. {
  56. return $this->only(['id','username', 'nickname', 'is_kefu', 'password', 'phone', 'email', 'sex', 'role_id', 'department_id', 'remark']);
  57. }
  58. public function sceneDel()
  59. {
  60. return $this->only(['id']);
  61. }
  62. public function scenePassword()
  63. {
  64. return $this->only(['old_password','password','password_confirmation']);
  65. }
  66. public function sceneLogin()
  67. {
  68. return $this->only(['username','password']);
  69. }
  70. }