HouseDistrict.php 728 B

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class HouseDistrict extends Validate{
  6. protected $rule = [
  7. 'title|标题' => 'require|checkUnique',
  8. ];
  9. protected $scene = [
  10. ];
  11. protected function checkUnique($value,$rule,$data=[])
  12. {
  13. $info = Db::name('house_district')
  14. ->where('title',$data['title'])
  15. ->where('org_id',$data['org_id'])
  16. ->where('type',$data['type'])
  17. ->find();
  18. if($data['id'] <= 0 && $info){
  19. return '名称已被使用';
  20. }
  21. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  22. return '名称已被使用';
  23. }
  24. return true;
  25. }
  26. }