From 96675a9ff186143b27d8d4dac20c8ca4e3d57a1a Mon Sep 17 00:00:00 2001 From: dy Date: Sun, 31 Dec 2023 09:48:26 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B4=AF=E8=AE=A1=E5=85=85=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/leijichongzhi/ApiOpen.ts | 5 +++- src/api_s2c/event/leijichongzhi/ApiRec.ts | 28 ++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/src/api_s2c/event/leijichongzhi/ApiOpen.ts b/src/api_s2c/event/leijichongzhi/ApiOpen.ts index 694a5bd..ec12bf4 100644 --- a/src/api_s2c/event/leijichongzhi/ApiOpen.ts +++ b/src/api_s2c/event/leijichongzhi/ApiOpen.ts @@ -3,6 +3,7 @@ import {HuoDongFun} from "../../../public/huodongfun"; import {PayFun} from '../../../public/pay'; import {ReqOpen, ResOpen} from "../../../shared/protocols/event/leijichongzhi/PtlOpen"; import {PublicShared} from '../../../shared/public/public'; +import {checkNextRound} from "./ApiRec"; export default async function (call: ApiCall) { let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid) @@ -22,8 +23,10 @@ export default async function (call: ApiCall) { {upsert: true} ); } + db = await checkNextRound(call, db, _hdinfo.data.tasks) + let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime)) * 10 - payNum = payNum - (db.round || 0) * R.compose(R.sum(), R.map(i => i.total))(_hdinfo.data.tasks) + payNum = payNum - (db.round || 0) * R.sort((a, b) => b.total - a.total)(_hdinfo.data.tasks)[0].total call.succ({ sTime: sTime, diff --git a/src/api_s2c/event/leijichongzhi/ApiRec.ts b/src/api_s2c/event/leijichongzhi/ApiRec.ts index 103cff5..e076e7c 100644 --- a/src/api_s2c/event/leijichongzhi/ApiRec.ts +++ b/src/api_s2c/event/leijichongzhi/ApiRec.ts @@ -21,25 +21,29 @@ export default async function (call: ApiCall) { if (db.recIndex.includes(call.req.index)) return call.error('', {code: -2}); let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime)) * 10; - payNum = payNum - (db.round || 0) * R.compose(R.sum(), R.map(i => i.total))(_hdinfo.data.tasks) + payNum = payNum - (db.round || 0) * R.sort((a, b) => b.total - a.total)(_hdinfo.data.tasks)[0].total if (payNum < conf.total) return call.error('', {code: -3}); await PlayerFun.sendPrize(call, conf.prize); - if (db.recIndex.length + 1 >= _hdinfo.data.tasks.length) { - await G.mongodb.cEvent(_dbType).updateOne( - {uid: call.uid, type: _dbType}, - {$set: {recIndex: []}, $inc: {round: 1}} - ); - } else { - await G.mongodb.cEvent(_dbType).updateOne( - {uid: call.uid, type: _dbType}, - {$push: {recIndex: call.req.index}} - ); - } + await G.mongodb.cEvent(_dbType).updateOne( + {uid: call.uid, type: _dbType}, + {$push: {recIndex: call.req.index}} + ); + + await checkNextRound(call, db, _hdinfo.data.tasks) HongDianChange.sendChangeKey(call.uid, ['huodonghd']) call.succ({ prize: conf.prize }); +} + +export async function checkNextRound(call: ApiCall, event, tasks) { + let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}` + if ((event.recIndex.length || 0) < tasks.length) return event + return (await G.mongodb.cEvent(_dbType).findOneAndUpdate( + {uid: call.uid, type: _dbType}, + {$set: {recIndex: []}, $inc: {round: 1}}, {returnDocument: 'after'} + )).value; } \ No newline at end of file