✨ feat(db): 给GiftCodeDetail添加只读库
This commit is contained in:
@@ -10,7 +10,7 @@ import { ITID } from "../../../consts/constModules/itemConst";
|
||||
import { useGiftPackage } from "../../../services/activity/giftPackageService";
|
||||
import { getAp, setAp, setApBuyTimes } from "../../../services/actionPointService";
|
||||
import { ActionPointModel } from "../../../db/ActionPoint";
|
||||
import { GiftCodeDetailModel } from "../../../db/GiftCodeDetail";
|
||||
import GiftCodeDetail from "../../../db/GiftCodeDetail";
|
||||
import GiftCode from "../../../db/GiftCode";
|
||||
import { nowSeconds } from "../../../pubUtils/timeUtil";
|
||||
import { AP } from "../../../pubUtils/dicParam";
|
||||
@@ -168,7 +168,7 @@ export class ItemHandler {
|
||||
const channel: string = session.get('channel');
|
||||
const { code } = msg;
|
||||
|
||||
let giftCodeDetail = await GiftCodeDetailModel.findByCode(code);
|
||||
let giftCodeDetail = await GiftCodeDetail.findByCode(code);
|
||||
if(!giftCodeDetail) {
|
||||
return resResult(STATUS.GIFT_CODE_NOT_FOUND);
|
||||
}
|
||||
@@ -191,13 +191,13 @@ export class ItemHandler {
|
||||
return resResult(STATUS.YOU_HAVE_USED_THIS_CODE);
|
||||
}
|
||||
|
||||
let checkHasUse = await GiftCodeDetailModel.checkHasUsed(roleId, giftCodeDetail.giftId)
|
||||
let checkHasUse = await GiftCodeDetail.checkHasUsed(roleId, giftCodeDetail.giftId)
|
||||
if(checkHasUse) {
|
||||
return resResult(STATUS.YOU_HAVE_USED_THIS_CODE);
|
||||
}
|
||||
|
||||
|
||||
await GiftCodeDetailModel.increaseUsedNum(code, roleId, roleName, serverId);
|
||||
await GiftCodeDetail.increaseUsedNum(code, roleId, roleName, serverId);
|
||||
await GiftCode.increaseUsedNum(giftCode.id);
|
||||
|
||||
let goods = await addItems(roleId, roleName, sid, giftCode.goods, ITEM_CHANGE_REASON.USE_GIFT_CODE);
|
||||
|
||||
@@ -23,7 +23,6 @@ import { GuildLeader } from "../domain/rank";
|
||||
import { initTaLoggingMode } from "./sdk/ta";
|
||||
import { DicPushMessage } from "../pubUtils/dictionary/DicPushMessage";
|
||||
import GiftCode from "../db/GiftCode";
|
||||
import { GiftCodeDetailModel } from "../db/GiftCodeDetail";
|
||||
|
||||
// 检查私聊是否合法
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { gameData } from '@pubUtils/data';
|
||||
import { smsModel } from '@db/Sms';
|
||||
import { isString } from 'underscore';
|
||||
import GiftCode from '@db/GiftCode';
|
||||
import GiftCodeDetail, { GiftCodeDetailModel } from '@db/GiftCodeDetail';
|
||||
import GiftCodeDetail from '@db/GiftCodeDetail';
|
||||
import { deletRole } from '@pubUtils/roleUtil';
|
||||
import { RScriptRecordModel } from '@db/RScriptRecord';
|
||||
import { DicWar } from '@pubUtils/dictionary/DicWar';
|
||||
@@ -532,7 +532,7 @@ export default class GMUsers extends Service {
|
||||
if(!isNumber(count) || !params.checkParams()) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
|
||||
let giftCode = await GiftCode.createData(params);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
await GiftCodeDetail.generateMany(giftCode, count, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
@@ -552,7 +552,7 @@ export default class GMUsers extends Service {
|
||||
|
||||
let giftCode = await GiftCode.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.DB_DATA_NOT_FOUND);
|
||||
await GiftCodeDetailModel.generateMany(giftCode, count, ctx.user?.uid);
|
||||
await GiftCodeDetail.generateMany(giftCode, count, ctx.user?.uid);
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, giftCode);
|
||||
}
|
||||
|
||||
@@ -571,7 +571,7 @@ export default class GMUsers extends Service {
|
||||
|
||||
let giftCode = await GiftCode.findByGiftId(id);
|
||||
if(!giftCode) return ctx.service.utils.resResult(STATUS.WRONG_PARMS);
|
||||
let giftCodeDetails = await GiftCodeDetailModel.findAllCodeByGiftId(giftCode.id);
|
||||
let giftCodeDetails = await GiftCodeDetail.findAllCodeByGiftId(giftCode.id);
|
||||
|
||||
if(fileType == 'txt') {
|
||||
let codes: string[] = [];
|
||||
@@ -606,8 +606,8 @@ export default class GMUsers extends Service {
|
||||
public async getGiftCodeDetailList(page: number, pageSize: number, sortField: string, sortOrder: string, form: SearchGiftCodeDetailParam = {}) {
|
||||
const { ctx } = this;
|
||||
|
||||
const list = await GiftCodeDetailModel.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GiftCodeDetailModel.countByCondition( form )
|
||||
const list = await GiftCodeDetail.findByCondition(page, pageSize, sortField, sortOrder, form);
|
||||
const total = await GiftCodeDetail.countByCondition( form )
|
||||
return ctx.service.utils.resResult(STATUS.SUCCESS, {
|
||||
list: list.map(cur => ({...cur, env: ctx.app.config.realEnv })), total
|
||||
});
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions } from '@typegoose/typegoose';
|
||||
import { index, getModelForClass, prop, DocumentType, modelOptions, mongoose, ReturnModelType } from '@typegoose/typegoose';
|
||||
import { GIFT_GENERATE_TYPE } from '../consts';
|
||||
import { GiftCodeModel, GiftCodeType } from './GiftCode';
|
||||
import { nowSeconds } from '../pubUtils/timeUtil';
|
||||
@@ -55,17 +55,17 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
|
||||
// 根据code
|
||||
public static async findByCode(code: string) {
|
||||
let result: GiftCodeDetailType = await GiftCodeDetailModel.findOne({ code }).lean(true);
|
||||
let result: GiftCodeDetailType = await GiftCodeDetailROModel.findOne({ code }).lean(true);
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async checkHasUsed(roleId: string, id: number) {
|
||||
let result = await GiftCodeDetailModel.exists({ giftId: id, 'record.roleId': roleId });
|
||||
let result = await GiftCodeDetailROModel.exists({ giftId: id, 'record.roleId': roleId });
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async checkOrderHasUsed(id: number, orderId: string) {
|
||||
let result = await GiftCodeDetailModel.exists({ giftId: id, 'record.orderId': orderId });
|
||||
let result = await GiftCodeDetailROModel.exists({ giftId: id, 'record.orderId': orderId });
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -120,7 +120,7 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
sort[sortField] = -1;
|
||||
}
|
||||
}
|
||||
const result: GiftCodeDetailType[] = await GiftCodeDetailModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
const result: GiftCodeDetailType[] = await GiftCodeDetailROModel.find(searchObj, { _id: 0 }).limit(pageSize).skip((page - 1) * pageSize).sort(sort).lean({ getters: true, virtuals: true });
|
||||
return result;
|
||||
|
||||
}
|
||||
@@ -128,7 +128,7 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
public static async countByCondition(form: SearchGiftCodeDetailParam = {}) {
|
||||
|
||||
let searchObj = this.getSearchObj(form);
|
||||
const result = await GiftCodeDetailModel.count(searchObj);
|
||||
const result = await GiftCodeDetailROModel.count(searchObj);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -136,5 +136,12 @@ export default class GiftCodeDetail extends BaseModel {
|
||||
|
||||
export const GiftCodeDetailModel = getModelForClass(GiftCodeDetail);
|
||||
|
||||
export let GiftCodeDetailROModel: ReturnModelType<typeof GiftCodeDetail, {}>;
|
||||
export function loadGiftCodeDetailROModel(connect: mongoose.Connection) {
|
||||
GiftCodeDetailROModel = getModelForClass(GiftCodeDetail, {
|
||||
existingConnection: connect
|
||||
});
|
||||
}
|
||||
|
||||
export interface GiftCodeDetailType extends Pick<DocumentType<GiftCodeDetail>, keyof GiftCodeDetail> { }
|
||||
export type GiftCodeDetailParam = Partial<GiftCodeDetailType>;
|
||||
|
||||
@@ -20,6 +20,7 @@ import { loadItemROModel } from "./Item";
|
||||
import { loadUserGachaRecROModel } from "./UserGachaRec";
|
||||
import { loadUserGachaROModel } from "./UserGacha";
|
||||
import { loadGiftCodeROModel } from "./GiftCode";
|
||||
import { loadGiftCodeDetailROModel } from "./GiftCodeDetail";
|
||||
|
||||
export function loadGmDb(connect: mongoose.Connection) {
|
||||
// console.log('************')
|
||||
@@ -51,4 +52,5 @@ export function loadRODb(connect: mongoose.Connection) {
|
||||
loadUserGachaRecROModel(connect);
|
||||
loadUserGachaROModel(connect);
|
||||
loadGiftCodeROModel(connect);
|
||||
loadGiftCodeDetailROModel(connect);
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import { ServerlistModel } from '@db/Serverlist';
|
||||
import moment = require('moment');
|
||||
import { RegionModel } from '@db/Region';
|
||||
import { ActivityPublicAccountCodeModel } from '@db/ActivityPublicAccountCode';
|
||||
import { GiftCodeDetailModel } from '@db/GiftCodeDetail';
|
||||
import GiftCodeDetail from '@db/GiftCodeDetail';
|
||||
import GiftCode from '@db/GiftCode';
|
||||
|
||||
/**
|
||||
@@ -446,7 +446,7 @@ export default class Sdk extends Service {
|
||||
|
||||
} else {
|
||||
|
||||
let giftCodeDetail = await GiftCodeDetailModel.findByCode(params.gift_id);
|
||||
let giftCodeDetail = await GiftCodeDetail.findByCode(params.gift_id);
|
||||
if(!giftCodeDetail) {
|
||||
return resResult(SDK_37_ACTIVITY_CODE.GIFT_NOT_FOUND);
|
||||
}
|
||||
@@ -469,12 +469,12 @@ export default class Sdk extends Service {
|
||||
if(!role) return resResult(SDK_37_ACTIVITY_CODE.ROLE_NOT_FOUND);
|
||||
if(params.role_id && role.roleId != params.role_id) return resResult(SDK_37_ACTIVITY_CODE.ROLE_NOT_FOUND);
|
||||
|
||||
let checkHasUse = await GiftCodeDetailModel.checkOrderHasUsed(giftCodeDetail.giftId, params.order_id);
|
||||
let checkHasUse = await GiftCodeDetail.checkOrderHasUsed(giftCodeDetail.giftId, params.order_id);
|
||||
if(checkHasUse) {
|
||||
return resResult(SDK_37_ACTIVITY_CODE.ORDER_DUPLICATE);
|
||||
}
|
||||
|
||||
await GiftCodeDetailModel.increaseUsedNum(giftCodeDetail.code, role.roleId, role.roleName, role.serverId, params.order_id);
|
||||
await GiftCodeDetail.increaseUsedNum(giftCodeDetail.code, role.roleId, role.roleName, role.serverId, params.order_id);
|
||||
await GiftCode.increaseUsedNum(giftCode.id);
|
||||
|
||||
await ctx.service.utils.pushGiftCodeChannel(role.roleId, giftCode.id);
|
||||
|
||||
Reference in New Issue
Block a user