12345678910111213141516171819202122232425262728293031323334353637 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class HouseLevel extends Validate{
- protected $rule = [
- 'title|标题' => 'require|checkUnique',
- 'type|类型' => 'require|in:1,2',
- ];
- protected $message = [
- 'type.in' => '参数错误'
- ];
- protected $scene = [
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('house_level')
- ->where('title',$data['title'])
- ->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;
- }
- }
|