45 lines
1.7 KiB
TypeScript
45 lines
1.7 KiB
TypeScript
import { ApiCall } from "tsrpc";
|
|
import { HuoDongFun } from "../../../public/huodongfun";
|
|
import { ReqCanReceive, ResCanReceive } from '../../../shared/protocols/event/payForDiamond/PtlCanReceive';
|
|
import { PublicShared } from "../../../shared/public/public";
|
|
|
|
export async function playerCanReceive(call: ApiCall) {
|
|
const activityInfo = await HuoDongFun.getHdidInfo(call, call.req.activityId);
|
|
if (!activityInfo) {
|
|
return call.error('No such activity');
|
|
}
|
|
const remaining = activityInfo.data['remaining'];
|
|
const zeroTime = PublicShared.getToDayZeroTime();
|
|
const dayPayInfo = await G.mongodb.collection('dayPay').findOne({ uid: call.uid, time: zeroTime });
|
|
if (!dayPayInfo || !dayPayInfo.payNum) {
|
|
return {
|
|
payNum: 0, remaining, result: false, activityInfo
|
|
};
|
|
}
|
|
const payNum = dayPayInfo.payNum;
|
|
// 玩家充值未达标或者奖池余额耗尽则不能领取
|
|
if (payNum < activityInfo.data['price'] || remaining <= 0) {
|
|
return {
|
|
payNum, remaining, result: false, activityInfo
|
|
}
|
|
}
|
|
// 检查玩家今日是否已经领取
|
|
const playerActivityInfo = G.mongodb.cEvent('payForDiamond').findOne({ uid: call.uid });
|
|
if (playerActivityInfo) {
|
|
if (playerActivityInfo[zeroTime]?.length) {
|
|
return {
|
|
payNum, remaining, result: false, activityInfo
|
|
};
|
|
}
|
|
}
|
|
return {
|
|
payNum, remaining, result: true, activityInfo
|
|
};
|
|
}
|
|
|
|
export default async function (call: ApiCall<ReqCanReceive, ResCanReceive>) {
|
|
const canReceiveResult = await playerCanReceive(call);
|
|
if (canReceiveResult) {
|
|
call.succ(canReceiveResult);
|
|
}
|
|
} |