From 69dcd27a87c432a4b231b11218f2b5012a793047 Mon Sep 17 00:00:00 2001 From: Lei OT Date: Mon, 26 Aug 2024 14:32:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=B0=E5=BD=95=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E5=90=8E,=20heytrip=E6=8E=A5=E5=8F=A3=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/controllers/Heytrip.js | 4 ++++ server/controllers/api.js | 10 ++++++++-- server/services/heytripService.js | 9 +++++---- server/vendor/heytrip.js | 13 +++++++++++++ 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/server/controllers/Heytrip.js b/server/controllers/Heytrip.js index 3e5c618..48c1807 100644 --- a/server/controllers/Heytrip.js +++ b/server/controllers/Heytrip.js @@ -21,6 +21,10 @@ class Heytrip extends BaseController { getAvailability = async (ctx) => { try { const data = await heytripService.getHotelAvailability(ctx.query); + heytripService.writeHeytripRequestLog({ + action: 'heytripAvailability', + body: ctx.query, + }); ctx.body = this.response(0, 'get_hotel_availability', data); } catch (error) { ctx.body = this.response(1, error.message || 'An error occurred.'); diff --git a/server/controllers/api.js b/server/controllers/api.js index 66547e5..7e667a9 100644 --- a/server/controllers/api.js +++ b/server/controllers/api.js @@ -21,14 +21,20 @@ class Api extends BaseController { let quoteRes = []; if (checkin && checkout) { - const allIds = rows.map((item) => item.hotel_id); - quoteRes = await QuotedHotelsPrice({ + const allIds = rows.map((item) => Number(item.hotel_id)); + const basePriceParam = { hotelIds: allIds, nationality: 'CN', // 默认取中国报价 CheckInDate: checkin, CheckOutDate: checkout, adultNum: 1, roomCount: 1, + }; + quoteRes = await QuotedHotelsPrice(basePriceParam); + + heytripService.writeHeytripRequestLog({ + action: 'heytripBasePrice', + body: basePriceParam, }); } diff --git a/server/services/heytripService.js b/server/services/heytripService.js index b6fe6f2..a05e048 100644 --- a/server/services/heytripService.js +++ b/server/services/heytripService.js @@ -465,15 +465,16 @@ class Heytrip { writeHeytripRequestLog = async ({ action, body }) => { const actionMapped = { - 'getHotelAvailability': '/Accommodation/Availability', - 'getHotelInfo': '/Accommodation/AccommodationsDetails', - 'getHotelIds': '/Accommodation/AvailableAccommodationIds', + 'heytripAvailability': '/Accommodation/Availability', + 'heytripDetails': '/Accommodation/AccommodationsDetails', + 'heytripIds': '/Accommodation/AvailableAccommodationIds', + 'heytripBasePrice': '/Accommodation/QuotedHotelsPrice', }; const data = { action: action, // method: ctx.method, path: actionMapped[action], - request_data: body, + request_data: JSON.stringify(body), // ip: ctx.ip, }; return await Logs.create(data, { logging: false }); diff --git a/server/vendor/heytrip.js b/server/vendor/heytrip.js index 35fd24f..cc54b34 100644 --- a/server/vendor/heytrip.js +++ b/server/vendor/heytrip.js @@ -16,6 +16,10 @@ const make_token = () => { var authHeaderValue = 'Bearer apikey=' + apiKey + ',signature=' + hash + ',timestamp=' + timestamp; return authHeaderValue; }; + +/** + * 获取有效酒店编号 + */ const AvailableAccommodationIds = async (pageIndex) => { const response = await get(`${HEYTRIP_API_PROD}/AvailableAccommodationIds?pageIndex=${pageIndex}`, { headers: { @@ -26,6 +30,9 @@ const AvailableAccommodationIds = async (pageIndex) => { return response.data.Data || []; }; +/** + * 获取酒店房型相关静态信息 + */ const AccommodationsDetails = async (body) => { if (isEmpty(body.AccommodationIds)) { return []; @@ -42,6 +49,9 @@ const AccommodationsDetails = async (body) => { return Object.values(response.data.Data || {}); }; +/** + * 报价查询 + */ const Availability = async (body) => { // console.log('Call Heytrip'); const response = await post( @@ -57,6 +67,9 @@ const Availability = async (body) => { return response.data.Data || []; }; +/** + * 酒店起价查询 + */ const QuotedHotelsPrice = async (body) => { const idsChunk = body.hotelIds.length > 10 ? chunk(body.hotelIds, 10) : [body.hotelIds]; let quoteRes = [];