12345678910111213141516171819202122232425262728293031323334 |
- <?php
- namespace app\common\validate;
- use think\Db;
- use think\Validate;
- class TemperatureDevice extends Validate{
- protected $rule = [
- 'snaddr|设备码' => 'require|checkUnique',
- 'dev_name|设备名称' => 'require|length:1,30',
- ];
- protected function checkUnique($value, $rule, $data=[]){
- if(isset($data['id']) && $data['id'] > 0){
- $ret = Db::name('temperature_device')
- ->where('snaddr',$data['snaddr'])
- ->where('org_id',$data['org_id'])
- ->where('del',0)
- ->where('id','<>',$data['id'])
- ->find();
- }else{
- $ret = Db::name('temperature_device')
- ->where('snaddr',$data['snaddr'])
- ->where('org_id',$data['org_id'])
- ->where('del',0)
- ->find();
- }
- return $ret?'设备码已存在':true;
- }
- }
|