feat: 记录请求后, heytrip接口日志

main
Lei OT 10 months ago
parent 06c6c2506b
commit 69dcd27a87

@ -21,6 +21,10 @@ class Heytrip extends BaseController {
getAvailability = async (ctx) => { getAvailability = async (ctx) => {
try { try {
const data = await heytripService.getHotelAvailability(ctx.query); const data = await heytripService.getHotelAvailability(ctx.query);
heytripService.writeHeytripRequestLog({
action: 'heytripAvailability',
body: ctx.query,
});
ctx.body = this.response(0, 'get_hotel_availability', data); ctx.body = this.response(0, 'get_hotel_availability', data);
} catch (error) { } catch (error) {
ctx.body = this.response(1, error.message || 'An error occurred.'); ctx.body = this.response(1, error.message || 'An error occurred.');

@ -21,14 +21,20 @@ class Api extends BaseController {
let quoteRes = []; let quoteRes = [];
if (checkin && checkout) { if (checkin && checkout) {
const allIds = rows.map((item) => item.hotel_id); const allIds = rows.map((item) => Number(item.hotel_id));
quoteRes = await QuotedHotelsPrice({ const basePriceParam = {
hotelIds: allIds, hotelIds: allIds,
nationality: 'CN', // 默认取中国报价 nationality: 'CN', // 默认取中国报价
CheckInDate: checkin, CheckInDate: checkin,
CheckOutDate: checkout, CheckOutDate: checkout,
adultNum: 1, adultNum: 1,
roomCount: 1, roomCount: 1,
};
quoteRes = await QuotedHotelsPrice(basePriceParam);
heytripService.writeHeytripRequestLog({
action: 'heytripBasePrice',
body: basePriceParam,
}); });
} }

@ -465,15 +465,16 @@ class Heytrip {
writeHeytripRequestLog = async ({ action, body }) => { writeHeytripRequestLog = async ({ action, body }) => {
const actionMapped = { const actionMapped = {
'getHotelAvailability': '/Accommodation/Availability', 'heytripAvailability': '/Accommodation/Availability',
'getHotelInfo': '/Accommodation/AccommodationsDetails', 'heytripDetails': '/Accommodation/AccommodationsDetails',
'getHotelIds': '/Accommodation/AvailableAccommodationIds', 'heytripIds': '/Accommodation/AvailableAccommodationIds',
'heytripBasePrice': '/Accommodation/QuotedHotelsPrice',
}; };
const data = { const data = {
action: action, action: action,
// method: ctx.method, // method: ctx.method,
path: actionMapped[action], path: actionMapped[action],
request_data: body, request_data: JSON.stringify(body),
// ip: ctx.ip, // ip: ctx.ip,
}; };
return await Logs.create(data, { logging: false }); return await Logs.create(data, { logging: false });

@ -16,6 +16,10 @@ const make_token = () => {
var authHeaderValue = 'Bearer apikey=' + apiKey + ',signature=' + hash + ',timestamp=' + timestamp; var authHeaderValue = 'Bearer apikey=' + apiKey + ',signature=' + hash + ',timestamp=' + timestamp;
return authHeaderValue; return authHeaderValue;
}; };
/**
* 获取有效酒店编号
*/
const AvailableAccommodationIds = async (pageIndex) => { const AvailableAccommodationIds = async (pageIndex) => {
const response = await get(`${HEYTRIP_API_PROD}/AvailableAccommodationIds?pageIndex=${pageIndex}`, { const response = await get(`${HEYTRIP_API_PROD}/AvailableAccommodationIds?pageIndex=${pageIndex}`, {
headers: { headers: {
@ -26,6 +30,9 @@ const AvailableAccommodationIds = async (pageIndex) => {
return response.data.Data || []; return response.data.Data || [];
}; };
/**
* 获取酒店房型相关静态信息
*/
const AccommodationsDetails = async (body) => { const AccommodationsDetails = async (body) => {
if (isEmpty(body.AccommodationIds)) { if (isEmpty(body.AccommodationIds)) {
return []; return [];
@ -42,6 +49,9 @@ const AccommodationsDetails = async (body) => {
return Object.values(response.data.Data || {}); return Object.values(response.data.Data || {});
}; };
/**
* 报价查询
*/
const Availability = async (body) => { const Availability = async (body) => {
// console.log('Call Heytrip'); // console.log('Call Heytrip');
const response = await post( const response = await post(
@ -57,6 +67,9 @@ const Availability = async (body) => {
return response.data.Data || []; return response.data.Data || [];
}; };
/**
* 酒店起价查询
*/
const QuotedHotelsPrice = async (body) => { const QuotedHotelsPrice = async (body) => {
const idsChunk = body.hotelIds.length > 10 ? chunk(body.hotelIds, 10) : [body.hotelIds]; const idsChunk = body.hotelIds.length > 10 ? chunk(body.hotelIds, 10) : [body.hotelIds];
let quoteRes = []; let quoteRes = [];

Loading…
Cancel
Save