HouseLevel.php 836 B

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