'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; } }