'require|checkUnique', 'type|类型' => 'require', ]; protected $message = [ ]; protected $scene = [ ]; protected function checkUnique($value,$rule,$data=[]) { $info = Db::name('device_log') ->where('sn',$value) ->where('del',0) ->where('type',$data['type'])->find(); if($data['id'] <= 0 && $info){ return '编号已存在'; } if($info && $data['id'] > 0 && $info['id'] != $data['id']){ return '编号已存在'; } return true; } }