refactor: 项目架构重构 - 目录标准化 + 清理冗余
- 目录重命名: backend/wdkj-server/ → server/, frontend/ai-dimension/ → client/ - 删除 20+ 冗余文件(WDKJ 旧脚本、Windows 脚本、过时文档、设计稿) - 更新 package.json 元数据(移除 wdkj 命名) - 完善三级 .gitignore(根 + server + client) - 重写 README.md 和 CHANGELOG.md - 工具脚本移至 scripts/
This commit is contained in:
Executable
+109
@@ -0,0 +1,109 @@
|
||||
const mongoose = require('mongoose')
|
||||
const { Schema } = mongoose
|
||||
|
||||
/**
|
||||
* 商品模型
|
||||
*/
|
||||
const ShopItemSchema = new Schema({
|
||||
// 基本信息
|
||||
itemId: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
index: true
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
trim: true
|
||||
},
|
||||
description: {
|
||||
type: String,
|
||||
trim: true
|
||||
},
|
||||
|
||||
// 价格(单位:分)
|
||||
price: {
|
||||
type: Number,
|
||||
required: true,
|
||||
min: 1
|
||||
},
|
||||
originalPrice: {
|
||||
type: Number
|
||||
},
|
||||
|
||||
// 商品类型
|
||||
type: {
|
||||
type: String,
|
||||
enum: ['skin', 'noad', 'subscription'],
|
||||
required: true
|
||||
},
|
||||
|
||||
// 订阅天数(仅订阅商品)
|
||||
duration: {
|
||||
type: Number,
|
||||
default: 30
|
||||
},
|
||||
|
||||
// 图片
|
||||
imageUrl: String,
|
||||
previewUrl: String,
|
||||
|
||||
// 统计
|
||||
purchaseCount: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
|
||||
// 状态
|
||||
status: {
|
||||
type: String,
|
||||
enum: ['active', 'inactive', 'discontinued'],
|
||||
default: 'active',
|
||||
index: true
|
||||
},
|
||||
|
||||
// 排序
|
||||
sortOrder: {
|
||||
type: Number,
|
||||
default: 0
|
||||
},
|
||||
|
||||
// 促销
|
||||
isOnSale: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
saleEndTime: Date,
|
||||
|
||||
// 时间戳
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
}, {
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true }
|
||||
})
|
||||
|
||||
// 索引
|
||||
ShopItemSchema.index({ status: 1, sortOrder: 1 })
|
||||
ShopItemSchema.index({ type: 1 })
|
||||
|
||||
// 虚拟字段:是否在促销中
|
||||
ShopItemSchema.virtual('isOnSaleActive').get(function() {
|
||||
return this.isOnSale && this.saleEndTime && new Date() < this.saleEndTime
|
||||
})
|
||||
|
||||
// 中间件:保存前更新 updatedAt
|
||||
ShopItemSchema.pre('save', function(next) {
|
||||
this.updatedAt = Date.now()
|
||||
next()
|
||||
})
|
||||
|
||||
module.exports = mongoose.model('ShopItem', ShopItemSchema)
|
||||
Reference in New Issue
Block a user