后台:礼包码
This commit is contained in:
@@ -19,6 +19,9 @@ import { checkTaskWithHero, checkTaskWithEquip, checkTask, checkTaskWithArgs, ch
|
||||
import { useGiftPackage } from "../../../services/activity/giftPackageService";
|
||||
import { getAp, setAp, setApBuyTimes } from "../../../services/actionPointService";
|
||||
import { ActionPointModel } from "../../../db/ActionPoint";
|
||||
import { GiftCodeDetailModel } from "../../../db/GiftCodeDetail";
|
||||
import { GiftCodeType, GiftCodeModel } from "../../../db/GiftCode";
|
||||
import UserGiftCode, { UserGiftCodeModel } from "../../../db/UserGiftCode";
|
||||
|
||||
export default function (app: Application) {
|
||||
return new ItemHandler(app);
|
||||
@@ -141,6 +144,35 @@ export class ItemHandler {
|
||||
});
|
||||
}
|
||||
|
||||
// 兑换礼包码
|
||||
public async useGiftCode(msg: { code: string }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const sid: string = session.get('sid');
|
||||
const { code } = msg;
|
||||
|
||||
let giftCodeDetail = await GiftCodeDetailModel.findByCode(code);
|
||||
let giftCode = <GiftCodeType>giftCodeDetail.giftCode;
|
||||
|
||||
if(giftCode.isLimit && giftCodeDetail.usedNum >= giftCode.count) {
|
||||
return resResult(STATUS.GIFT_CODE_USED_NUM_MAX);
|
||||
}
|
||||
if(giftCode.beginTime > new Date()) return resResult(STATUS.GIFT_CODE_NOT_START);
|
||||
if(giftCode.endTime < new Date()) return resResult(STATUS.GIFT_CODE_HAS_EXPIRED);
|
||||
|
||||
let userGiftCode = await UserGiftCodeModel.findByCode(roleId, code);
|
||||
if(userGiftCode) {
|
||||
return resResult(STATUS.YOU_HAVE_USED_THIS_CODE);
|
||||
}
|
||||
|
||||
await UserGiftCode.createCode(roleId, code, giftCode);
|
||||
await GiftCodeDetailModel.increaseUsedNum(code);
|
||||
await GiftCodeModel.increaseUsedNum(giftCode.id);
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, giftCode.goods);
|
||||
return resResult(STATUS.SUCCESS, { goods });
|
||||
}
|
||||
|
||||
public async debugIncAp(msg: { magicWord: string, ap: number }, session: BackendSession) {
|
||||
const { magicWord } = msg;
|
||||
if (magicWord !== DEBUG_MAGIC_WORD) {
|
||||
|
||||
Reference in New Issue
Block a user