HouseSelect.php 710 B

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