123456789101112131415161718192021222324252627282930313233 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class HouseFloor extends Validate{
- protected $rule = [
- 'title|标题' => 'require|checkUnique',
- 'building_id|所属楼房' => 'require',
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('house_floor')
- ->where('title',$data['title'])
- ->where('building_id',$data['building_id'])
- ->where('org_id',$data['org_id'])
- ->find();
- if($data['id'] <= 0 && $info){
- return '名称已被使用';
- }
- if($info && $data['id'] > 0 && $info['id'] != $data['id']){
- return '名称已被使用';
- }
- return true;
- }
- }
|