feat: 小黑盒游戏折扣改为按平台查询 (#4553)

This commit is contained in:
Yorkin Yuan
2020-04-28 11:12:54 +08:00
committed by GitHub
parent 1bb6cb51cf
commit 71af212afa
3 changed files with 67 additions and 13 deletions

View File

@@ -352,9 +352,15 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的
<Route author="MyFaith" example="/xiaoheihe/news" path="xiaoheihe/news"/> <Route author="MyFaith" example="/xiaoheihe/news" path="xiaoheihe/news"/>
### 游戏打折情况 ### 游戏折扣信息
<Route author="MyFaith" example="/xiaoheihe/discount" path="xiaoheihe/discount"/> <Route author="MyFaith" example="/xiaoheihe/discount/pc" path="xiaoheihe/discount/:platform?" :paramsDesc="['平台, 默认为Steam']">
| Steam | PlatStation4 | Switch |
| ----- | ------------ | ------ |
| pc | ps4 | switch |
</Route>
## 英雄联盟 ## 英雄联盟

View File

@@ -1182,7 +1182,7 @@ router.get('/gov/beijing/mhc/:caty', require('./routes/gov/beijing/mhc'));
// 小黑盒 // 小黑盒
router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user')); router.get('/xiaoheihe/user/:id', require('./routes/xiaoheihe/user'));
router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news')); router.get('/xiaoheihe/news', require('./routes/xiaoheihe/news'));
router.get('/xiaoheihe/discount', require('./routes/xiaoheihe/discount')); router.get('/xiaoheihe/discount/:platform?', require('./routes/xiaoheihe/discount'));
// 惠誉评级 // 惠誉评级
router.get('/fitchratings/site/:type', require('./routes/fitchratings/site')); router.get('/fitchratings/site/:type', require('./routes/fitchratings/site'));

View File

@@ -1,22 +1,70 @@
const got = require('@/utils/got'); const got = require('@/utils/got');
module.exports = async (ctx) => { module.exports = async (ctx) => {
const platform = ctx.params.platform || 'pc';
const response = await got({ const response = await got({
method: 'get', method: 'get',
url: 'https://api.xiaoheihe.cn/game/get_game_list_v3?sort_type=discount&limit=20&os_type=web', url: `https://api.xiaoheihe.cn/game/get_game_list_v3?sort_type=discount&filter_head=${platform}&offset=0&limit=30&os_type=web`,
}); });
const data = response.data.result.games; const data = response.data.result.games;
ctx.state.data = { ctx.state.data = {
title: '小黑盒 Steam 热门折扣', title: `小黑盒${platform.toUpperCase()}游戏折扣`,
link: 'https://xiaoheihe.cn/games/index', link: 'https://xiaoheihe.cn/games/index',
item: data.map((item) => ({ item: data.map((item) => {
title: (item.price.discount === item.price.lowest_discount ? '[史低] ' : '') + item.name + (item.name_en ? ' / ' + item.name_en : ''), const title = `${item.name}${item.name_en ? '/' + item.name_en : ''}`;
description: let description = `
`<img src="https://steamcdn-a.akamaihd.net/steam/apps/${item.appid}/header.jpg"> <br>` + <img src="${item.image}"/> <br/>
(item.heybox_price ? ` 小黑盒: 原价¥${item.heybox_price.original_coin / 1000},现价¥${item.heybox_price.cost_coin / 1000},折扣力度 ${item.heybox_price.discount}% <br> ` : '') + `;
`steam: 原价¥${item.price.initial},现价¥${item.price.current},折扣力度 ${item.price.discount}% ${item.price.deadline_date}`, if (item.platform_infos) {
link: `https://store.steampowered.com/app/${item.appid}/?l=zh&cc=cn`, item.platform_infos.forEach((platform) => {
})), if (platform.price) {
if (platform.key) {
description += `平台: ${platform.key}<br/>>`;
}
if (platform.price.current) {
description += `当前价格: ${platform.price.current}${platform.price.discount === platform.price.lowest_discount ? '[史低]' : ''}<br/>`;
}
if (platform.price.initial) {
description += `原价: ${platform.price.initial}<br/>`;
}
if (platform.price.discount_desc) {
description += `折扣力度: ${platform.price.discount_desc}<br/>`;
}
if (platform.price.deadline_date) {
description += `截止时间: ${platform.price.deadline_date}<br/>`;
}
description += '<br/>';
}
});
} else {
if (item.price) {
description += `平台: ${platform.toUpperCase()}<br/>`;
if (item.price.current) {
description += `当前价格: ${item.price.current}${item.price.discount === item.price.lowest_discount ? '[史低]' : ''}<br/>`;
}
if (item.price.initial) {
description += `原价: ${item.price.initial}<br/>`;
}
if (item.price.discount_desc) {
description += `折扣力度: ${item.price.discount_desc}<br/>`;
}
if (item.price.deadline_date) {
description += `截止时间: ${item.price.deadline_date}<br/>`;
}
description += '<br/>';
}
}
let link = `https://xiaoheihe.cn/games/detail/${item.steam_appid}`;
if (platform === 'pc') {
link = `https://store.steampowered.com/app/${item.steam_appid}`;
}
return {
title,
description,
link,
};
}),
}; };
}; };