123456789101112131415161718192021222324252627282930313233343536373839 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class HouseAuth extends Validate{
- protected $rule = [
- 'user_id|用户' => 'require|checkUnique',
- 'type|类型' => 'require|in:1,2',
- 'ids|权限' => 'require',
- ];
- protected $message = [
- 'type.in' => '参数错误',
- 'ids.require' => '未选择权限'
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('house_auth')
- ->where('user_id',$data['user_id'])
- ->where('org_id',$data['org_id'])
- ->where('type',$data['type'])
- ->find();
- if($data['id'] <= 0 && $info){
- return '该用户已存在';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '该用户已存在';
- }
- return true;
- }
- }
|