HouseCommunity.php 926 B

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