feat(37需求): 礼包码的使用限制通过order_id判断

This commit is contained in:
luying
2023-04-10 10:38:40 +08:00
parent 2ce30ee807
commit 06c03ed709
3 changed files with 10 additions and 7 deletions

View File

@@ -799,4 +799,5 @@ export const SDK_37_ACTIVITY_CODE = {
GIFT_CHANNEL_ERR: { code: 20007, simStr: '礼包不可在此渠道使用' },
TIME_IS_EXPIRED: { code: 20008, simStr: '时间戳已过期' },
SERVER_NOT_FOUND: { code: 20009, simStr: '服务器未找到' },
GIFT_CODE_CANNOT_USE: { code: 20010, simStr: '该礼包码不可使用' },
}

View File

@@ -63,6 +63,12 @@ export default class GiftCodeDetail extends BaseModel {
return result;
}
public static async checkOrderHasUsed(id: number, orderId: string) {
let result = await GiftCodeDetailModel.exists({ giftId: id, 'record.orderId': orderId });
return result;
}
public static async findAllCodeByGiftId(id: number, cnt: number) {
let n = Math.ceil(cnt/1000);
let result: GiftCodeDetailType[] = [];

View File

@@ -454,8 +454,8 @@ export default class Sdk extends Service {
if(!giftCode) {
return resResult(SDK_37_ACTIVITY_CODE.GIFT_NOT_FOUND);
}
if(giftCode.generateType == GIFT_GENERATE_TYPE.ONE_TO_ONE) { // 一人一条,单条不能被多人使用
if(giftCodeDetail.usedNum > 0) return resResult(SDK_37_ACTIVITY_CODE.USE_CNT_MAX);
if(giftCode.generateType != GIFT_GENERATE_TYPE.ONE_TO_MANY) { // 一人一条,单条不能被多人使用
return resResult(SDK_37_ACTIVITY_CODE.GIFT_CODE_CANNOT_USE);
}
if(!giftCode.isEnable) return resResult(SDK_37_ACTIVITY_CODE.GIFT_CODE_HAS_EXPIRED);
if (giftCode.beginTime > nowSeconds()) return resResult(SDK_37_ACTIVITY_CODE.GIFT_CODE_NOT_START);
@@ -467,12 +467,8 @@ export default class Sdk extends Service {
let role = await RoleModel.findByUid(user.uid, params.server_id);
if(!role) return resResult(SDK_37_ACTIVITY_CODE.ROLE_NOT_FOUND);
if (giftCodeDetail.roleIds.indexOf(role.roleId) != -1) {
return resResult(SDK_37_ACTIVITY_CODE.ORDER_DUPLICATE);
}
let checkHasUse = await GiftCodeDetailModel.checkHasUsed(role.roleId, giftCodeDetail.giftId);
let checkHasUse = await GiftCodeDetailModel.checkOrderHasUsed(giftCodeDetail.giftId, params.order_id);
if(checkHasUse) {
return resResult(SDK_37_ACTIVITY_CODE.ORDER_DUPLICATE);
}