25 lines
935 B
JavaScript
25 lines
935 B
JavaScript
const mongoose = require('mongoose');
|
|
|
|
const complaintSchema = new mongoose.Schema({
|
|
complaintId: { type: String, required: true, unique: true },
|
|
customer: { type: mongoose.Schema.Types.ObjectId, ref: 'Customer' },
|
|
order: { type: mongoose.Schema.Types.ObjectId, ref: 'Order' },
|
|
type: { type: String, enum: ['服务态度', '车辆问题', '费用问题', '其他'], required: true },
|
|
content: { type: String, required: true },
|
|
status: { type: String, enum: ['待处理', '处理中', '已解决', '已关闭'], default: '待处理' },
|
|
response: { type: String },
|
|
handler: { type: String },
|
|
createdAt: { type: Date, default: Date.now },
|
|
updatedAt: { type: Date, default: Date.now }
|
|
});
|
|
|
|
complaintSchema.pre('save', function(next) {
|
|
if (!this.complaintId) {
|
|
this.complaintId = `COMP${Date.now()}`;
|
|
}
|
|
this.updatedAt = new Date();
|
|
next();
|
|
});
|
|
|
|
module.exports = mongoose.model('Complaint', complaintSchema);
|