1234567891011121314151617181920212223242526272829303132333435 |
- <?php
- namespace app\common\validate;
- use think\Validate;
- use think\Db;
- class HouseCommunity extends Validate{
- protected $rule = [
- 'title|标题' => 'require|checkUnique',
- 'district_id' => 'require|gt:0',
- ];
- protected $scene = [
- 'district_id.require' => '未选择所属城区',
- 'district_id.gt' => '未选择所属城区',
- ];
- protected function checkUnique($value,$rule,$data=[])
- {
- $info = Db::name('house_community')
- ->where('title',$data['title'])
- ->where('type',$data['type'])
- ->where('district_id',$data['district_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;
- }
- }
|