HouseFloor.php 785 B

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