39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
const mongoose = require('mongoose');
|
|
|
|
const paymentSchema = new mongoose.Schema({
|
|
paymentId: { type: String, required: true, unique: true },
|
|
// 收支类型:收入(客户付款)/ 支出(退款、工资、房租等)
|
|
type: {
|
|
type: String,
|
|
enum: ['收入', '支出'],
|
|
required: true
|
|
},
|
|
// 对方名称(谁给钱/我们给谁)
|
|
party: { type: String, required: true },
|
|
// 金额
|
|
amount: { type: Number, required: true },
|
|
// 收支方式
|
|
method: { type: String, enum: ['微信', '支付宝', '银行卡', '现金'] },
|
|
// 分类
|
|
category: {
|
|
type: String,
|
|
enum: ['租金收入', '押金退还', '退款', '工资', '房租', '水电', '维修', '其他']
|
|
},
|
|
// 备注
|
|
remark: { type: String },
|
|
// 经手人
|
|
operator: { type: String },
|
|
createdAt: { type: Date, default: Date.now },
|
|
updatedAt: { type: Date, default: Date.now }
|
|
});
|
|
|
|
paymentSchema.pre('save', function(next) {
|
|
if (!this.paymentId) {
|
|
this.paymentId = `PAY${Date.now()}`;
|
|
}
|
|
this.updatedAt = new Date();
|
|
next();
|
|
});
|
|
|
|
module.exports = mongoose.model('Payment', paymentSchema);
|