where('user_id',$userId)->find(); $token = create_token($userId); if($info){ $ret = Db::name('token')->where('id',$info['id'])->setField('token',$token); }else{ $ret = Db::name('token')->insert([ 'token' => $token, 'user_id' => $userId ]); } if(!$ret){ $this->error = 'token更新失败'; return false; } return $token; } public function logout($userId){ $this->where('user_id',$userId)->setField('token',''); return true; } }