HouseBuilding.php 951 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class HouseBuilding extends Validate{
  6. protected $rule = [
  7. 'title|标题' => 'require|checkUnique',
  8. 'type|类型' => 'require|in:1,2',
  9. 'community_id|所属小区' => 'require',
  10. ];
  11. protected $message = [
  12. 'type.in' => '参数错误'
  13. ];
  14. protected $scene = [
  15. ];
  16. protected function checkUnique($value,$rule,$data=[])
  17. {
  18. $info = Db::name('house_building')
  19. ->where('title',$data['title'])
  20. ->where('org_id',$data['org_id'])
  21. ->where('community_id',$data['community_id'])
  22. ->where('type',$data['type'])
  23. ->find();
  24. if($data['id'] <= 0 && $info){
  25. return '名称已被使用';
  26. }
  27. if($info && $data['id'] > 0 && $info['id'] != $data['id']){
  28. return '名称已被使用';
  29. }
  30. return true;
  31. }
  32. }