HJ_Server/src/api_s2c/conglinshoulie/ApiBuyNum.ts
DESKTOP-15R5JU0\legu 97e070ea81 init
2023-11-17 12:02:12 +08:00

24 lines
871 B
TypeScript

import { ApiCall } from "tsrpc";
import { PlayerFun } from '../../public/player';
import { ReqBuyNum, ResBuyNum } from "../../shared/protocols/conglinshoulie/PtlBuyNum";
import { HongDianChange } from "../hongdian/fun";
import { clslDb } from './ApiOpen';
export default async function (call: ApiCall<ReqBuyNum, ResBuyNum>) {
let db = await clslDb().findOne({ uid: call.uid, type: 'clsl' });
let buyNum = db?.buyFightNum || 0;
let hasNum = G.gc.clsl_com.vipBuyFightNum[call.conn.gud.vip];
if (buyNum >= hasNum) return call.errorCode(-1);
let _need = [G.gc.clsl_com.buyFightNumNeed[buyNum]]
await PlayerFun.checkNeedIsMeet(call, _need);
await PlayerFun.cutNeed(call, _need);
clslDb().updateOne({ uid: call.uid, type: 'clsl' }, { $inc: { buyFightNum: 1 } });
HongDianChange.sendChangeKey(call.uid, ['clslhd'])
call.succ({});
}