0
0

Group.php 922 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\validate;
  3. use think\Db;
  4. use think\Validate;
  5. class Group extends Validate{
  6. /**
  7. * 定义验证规则
  8. * 格式:'字段名' => ['规则1','规则2'...]
  9. *
  10. * @var array
  11. */
  12. protected $rule = [
  13. 'title|名称' => 'require|length:1,30|checkUnique',
  14. ];
  15. /**
  16. * 定义错误信息
  17. * 格式:'字段名.规则名' => '错误信息'
  18. *
  19. * @var array
  20. */
  21. protected $message = [];
  22. protected function checkUnique($value, $rule, $data=[]){
  23. if(isset($data['id']) && $data['id'] > 0){
  24. $ret = Db::name('group')->where('title',$data['title'])->where('org_id',$data['org_id'])->where('id','<>',$data['id'])->find();
  25. }else{
  26. $ret =Db::name('group')->where('title',$data['title'])->where('org_id',$data['org_id'])->find();
  27. }
  28. return $ret?'名称已被使用':true;
  29. }
  30. }