From 8ec4a46837155b26b99113597d6f1657a84edcce Mon Sep 17 00:00:00 2001 From: xichaoyin Date: Thu, 4 Jan 2024 21:36:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E7=A4=BC=E5=8C=85?= =?UTF-8?q?=E5=9C=A8=E6=9C=80=E5=90=8E=E4=B8=80=E5=A4=A9=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=80=E9=94=AE=E9=A2=86=E5=8F=96=E6=89=80=E6=9C=89=E5=A5=96?= =?UTF-8?q?=E5=8A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api_s2c/event/pobinglibao/ApiReceive.ts | 104 ++++++++++++++------ 1 file changed, 75 insertions(+), 29 deletions(-) diff --git a/src/api_s2c/event/pobinglibao/ApiReceive.ts b/src/api_s2c/event/pobinglibao/ApiReceive.ts index c97f0da..a37404f 100644 --- a/src/api_s2c/event/pobinglibao/ApiReceive.ts +++ b/src/api_s2c/event/pobinglibao/ApiReceive.ts @@ -1,42 +1,88 @@ -import {ApiCall} from "tsrpc"; -import {ReqReceive, ResReceive} from "../../../shared/protocols/event/pobinglibao/PtlReceive"; -import {HuoDongFun} from "../../../public/huodongfun"; -import {PlayerFun} from "../../../public/player"; -import {HongDianChange} from "../../hongdian/fun"; -import {PayFun} from "../../../public/pay"; -import {PublicShared} from "../../../shared/public/public"; +import { ApiCall } from "tsrpc"; +import { ReqReceive, ResReceive } from "../../../shared/protocols/event/pobinglibao/PtlReceive"; +import { HuoDongFun } from "../../../public/huodongfun"; +import { PlayerFun } from "../../../public/player"; +import { HongDianChange } from "../../hongdian/fun"; +import { PayFun } from "../../../public/pay"; +import { PublicShared } from "../../../shared/public/public"; export default async function (call: ApiCall) { // 查询活动是否是可领取状态 let _hd = (await HuoDongFun.gethdList(call, 10))[0] - let gift = _hd?.data?.gift?.find(i => i.id == call.req.id) - if (!gift || !call.req.recId) return call.errorCode(-1) - // 查询购买状态 - let payLog = await PayFun.getPayLog(call.uid, gift.payId) - payLog = payLog?.filter(i => i.time >= _hd.stime && i.time <= _hd.etime) || [] - if (!payLog || !payLog.length) return call.errorCode(-2) + let prize = []; + let update = {}; + // 判断活动是否是最后一天 + if (PublicShared.chkSameDate(G.time, _hd.etime)) { + let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne( + { uid: call.uid, type: `pobinglibao${_hd.hdid}` } + ); - /** - * 取奖励列表,判断是否有可领取奖励 - * 购买日起,每种礼包每天可领一次礼包,每种类型独立 - * 活动结束前的最后一天,可领取所有奖励 - */ - let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne({uid: call.uid, type: `pobinglibao${_hd.hdid}`}) - let rec = data?.record?.[call.req.id]?.length - let _payDiff = PublicShared.getDiff(payLog[0].time) - _payDiff = _payDiff > 3 ? 3 : _payDiff - let _endDiff = PublicShared.getDiff(_hd.etime) - if ((rec >= _payDiff && _endDiff < 1) || data?.record?.[gift.id] == call.req.recId) return call.errorCode(-3) + for (let gift of _hd.data.gift) { + // 查询购买状态 + let push = []; + let payLog = await PayFun.getPayLog(call.uid, gift.payId) + payLog = payLog?.filter(i => i.time >= _hd.stime && i.time <= _hd.etime) || [] + if (!payLog || !payLog.length) continue; - await PlayerFun.sendPrize(call, gift[call.req.recId]); + for (let key of ["prize", "recPrize1", "recPrize2"]) { + if (data.record[gift.id] && data.record[gift.id].includes(key)) { + push.concat(key); + prize.concat(gift[key]); + } + } + if (push.length > 0) { + if (update["$push"]) { + update["$push"]["record." + gift.id] = { $each: push } + } else { + update["$push"] = { ["record." + gift.id]: { $each: push } } + } + } + } - await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).updateOne({uid: call.uid, type: `pobinglibao${_hd.hdid}`}, { - $push: {[`record.${gift.id}`]: call.req.recId}, - }, {upsert: true}) + if (!prize.length) { + return call.errorCode(-3) + } + } else { + let gift = _hd?.data?.gift?.find(i => i.id == call.req.id); + if (!gift || !call.req.recId) return call.errorCode(-1); - call.succ({prize: gift[call.req.recId]}) + // 查询购买状态 + let payLog = await PayFun.getPayLog(call.uid, gift.payId) + payLog = payLog?.filter(i => i.time >= _hd.stime && i.time <= _hd.etime) || [] + + if (!payLog || !payLog.length) return call.errorCode(-2); + + /** + * 取奖励列表,判断是否有可领取奖励 + * 购买日起,每种礼包每天可领一次礼包,每种类型独立 + * 活动结束前的最后一天,可领取所有奖励 + */ + let data = await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).findOne( + { uid: call.uid, type: `pobinglibao${_hd.hdid}` } + ) + + let rec = data?.record?.[call.req.id]?.length + + let _payDiff = PublicShared.getDiff(payLog[0].time) + _payDiff = _payDiff > 3 ? 3 : _payDiff + + if (rec >= _payDiff || data?.record?.[gift.id] == call.req.recId) return call.errorCode(-3) + + prize.concat(gift[call.req.recId]); + update = { + $push: { [`record.${gift.id}`]: call.req.recId }, + } + } + + await PlayerFun.sendPrize(call, prize); + + await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).updateOne( + { uid: call.uid, type: `pobinglibao${_hd.hdid}` }, update, { upsert: true } + ); + + call.succ({ prize: prize }); HongDianChange.sendChangeKey(call.uid, ['huodonghd']); }