GroupCheck.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2021 勾股工作室
  4. * @license https://opensource.org/licenses/Apache-2.0
  5. * @link https://www.gougucms.com
  6. */
  7. namespace app\admin\validate;
  8. use think\Validate;
  9. class GroupCheck extends Validate
  10. {
  11. protected $rule = [
  12. // 'title' => 'require|unique:admin_group',
  13. 'title' => 'require',
  14. 'id' => 'require',
  15. 'status' => 'require|checkStatus:-1,1',
  16. ];
  17. protected $message = [
  18. 'title.require' => '名称不能为空',
  19. // 'title.unique' => '同样的记录已经存在',
  20. 'id.require' => '缺少更新条件',
  21. 'status.require' => '状态为必选',
  22. 'status.checkStatus' => '系统所有者组不能被禁用',
  23. ];
  24. protected $scene = [
  25. 'add' => ['title', 'status'],
  26. 'edit' => ['id', 'title', 'status'],
  27. ];
  28. // 自定义验证规则
  29. protected function checkStatus($value, $rule, $data)
  30. {
  31. if ($value == -1 and $data['id'] == 1) {
  32. return $rule == false;
  33. }
  34. return $rule == true;
  35. }
  36. }