HouseAuth.php 920 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. use think\Db;
  5. class HouseAuth extends Validate{
  6. protected $rule = [
  7. 'user_id|用户' => 'require|checkUnique',
  8. 'type|类型' => 'require|in:1,2',
  9. 'ids|权限' => 'require',
  10. ];
  11. protected $message = [
  12. 'type.in' => '参数错误',
  13. 'ids.require' => '未选择权限'
  14. ];
  15. protected $scene = [
  16. ];
  17. protected function checkUnique($value,$rule,$data=[])
  18. {
  19. $info = Db::name('house_auth')
  20. ->where('user_id',$data['user_id'])
  21. ->where('org_id',$data['org_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. }