FlowCateCheck.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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\adm\validate;
  14. use think\Validate;
  15. use think\facade\Db;
  16. class FlowCateCheck extends Validate
  17. {
  18. // 自定义验证规则
  19. protected function checkOne($value,$rule,$data=[])
  20. {
  21. $id = isset($data['id'])?$data['id']:0;
  22. $table_array = ['invoice','ticket','approve'];
  23. if(in_array($data['check_table'],$table_array)){
  24. return true;
  25. }
  26. else{
  27. $count = Db::name('FlowCate')->where([['check_table','=',$data['check_table']],['id','<>',$id]])->count();
  28. return $count == 0 ? true : false;
  29. }
  30. }
  31. protected $rule = [
  32. 'title' => 'require',
  33. 'name' => 'require|alphaDash|unique:flow_cate',
  34. 'check_table' => 'require|alphaDash|checkOne',
  35. 'id' => 'require',
  36. ];
  37. protected $message = [
  38. 'title.require' => '审批类型名称不能为空',
  39. 'name.require' => '审批类型标识不能为空',
  40. 'name.unique' => '同样的审批类型标识已经存在',
  41. 'name.alphaDash' => '审批类型标识只能是小写字母',
  42. 'check_table.require' => '数据表不能为空',
  43. 'check_table.alphaDash' => '数据表只能是小写字母、数字下划线_',
  44. 'check_table.checkOne' => '同样的数据表已经存在',
  45. 'id.require' => '缺少更新条件',
  46. ];
  47. protected $scene = [
  48. 'add' => ['title','check_table'],
  49. 'edit' => ['id', 'title','check_table'],
  50. ];
  51. }