GradeValidate.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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\customer\validate;
  14. use think\Validate;
  15. use think\facade\Db;
  16. class GradeValidate extends Validate
  17. {
  18. // 自定义验证规则
  19. protected function checkOne($value,$rule,$data=[])
  20. {
  21. $id = isset($data['id'])?$data['id']:0;
  22. $count = Db::name('CustomerGrade')->where([['title','=',$data['title']],['id','<>',$id],['delete_time','=',0]])->count();
  23. return $count == 0 ? true : false;
  24. }
  25. protected $rule = [
  26. 'title' => 'require|checkOne',
  27. 'id' => 'require',
  28. ];
  29. protected $message = [
  30. 'title.require' => '名称不能为空',
  31. 'title.checkOne' => '同样的名称已经存在',
  32. 'id.require' => '缺少更新条件',
  33. ];
  34. protected $scene = [
  35. 'add' => ['title'],
  36. 'edit' => ['title', 'id'],
  37. ];
  38. }