后台:添加操作日志

This commit is contained in:
luying
2021-12-22 17:10:10 +08:00
parent 5573faafb1
commit 8c488ea710
14 changed files with 273 additions and 28 deletions

View File

@@ -140,6 +140,11 @@ export default class GMMail extends BaseModel {
return result;
}
public static async getGmMailByIdAndType(_id: string, mailType: GM_MAIL_TYPE, hasGoods: boolean) {
const result: GMMailType = await GMMailModel.findOne({ _id, mailType, hasGoods }).lean();
return result;
}
private static getSearchObj(form: SearchMailParam) {
let searchObj = {};
if(form.createTimeStart) searchObj['createdAt'] = { $gt: new Date(form.createTimeStart * 1000) };

View File

@@ -1,6 +1,7 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType, ReturnModelType, mongoose } from '@typegoose/typegoose';
import { gameData } from '../pubUtils/data';
import { SearchLogParam } from '../domain/backEndField/search';
/**
* GM用户组接口
@@ -22,6 +23,9 @@ export default class GMRecord extends BaseModel {
@prop({ required: true })
apiName: string;
@prop({ required: true })
apiModule: string;
@prop({ required: true })
body: string;
@@ -30,10 +34,28 @@ export default class GMRecord extends BaseModel {
public static async createRecord(uid: number, env: string, api: string, body: string, result: string) {
let dicApi = gameData.apiByUrl.get(api);
const r = await GMRecordModel.insertMany({uid, env, api, apiName: dicApi?.name, body, result});
const r = await GMRecordModel.insertMany({uid, env, api, apiName: dicApi?.name, apiModule: dicApi?.module, body, result});
return r;
}
private static getSearchObj(form: SearchLogParam) {
let searchObj = {};
if (form.env) searchObj['env'] = form.env;
if (form.uid) searchObj['uid'] = form.uid;
if (form.apiModule) searchObj['apiModule'] = form.apiModule;
if (form.api) searchObj['api'] = form.api;
if (form.createTimeStart && form.createTimeEnd) {
searchObj['createdAt'] = { $lte: new Date(form.createTimeEnd * 1000), $gte: new Date(form.createTimeStart * 100) };
}
return searchObj
}
public static async findByCondition(page: number, pageSize: number, form: SearchLogParam = {}) {
let searchObj = GMRecordModel.getSearchObj(form);
const result: GMRecordType[] = await GMRecordModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort({ createdAt: -1 }).select('-_id').lean({ getters: true, virtuals: true });
return result;
}
}
export let GMRecordModel: ReturnModelType<typeof GMRecord, {}>;

104
shared/db/UserLog.ts Normal file
View File

@@ -0,0 +1,104 @@
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
class Reward {
@prop({ required: true })
id: number;
@prop({ required: true })
count: number;
}
/**
* 玩家充值订单
*/
@index({ localOrderID: 1 })
export default class UserLog extends BaseModel {
@prop({ required: true })
type: string; // 类型 LOG_TYPE
@prop({ required: true })
uid: number; // uid
@prop({ required: true })
roleId: string; // 角色id
@prop({ required: true })
roleName: string; // 角色名
@prop({ required: false })
ip: string; // ip
// 战力相关
@prop({ required: false })
inc: number; // 改变值 战力改变/道具数量改变
@prop({ required: false })
count: number; // 变化后的值 战力改变/道具数量改变
@prop({ required: false })
ceChangeReason: number; // 战力变化原因
@prop({ required: false })
ceChangeReasonInfo: string; // 战力变化原因信息如武将id等
// 充值相关
@prop({ required: false })
productId: string; // 商品id
@prop({ required: false })
productName: string; // 商品名字
@prop({ required: false })
price: number; // 充值金额
@prop({ required: false })
isYuanbao: boolean; // 是否为代币
@prop({ required: false })
localOrderId: string; // 订单id
@prop({ required: false })
totalPay: number; // 总充值金额
@prop({ required: false })
orderStatus: number; // 订单状态
// 道具相关
@prop({ required: false })
itemId: number; // 道具id
@prop({ required: false })
itemName: string; // 道具名
@prop({ required: false })
itid: number; // 道具类型
@prop({ required: false })
itemChangeModule: string; // 道具变更模块
@prop({ required: false })
itemChangeReason: number; // 道具变更来源
// 邮件日志
@prop({ required: false })
mailId: string; // 邮件id
@prop({ required: false, type: Reward, _id: false })
goods: Reward[]; // 邮件附带道具
@prop({ required: false })
mailContent: string; // 邮件正文
@prop({ required: false })
mailTitle: string; // 邮件标题
@prop({ required: false })
mailSendName: string; // 邮件发件人
}
export const UserLogModel = getModelForClass(UserLog);
export interface UserLogModelType extends Pick<DocumentType<UserLog>, keyof UserLog> { }
export type UserLogModelTypeParam = Partial<UserLogModelType>; // 将所有字段变成可选项