| 123456789101112131415161718192021222324252627282930 | <?phpnamespace app\common\validate;use think\Db;use think\Validate;class AttendanceMachine extends Validate{    protected $rule = [        'sn|设备编号'  =>  'require|max:30|checkUnique',//        'org_id|所属项目'  =>  'require|gt:0',    ];    protected function checkUnique($value,$rule,$data=[])    {        $info = Db::name('attendance_machine')            ->where('sn',$value)            ->where('del',0)            ->find();        if($data['id'] <= 0 && $info){            return '设备编号已被使用';        }        if($info && $data['id'] > 0 && $info['id'] != $data['id']){            return '设备编号已被使用';        }        return true;    }}
 |