HJ_Server/src/api_s2c/event/yuandan/ApiDMRec.ts
2023-12-26 17:33:48 +08:00

36 lines
1.3 KiB
TypeScript

import {ApiCall} from "tsrpc";
import {ReqDMRec, ResDMRec} from "../../../shared/protocols/event/yuandan/PtlDMRec";
import {HuoDongFun} from "../../../public/huodongfun";
import {PlayerFun} from "../../../public/player";
import {HongDianChange} from "../../hongdian/fun";
export default async function (call: ApiCall<ReqDMRec, ResDMRec>) {
// 查询活动是否存在
let _hd = (await HuoDongFun.gethdList(call, 14))[0]
if (!_hd) return call.errorCode(-1)
// 奖励不符合
let toPrize = call.req.prize
let prize = _hd.data.game.find(i => i.a == toPrize.a && i.t == toPrize.t && i.n == toPrize.n)
if (toPrize && !prize) return call.errorCode(-4)
// 扣除免费次数或相应货币
let data = await G.mongodb.cEvent(`yuandan${_hd.hdid}`).findOne({uid: call.uid, type: `yuandan${_hd.hdid}`})
let rec = data?.gameNum
if (rec && rec >= _hd.data?.gamefree) {
await PlayerFun.checkNeedIsMeet(call, _hd.data.gameneed);
await PlayerFun.cutNeed(call, _hd.data.gameneed);
}
await PlayerFun.sendPrize(call, prize ? [prize] : []);
await G.mongodb.cEvent(`yuandan${_hd.hdid}`).updateOne({uid: call.uid, type: `yuandan${_hd.hdid}`}, {
$inc: {[`gameNum`]: 1},
}, {upsert: true})
call.succ({})
HongDianChange.sendChangeKey(call.uid, ['yuandan']);
}