后台:礼包码
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Application, BackendSession, HandlerService, } from "pinus";
|
||||
import { STATUS, CONSUME_TYPE, DEBUG_MAGIC_WORD } from "../../../consts";
|
||||
import { STATUS, CONSUME_TYPE, DEBUG_MAGIC_WORD, GIFT_GENERATE_TYPE } from "../../../consts";
|
||||
import { RewardInter } from "../../../pubUtils/interface";
|
||||
|
||||
import { resResult } from "../../../pubUtils/util";
|
||||
@@ -12,7 +12,7 @@ import { getAp, setAp, setApBuyTimes } from "../../../services/actionPointServic
|
||||
import { ActionPointModel } from "../../../db/ActionPoint";
|
||||
import { GiftCodeDetailModel } from "../../../db/GiftCodeDetail";
|
||||
import { GiftCodeType, GiftCodeModel } from "../../../db/GiftCode";
|
||||
import UserGiftCode, { UserGiftCodeModel } from "../../../db/UserGiftCode";
|
||||
import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
|
||||
export default function (app: Application) {
|
||||
new HandlerService(app, {});
|
||||
@@ -140,6 +140,7 @@ export class ItemHandler {
|
||||
public async useGiftCode(msg: { code: string }, session: BackendSession) {
|
||||
const roleId: string = session.get('roleId');
|
||||
const roleName: string = session.get('roleName');
|
||||
const serverId: number = session.get('serverId');
|
||||
const sid: string = session.get('sid');
|
||||
const { code } = msg;
|
||||
|
||||
@@ -147,24 +148,20 @@ export class ItemHandler {
|
||||
if(!giftCodeDetail) {
|
||||
return resResult(STATUS.GIFT_CODE_NOT_FOUND);
|
||||
}
|
||||
let giftCode = <GiftCodeType>giftCodeDetail.giftCode;
|
||||
let giftCode = await GiftCodeModel.findByGiftId(giftCodeDetail.giftId);
|
||||
if(!giftCode) {
|
||||
return resResult(STATUS.GIFT_CODE_NOT_FOUND);
|
||||
}
|
||||
|
||||
if(!giftCode.isEnable) return resResult(STATUS.GIFT_CODE_HAS_EXPIRED);
|
||||
if (giftCode.beginTime > nowSeconds()) return resResult(STATUS.GIFT_CODE_NOT_START);
|
||||
if (giftCode.endTime < nowSeconds()) return resResult(STATUS.GIFT_CODE_HAS_EXPIRED);
|
||||
|
||||
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) {
|
||||
if (giftCodeDetail.roleIds.indexOf(roleId) != -1) {
|
||||
return resResult(STATUS.YOU_HAVE_USED_THIS_CODE);
|
||||
}
|
||||
|
||||
await UserGiftCode.createCode(roleId, code, giftCode);
|
||||
await GiftCodeDetailModel.increaseUsedNum(code);
|
||||
await GiftCodeDetailModel.increaseUsedNum(code, roleId, roleName, serverId);
|
||||
await GiftCodeModel.increaseUsedNum(giftCode.id);
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, giftCode.goods);
|
||||
|
||||
Reference in New Issue
Block a user