From 6fd4e79fbe5b6aea53fd5ccff82efb1ccb84574f Mon Sep 17 00:00:00 2001 From: dy Date: Sat, 30 Dec 2023 16:32: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 | 27 +++++++------ src/api_s2c/event/leijichongzhi/ApiRec.ts | 38 +++++++++++-------- .../protocols/event/leijichongzhi/PtlOpen.ts | 2 + src/shared/protocols/serviceProto.ts | 7 ++++ 4 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/api_s2c/event/leijichongzhi/ApiOpen.ts b/src/api_s2c/event/leijichongzhi/ApiOpen.ts index 9d3779f..694a5bd 100644 --- a/src/api_s2c/event/leijichongzhi/ApiOpen.ts +++ b/src/api_s2c/event/leijichongzhi/ApiOpen.ts @@ -1,32 +1,35 @@ -import { ApiCall } from "tsrpc"; -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 {ApiCall} from "tsrpc"; +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'; export default async function (call: ApiCall) { let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid) if (!_hdinfo || Object.keys(_hdinfo).length <= 0) { // 无此活动 - return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 }) + return call.error('', {code: -1, message: globalThis.lng.huodong_open_1}) } let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}` - let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }); + let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType}); let sTime = db?.sTime || PublicShared.getToDayZeroTime(G.time); if (!db) { G.mongodb.cEvent(_dbType).updateOne( - { uid: call.uid, type: _dbType }, - { $set: { sTime: sTime, recIndex: [] } }, - { upsert: true } + {uid: call.uid, type: _dbType}, + {$set: {sTime: sTime, recIndex: []}}, + {upsert: true} ); } + 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) call.succ({ sTime: sTime, recIndex: db?.recIndex || [], - payNum: (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime)) * 10, - hdinfo: _hdinfo + payNum: payNum, + hdinfo: _hdinfo, + round: db.round || 0 }); } \ No newline at end of file diff --git a/src/api_s2c/event/leijichongzhi/ApiRec.ts b/src/api_s2c/event/leijichongzhi/ApiRec.ts index 39d27ee..103cff5 100644 --- a/src/api_s2c/event/leijichongzhi/ApiRec.ts +++ b/src/api_s2c/event/leijichongzhi/ApiRec.ts @@ -1,34 +1,42 @@ -import { ApiCall } from "tsrpc"; -import { HuoDongFun } from "../../../public/huodongfun"; -import { PayFun } from '../../../public/pay'; -import { PlayerFun } from '../../../public/player'; -import { ReqRec, ResRec } from "../../../shared/protocols/event/leijichongzhi/PtlRec"; -import { HongDianChange } from "../../hongdian/fun"; +import {ApiCall} from "tsrpc"; +import {HuoDongFun} from "../../../public/huodongfun"; +import {PayFun} from '../../../public/pay'; +import {PlayerFun} from '../../../public/player'; +import {ReqRec, ResRec} from "../../../shared/protocols/event/leijichongzhi/PtlRec"; +import {HongDianChange} from "../../hongdian/fun"; export default async function (call: ApiCall) { let _hdinfo = await HuoDongFun.getHdidInfo(call, call.req.hdid) if (!_hdinfo || Object.keys(_hdinfo).length <= 0) { // 无此活动 - return call.error('', { code: -1, message: globalThis.lng.huodong_open_1 }) + return call.error('', {code: -1, message: globalThis.lng.huodong_open_1}) } let _dbType: `leijichongzhi${number}` = `leijichongzhi${call.req.hdid}` let conf = _hdinfo.data.tasks[call.req.index]; - if (!conf) return call.error('', { code: -1 }); + if (!conf) return call.error('', {code: -1}); - let db = await G.mongodb.cEvent(_dbType).findOne({ uid: call.uid, type: _dbType }); - if (db.recIndex.includes(call.req.index)) return call.error('', { code: -2 }); + let db = await G.mongodb.cEvent(_dbType).findOne({uid: call.uid, type: _dbType}); + if (db.recIndex.includes(call.req.index)) return call.error('', {code: -2}); let payNum = (await PayFun.getPayDaysAllPayNum(call.uid, _hdinfo.stime, _hdinfo.rtime)) * 10; - if (payNum < conf.total) return call.error('', { code: -3 }); + payNum = payNum - (db.round || 0) * R.compose(R.sum(), R.map(i => i.total))(_hdinfo.data.tasks) + if (payNum < conf.total) return call.error('', {code: -3}); await PlayerFun.sendPrize(call, conf.prize); - G.mongodb.cEvent(_dbType).updateOne( - { uid: call.uid, type: _dbType }, - { $push: { recIndex: call.req.index } } - ); + 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}} + ); + } HongDianChange.sendChangeKey(call.uid, ['huodonghd']) call.succ({ diff --git a/src/shared/protocols/event/leijichongzhi/PtlOpen.ts b/src/shared/protocols/event/leijichongzhi/PtlOpen.ts index e61167b..9c2d03c 100644 --- a/src/shared/protocols/event/leijichongzhi/PtlOpen.ts +++ b/src/shared/protocols/event/leijichongzhi/PtlOpen.ts @@ -16,4 +16,6 @@ export type ResOpen = { payNum: number; /**活动信息 */ hdinfo: ReqAddHuoDong; + /** 当前领取轮次 */ + round: number }; \ No newline at end of file diff --git a/src/shared/protocols/serviceProto.ts b/src/shared/protocols/serviceProto.ts index 57b3262..bd8c93d 100644 --- a/src/shared/protocols/serviceProto.ts +++ b/src/shared/protocols/serviceProto.ts @@ -10263,6 +10263,13 @@ export const serviceProto: ServiceProto = { "type": "Reference", "target": "../../monopoly/protocols/PtlAddHuoDong/ReqAddHuoDong" } + }, + { + "id": 4, + "name": "round", + "type": { + "type": "Number" + } } ] },