| 12345678910111213141516171819202122232425262728293031323334353637 | 
							- <?php
 
- namespace app\common\validate;
 
- use think\Db;
 
- use think\Validate;
 
- class DeviceLog extends Validate{
 
-     protected $rule = [
 
-         'sn|编号'  =>  '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;
 
-     }
 
- }
 
 
  |