95 lines
2.1 KiB
TypeScript
95 lines
2.1 KiB
TypeScript
import { getModelForClass, index, modelOptions, mongoose, prop, ReturnModelType, Severity } from '@typegoose/typegoose'
|
|
import { dbconn } from 'decorators/dbconn'
|
|
import { BaseModule } from './Base'
|
|
|
|
export enum PayPlatEnum {
|
|
ALCHEMY = 1,
|
|
}
|
|
|
|
export enum PayType {
|
|
BUY = 1,
|
|
SELL = 2,
|
|
}
|
|
|
|
export enum PayStatus {
|
|
PENDING = 0,
|
|
TRANSFERING = 1, //只有国库模式才会有该状态
|
|
TRANSFERED = 2, //只有国库模式才会有该状态
|
|
SUCCESS = 9,
|
|
TRANSFER_FAIL = 98, // 转账错误
|
|
FAIL = 99,
|
|
}
|
|
|
|
@dbconn('pay')
|
|
@index({ outOrderId: 1 }, { unique: true, partialFilterExpression: { outOrderId: { $exists: true } } })
|
|
@modelOptions({
|
|
schemaOptions: { collection: 'pay_record', timestamps: true },
|
|
options: { allowMixed: Severity.ALLOW },
|
|
})
|
|
export class PayRecordClass extends BaseModule {
|
|
@prop({ enum: PayPlatEnum, default: PayPlatEnum.ALCHEMY })
|
|
public channel!: PayPlatEnum
|
|
|
|
@prop({ required: true, default: PayType.BUY })
|
|
public type: PayType
|
|
|
|
@prop({ required: true })
|
|
public account: string
|
|
|
|
@prop()
|
|
public address: string
|
|
|
|
@prop()
|
|
public network?: string
|
|
|
|
@prop()
|
|
public crypto?: string
|
|
|
|
@prop()
|
|
public env?: string
|
|
|
|
// 法币
|
|
@prop()
|
|
public fiat?: string
|
|
// 法币数量
|
|
@prop()
|
|
public fiatAmount?: string
|
|
// 加密货币数量
|
|
@prop()
|
|
public cryptoAmount?: string
|
|
|
|
// 加密货币价格
|
|
@prop()
|
|
public cryptoPrice?: string
|
|
// 该笔交易渠道会给我们多少usdt
|
|
@prop()
|
|
public usdtAdmount?: string
|
|
// 国家
|
|
@prop()
|
|
public country?: string
|
|
|
|
@prop({ required: true, default: PayStatus.PENDING })
|
|
public status: PayStatus
|
|
// 渠道返回的原始资料
|
|
@prop({ type: mongoose.Schema.Types.Mixed })
|
|
public outData: any
|
|
|
|
// 渠道返回的订单id
|
|
@prop()
|
|
public outOrderId: string
|
|
// 交易的txHash
|
|
@prop()
|
|
public txHash?: string
|
|
|
|
@prop()
|
|
public gameAccountId: string
|
|
@prop()
|
|
public gameOrderId: string
|
|
|
|
public static async findByRecordId(this: ReturnModelType<typeof PayRecordClass>, outOrderId: string) {
|
|
return this.findOne({ outOrderId }).exec()
|
|
}
|
|
}
|
|
|
|
export const PayRecord = getModelForClass(PayRecordClass, { existingConnection: PayRecordClass.db })
|