Files
ZYZ/shared/db/UserLog.ts
2022-02-11 15:31:48 +08:00

134 lines
4.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import BaseModel from './BaseModel';
import { index, getModelForClass, prop, DocumentType } from '@typegoose/typegoose';
import { SearchUserLogParam } from '../domain/backEndField/search';
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 })
serverId: number; // 小区id
@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, type: Number })
ceChangeIds: number[]; // 战力变化原因信息如武将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 })
orderID: string; // 平台订单id
@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 })
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; // 邮件发件人
public static async createRecord(params: UserLogModelTypeParam) {
const r = await UserLogModel.insertMany(params);
return r;
}
private static getSearchObj(form: SearchUserLogParam) {
let searchObj = {};
if (form.type) searchObj['type'] = form.type;
if (form.serverId) searchObj['serverId'] = form.serverId;
if (form.uid) searchObj['uid'] = form.uid;
if (form.roleId) searchObj['roleId'] = form.roleId;
if(form.roleName) searchObj['roleName'] = { $regex: new RegExp(form.roleName.toString(), 'i') };
if (form.createTimeStart && form.createTimeEnd) {
searchObj['createdAt'] = { $lte: new Date(form.createTimeEnd * 1000), $gte: new Date(form.createTimeStart * 1000) };
}
return searchObj
}
public static async findByCondition(page: number, pageSize: number, form: SearchUserLogParam = {}) {
let searchObj = UserLogModel.getSearchObj(form);
const result: UserLogModelType[] = await UserLogModel.find(searchObj).limit(pageSize).skip((page - 1) * pageSize).sort({ createdAt: -1 }).select('-_id').lean({ getters: true, virtuals: true });
return result;
}
}
export let UserLogModel = getModelForClass(UserLog);
export interface UserLogModelType extends Pick<DocumentType<UserLog>, keyof UserLog> { }
export type UserLogModelTypeParam = Partial<UserLogModelType>; // 将所有字段变成可选项