GroupCheck.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. +-----------------------------------------------------------------------------------------------
  4. * GouGuOPEN [ 左手研发,右手开源,未来可期!]
  5. +-----------------------------------------------------------------------------------------------
  6. * @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
  7. +-----------------------------------------------------------------------------------------------
  8. * @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
  9. +-----------------------------------------------------------------------------------------------
  10. * @Author 勾股工作室 <hdm58@qq.com>
  11. +-----------------------------------------------------------------------------------------------
  12. */
  13. namespace app\home\validate;
  14. use think\Validate;
  15. class GroupCheck extends Validate
  16. {
  17. protected $rule = [
  18. 'title' => 'require|unique:admin_group',
  19. 'id' => 'require',
  20. 'status' => 'require|checkStatus:-1,1',
  21. ];
  22. protected $message = [
  23. 'title.require' => '名称不能为空',
  24. 'title.unique' => '同样的记录已经存在',
  25. 'id.require' => '缺少更新条件',
  26. 'status.require' => '状态为必选',
  27. 'status.checkStatus' => '系统所有者组不能被禁用',
  28. ];
  29. protected $scene = [
  30. 'add' => ['title', 'status'],
  31. 'edit' => ['id', 'title', 'status'],
  32. ];
  33. // 自定义验证规则
  34. protected function checkStatus($value, $rule, $data)
  35. {
  36. if ($value == -1 and $data['id'] == 1) {
  37. return $rule == false;
  38. }
  39. return $rule == true;
  40. }
  41. }