ExchangeHistory.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import mongoose from "mongoose";
  2. const ExchangeHistorySchema = new mongoose.Schema(
  3. {
  4. userId: {
  5. type: mongoose.Schema.Types.ObjectId,
  6. ref: "User",
  7. required: true,
  8. },
  9. username: {
  10. type: String,
  11. required: true,
  12. },
  13. item: {
  14. type: mongoose.Schema.Types.ObjectId,
  15. ref: "ExchangeItem",
  16. required: true,
  17. },
  18. status: {
  19. type: String,
  20. enum: ["待兑换未审核", "待兑换已审核", "已兑换", "拒绝"],
  21. default: "待兑换未审核",
  22. },
  23. points: { type: Number, default: 0 },
  24. exchangeInfo: {
  25. account: { type: String },
  26. name: { type: String },
  27. phone: { type: String },
  28. address: { type: String },
  29. },
  30. exchangeTime: { type: Date },
  31. exchangeCount: { type: Number, default: 0 },
  32. },
  33. { timestamps: true }
  34. );
  35. ExchangeHistorySchema.index({ "userId": 1 }); // userId 索引
  36. ExchangeHistorySchema.index({ "username": 1 }); // username 索引
  37. ExchangeHistorySchema.index({ "createdAt": 1 }); // createdAt 索引
  38. export default mongoose.models.ExchangeHistory ||
  39. mongoose.model("ExchangeHistory", ExchangeHistorySchema);