From fd3c13d2b5c43c94ba65ba1a7e0d9ab3b24f489b Mon Sep 17 00:00:00 2001 From: dy Date: Wed, 20 Dec 2023 20:05:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E8=80=97=E7=AB=9E=E8=B5=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/xiaofeijingsai/ApiOpen.ts | 27 ++++++-- .../protocols/event/xiaofeijingsai/PtlOpen.ts | 7 +- src/shared/protocols/serviceProto.ts | 66 ++++++++++++++++++- 3 files changed, 92 insertions(+), 8 deletions(-) diff --git a/src/api_s2c/event/xiaofeijingsai/ApiOpen.ts b/src/api_s2c/event/xiaofeijingsai/ApiOpen.ts index b60d885..8eb9645 100644 --- a/src/api_s2c/event/xiaofeijingsai/ApiOpen.ts +++ b/src/api_s2c/event/xiaofeijingsai/ApiOpen.ts @@ -13,13 +13,14 @@ import {PublicShared} from "../../../shared/public/public"; export default async function (call: ApiCall) { let ioList = await G.ioredis.get(`rank:xiaofeijingsai`); if (ioList) { - return call.succ({list: JSON.parse(ioList)}) + let myData = await getMyData(call, JSON.parse(ioList)) + return call.succ({list: JSON.parse(ioList), myData}) } let _hd = (await HuoDongFun.gethdList(call, 11))[0] if (!_hd) return call.errorCode(-1) - let limit = _hd.data?.rank?.slice(-1)?.[0]?.rank?.slice(-1)?.[0] || 50 + let limit = call.req.limit || 50 let rmbuse = await G.mongodb.collection('rmbuse').aggregate([ {$match: {isAdd: false, cTime: {$gte: _hd.stime, $lte: _hd.etime}}}, @@ -35,9 +36,27 @@ export default async function (call: ApiCall) { list = list.map(i => ({...i, player: users.find(v => v.uid == i._id)})) // 活动结束前半小时,缓存过期时间改为10秒 - let exTime = (G.time + 1800) < _hd.etime ? 10 : 180 + let exTime = (G.time + 1800) > _hd.etime ? 10 : 180 G.ioredis.setex(`rank:xiaofeijingsai`, exTime, JSON.stringify(list)); - call.succ({list}) + let myData = await getMyData(call, list, _hd) + + call.succ({list, myData}) +} + +// 获取自己的信息 +async function getMyData(call, rankList, _hd?) { + let myData = rankList.find(i => i._id == call.uid) + if (myData) return myData + + if (!_hd) { + _hd = (await HuoDongFun.gethdList(call, 11))[0] + } + let a = await G.mongodb.collection('rmbuse').aggregate([ + {$match: {uid: call.uid, isAdd: false, cTime: {$gte: _hd.stime, $lte: _hd.etime}}}, + {$group: {_id: "$uid", total: {$sum: "$change"}}} + ]).toArray() + let myUser = await G.mongodb.collection('user').findOne({uid: call.uid}) + return {player: myUser, ...a} } \ No newline at end of file diff --git a/src/shared/protocols/event/xiaofeijingsai/PtlOpen.ts b/src/shared/protocols/event/xiaofeijingsai/PtlOpen.ts index 5145ee7..cf5b512 100644 --- a/src/shared/protocols/event/xiaofeijingsai/PtlOpen.ts +++ b/src/shared/protocols/event/xiaofeijingsai/PtlOpen.ts @@ -1,8 +1,11 @@ /** * 消费竞赛 */ -export type ReqOpen = {}; +export type ReqOpen = { + limit: number +}; export type ResOpen = { - list: any[] + list: { _id: string, total: number, player: any }[] + myData: { _id: string, total: number, player: any } }; \ No newline at end of file diff --git a/src/shared/protocols/serviceProto.ts b/src/shared/protocols/serviceProto.ts index 4bb9ce9..1f614dd 100644 --- a/src/shared/protocols/serviceProto.ts +++ b/src/shared/protocols/serviceProto.ts @@ -10534,7 +10534,16 @@ export const serviceProto: ServiceProto = { ] }, "event/xiaofeijingsai/PtlOpen/ReqOpen": { - "type": "Interface" + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "limit", + "type": { + "type": "Number" + } + } + ] }, "event/xiaofeijingsai/PtlOpen/ResOpen": { "type": "Interface", @@ -10545,9 +10554,62 @@ export const serviceProto: ServiceProto = { "type": { "type": "Array", "elementType": { - "type": "Any" + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "_id", + "type": { + "type": "String" + } + }, + { + "id": 1, + "name": "total", + "type": { + "type": "Number" + } + }, + { + "id": 2, + "name": "player", + "type": { + "type": "Any" + } + } + ] } } + }, + { + "id": 1, + "name": "myData", + "type": { + "type": "Interface", + "properties": [ + { + "id": 0, + "name": "_id", + "type": { + "type": "String" + } + }, + { + "id": 1, + "name": "total", + "type": { + "type": "Number" + } + }, + { + "id": 2, + "name": "player", + "type": { + "type": "Any" + } + } + ] + } } ] },