|
|
@@ -1,7 +1,17 @@
|
|
|
-
|
|
|
const axios = require('axios');
|
|
|
const Logs = require('../libs/logs');
|
|
|
|
|
|
+const PS_IOR_KEYS = [
|
|
|
+ ['0', 'ior_mh', 'ior_mn', 'ior_mc'],
|
|
|
+ // ['0', 'ior_rh_05', 'ior_mn', 'ior_rc_05'],
|
|
|
+ ['-1', 'ior_rh_15', 'ior_wmh_1', 'ior_rac_05'],
|
|
|
+ ['-2', 'ior_rh_25', 'ior_wmh_2', 'ior_rac_15'],
|
|
|
+ ['+1', 'ior_rah_05', 'ior_wmc_1', 'ior_rc_15'],
|
|
|
+ ['+2', 'ior_rah_15', 'ior_wmc_2', 'ior_rc_25'],
|
|
|
+];
|
|
|
+
|
|
|
+const BASE_URL = 'https://api.isthe.me/api/p';
|
|
|
+
|
|
|
const GAMES = {
|
|
|
Leagues: {},
|
|
|
List: {},
|
|
|
@@ -29,7 +39,7 @@ const getMarketType = (mk) => {
|
|
|
* 更新联赛列表
|
|
|
*/
|
|
|
const syncLeaguesList = ({ mk, leagues }) => {
|
|
|
- axios.post('https://api.isthe.me/api/p/syncLeague', { mk, leagues })
|
|
|
+ axios.post(`${BASE_URL}/syncLeague`, { mk, leagues })
|
|
|
.then(res => {
|
|
|
Logs.out('syncLeaguesList', res.data);
|
|
|
})
|
|
|
@@ -51,7 +61,7 @@ const updateLeaguesList = ({ mk, leagues }) => {
|
|
|
* 获取筛选过的联赛
|
|
|
*/
|
|
|
const getFilteredLeagues = async (mk) => {
|
|
|
- return axios.get(`https://api.isthe.me/api/p/getLeagueTast?mk=${mk}`)
|
|
|
+ return axios.get(`${BASE_URL}/getLeagueTast?mk=${mk}`)
|
|
|
.then(res => {
|
|
|
if (res.data.code == 0) {
|
|
|
return res.data.data;
|
|
|
@@ -64,7 +74,7 @@ const getFilteredLeagues = async (mk) => {
|
|
|
* 同步比赛列表到服务器
|
|
|
*/
|
|
|
const syncGamesList = ({ platform, mk, games }) => {
|
|
|
- axios.post('https://api.isthe.me/api/p/syncGames', { platform, mk, games })
|
|
|
+ axios.post(`${BASE_URL}/syncGames`, { platform, mk, games })
|
|
|
.then(res => {
|
|
|
Logs.out('syncGamesList', { platform, mk, count: games.length }, res.data);
|
|
|
})
|
|
|
@@ -122,10 +132,25 @@ const updateGamesList = (({ platform, mk, games } = {}) => {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+/**
|
|
|
+ * 提交盘口数据
|
|
|
+ */
|
|
|
+const submitOdds = ({ platform, mk, games }) => {
|
|
|
+ // console.log('syncOdds', games);
|
|
|
+ axios.post(`${BASE_URL}/syncOdds`, { platform, mk, games})
|
|
|
+ .then(res => {
|
|
|
+ Logs.out('syncOdds', { platform, mk, count: games.length }, res.data);
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ Logs.out('syncOdds', { platform, mk }, err.message);
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
/**
|
|
|
* 同步基准盘口
|
|
|
*/
|
|
|
-const syncBaseEvents = ({ marketType, games, outrights }) => {
|
|
|
+const syncBaseEvents = ({ mk, games, outrights }) => {
|
|
|
+ const marketType = getMarketType(mk);
|
|
|
const baseList = GAMES.Baselist;
|
|
|
if (!baseList[marketType]) {
|
|
|
return;
|
|
|
@@ -150,6 +175,33 @@ const syncBaseEvents = ({ marketType, games, outrights }) => {
|
|
|
baseGame.special = special;
|
|
|
}
|
|
|
});
|
|
|
+
|
|
|
+ if (games?.length) {
|
|
|
+ const gamesList = baseList[marketType]?.map(game => {
|
|
|
+ const { evtime, events, sptime, special, ...gameInfo } = game;
|
|
|
+ const expireTime = Date.now() - 15000;
|
|
|
+ let odds = {};
|
|
|
+ if (evtime > expireTime) {
|
|
|
+ odds = { ...odds, ...events };
|
|
|
+ }
|
|
|
+ if (sptime > expireTime) {
|
|
|
+ odds = { ...odds, ...special };
|
|
|
+ }
|
|
|
+ const matches = PS_IOR_KEYS.map(([label, ...keys]) => {
|
|
|
+ const match = keys.map(key => ({
|
|
|
+ key,
|
|
|
+ value: odds[key] ?? 0
|
|
|
+ }));
|
|
|
+ return {
|
|
|
+ label,
|
|
|
+ match
|
|
|
+ };
|
|
|
+ }).filter(item => item.match.every(entry => entry.value !== 0));
|
|
|
+ return { ...gameInfo, matches };
|
|
|
+ });
|
|
|
+ // console.log('baseList', baseList[marketType]);
|
|
|
+ submitOdds({ platform: 'ps', mk, games: gamesList });
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -161,10 +213,8 @@ const updateGamesEvents = ({ platform, mk, games, outrights }) => {
|
|
|
return reject(new Error('PLATFORM_GAMES_INVALID'));
|
|
|
}
|
|
|
|
|
|
- const marketType = getMarketType(mk);
|
|
|
-
|
|
|
if (platform == 'ps') {
|
|
|
- syncBaseEvents({ marketType, games, outrights });
|
|
|
+ syncBaseEvents({ mk, games, outrights });
|
|
|
}
|
|
|
|
|
|
resolve();
|
|
|
@@ -174,8 +224,14 @@ const updateGamesEvents = ({ platform, mk, games, outrights }) => {
|
|
|
/**
|
|
|
* 获取关联比赛
|
|
|
*/
|
|
|
-const getGamesRelation = () => {
|
|
|
- return [];
|
|
|
+const getGamesRelation = async (mk) => {
|
|
|
+ return axios.get(`${BASE_URL}/getGameTast?mk=${mk}`)
|
|
|
+ .then(res => {
|
|
|
+ if (res.data.code == 0) {
|
|
|
+ return res.data.data;
|
|
|
+ }
|
|
|
+ return Promise.reject(new Error(res.data.message));
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
|