Merge branch 'bugfix' into dev

This commit is contained in:
xichaoyin 2024-01-04 21:37:11 +08:00
commit 77087741a7

View File

@ -10,33 +10,79 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
// 查询活动是否是可领取状态
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 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}` }
);
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;
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 } }
}
}
}
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);
// 查询购买状态
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)
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 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)
await PlayerFun.sendPrize(call, gift[call.req.recId]);
if (rec >= _payDiff || data?.record?.[gift.id] == call.req.recId) return call.errorCode(-3)
await G.mongodb.cEvent(`pobinglibao${_hd.hdid}`).updateOne({uid: call.uid, type: `pobinglibao${_hd.hdid}`}, {
prize.concat(gift[call.req.recId]);
update = {
$push: { [`record.${gift.id}`]: call.req.recId },
}, {upsert: true})
}
}
call.succ({prize: gift[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']);
}