Merge branch 'feature/pay_for_diamond' into dev
This commit is contained in:
commit
093de3350f
@ -8,19 +8,20 @@ export async function playerCanReceive(call: ApiCall) {
|
||||
if (!activityInfo) {
|
||||
return call.error('No such activity');
|
||||
}
|
||||
const remaining = typeof activityInfo.data['remaining'] === 'number'? activityInfo.data['remaining'] : activityInfo.data['totalmoney'];
|
||||
const remaining = activityInfo.data['totalmoney'];
|
||||
const showOffList = activityInfo.data['showOffList'] || [];
|
||||
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
|
||||
payNum: 0, remaining, result: false, activityInfo, showOffList
|
||||
};
|
||||
}
|
||||
const payNum = dayPayInfo.payNum;
|
||||
// 玩家充值未达标或者奖池余额耗尽则不能领取
|
||||
if (payNum < activityInfo.data['price'] || remaining <= 0) {
|
||||
return {
|
||||
payNum, remaining, result: false, activityInfo
|
||||
payNum, remaining, result: false, activityInfo, showOffList
|
||||
}
|
||||
}
|
||||
// 检查玩家今日是否已经领取
|
||||
@ -28,18 +29,19 @@ export async function playerCanReceive(call: ApiCall) {
|
||||
if (playerActivityInfo) {
|
||||
if (playerActivityInfo[zeroTime]?.length) {
|
||||
return {
|
||||
payNum, remaining, result: false, activityInfo
|
||||
payNum, remaining, result: false, activityInfo, showOffList
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
payNum, remaining, result: true, activityInfo
|
||||
payNum, remaining, result: true, activityInfo, showOffList
|
||||
};
|
||||
}
|
||||
|
||||
export default async function (call: ApiCall<ReqCanReceive, ResCanReceive>) {
|
||||
const canReceiveResult = await playerCanReceive(call);
|
||||
if (canReceiveResult) {
|
||||
call.succ(canReceiveResult);
|
||||
const { payNum, remaining, result, showOffList } = canReceiveResult;
|
||||
call.succ({ payNum, remaining, result, showOffList });
|
||||
}
|
||||
}
|
@ -62,31 +62,31 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
|
||||
if (!canReceiveResult.result) {
|
||||
return call.succ({
|
||||
amount: 0,
|
||||
timesRemaining: 0
|
||||
timesRemaining: 0,
|
||||
showOff: false
|
||||
});
|
||||
}
|
||||
const activityData = canReceiveResult.activityInfo.data;
|
||||
const remaining = typeof activityData['remaining'] === 'number'? activityData['remaining'] : activityData['totalmoney'];
|
||||
const remaining = activityData['totalmoney'];
|
||||
const { group, maxAmount } = randomWithWeight(activityData['groupConf']['base']['arr']);
|
||||
const gotAmount = calcDiamondGot(remaining, group, maxAmount);
|
||||
// 减去余额
|
||||
const filter = {
|
||||
hdid: call.req.activityId,
|
||||
$or: [
|
||||
{'data.remaining': { $exists: false }},
|
||||
{$expr: {$gte: [ `$data.remaining - ${gotAmount}`, 0 ]}},
|
||||
],
|
||||
$expr: {$gte: [ `$data.totalmoney - ${gotAmount}`, 0 ]},
|
||||
};
|
||||
const updateDoc = {
|
||||
$set: { 'data.remaining': `$data.remaining - ${gotAmount}` }
|
||||
$inc: { 'data.totalmoney': -1 * Math.abs(gotAmount) }
|
||||
}
|
||||
const updateResult = await G.mongodb.collection('hdinfo').updateOne(filter, updateDoc);
|
||||
// 更新成功
|
||||
if (updateResult.modifiedCount) {
|
||||
const showOff = gotAmount >= activityData['groupConf']['base']['loglimit'];
|
||||
// 请求返回
|
||||
call.succ({
|
||||
amount: gotAmount,
|
||||
timesRemaining: 0
|
||||
timesRemaining: 0,
|
||||
showOff,
|
||||
});
|
||||
// 添加玩家领取记录
|
||||
const zeroTime = PublicShared.getToDayZeroTime();
|
||||
@ -95,19 +95,11 @@ export default async function (call: ApiCall<ReqReceive, ResReceive>) {
|
||||
G.mongodb.cEvent('payForDiamond').updateOne({ uid: call.uid }, {
|
||||
$set: setObj
|
||||
});
|
||||
// 记录玩家日志. 仅保留最近 10 条
|
||||
if (showOff) {
|
||||
G.mongodb.collection('hdinfo').updateOne({ hdid: call.req.activityId, }, { $push: { 'data.showOffList': { $each: [{ name: call.conn.gud.name, gotAmount }], $slice: -10 }}});
|
||||
}
|
||||
}
|
||||
// 发送炫耀
|
||||
if (gotAmount >= activityData['groupConf']['base']['loglimit']) {
|
||||
ChatFun.newMsg({
|
||||
type: 'local',
|
||||
msg: G.gc.pmd.get_hero_star5_pmd,
|
||||
time: G.time,
|
||||
sender: 'system',
|
||||
otherData: {
|
||||
pmd: true,
|
||||
args: [gotAmount]
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -6,4 +6,5 @@ export type ResCanReceive = {
|
||||
payNum: number;
|
||||
remaining?: number;
|
||||
result: boolean;
|
||||
showOffList: any[];
|
||||
};
|
@ -5,4 +5,5 @@ export type ReqReceive = {
|
||||
export type ResReceive = {
|
||||
amount: number,
|
||||
timesRemaining: number;
|
||||
showOff: boolean;
|
||||
};
|
||||
|
@ -10234,6 +10234,16 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"type": {
|
||||
"type": "Boolean"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"name": "showOffList",
|
||||
"type": {
|
||||
"type": "Array",
|
||||
"elementType": {
|
||||
"type": "Any"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
@ -10265,6 +10275,13 @@ export const serviceProto: ServiceProto<ServiceType> = {
|
||||
"type": {
|
||||
"type": "Number"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"name": "showOff",
|
||||
"type": {
|
||||
"type": "Boolean"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
Loading…
Reference in New Issue
Block a user