const { DataTypes } = require('sequelize'); const sequelize = require('../config/db'); const Coupon = sequelize.define('Coupon', { id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true, comment: '优惠券ID' }, code: { type: DataTypes.STRING(50), allowNull: false, unique: true, comment: '优惠券代码' }, name: { type: DataTypes.STRING(100), allowNull: false, comment: '优惠券名称' }, description: { type: DataTypes.TEXT, allowNull: true, comment: '描述' }, discountType: { type: DataTypes.ENUM('percentage', 'fixed'), defaultValue: 'percentage', comment: '折扣类型:percentage-百分比,fixed-固定金额' }, discountValue: { type: DataTypes.DECIMAL(10, 2), allowNull: false, comment: '折扣值' }, minOrderAmount: { type: DataTypes.DECIMAL(10, 2), defaultValue: 0, comment: '最低订单金额' }, maxDiscountAmount: { type: DataTypes.DECIMAL(10, 2), allowNull: true, comment: '最大折扣金额' }, applicablePlans: { type: DataTypes.JSON, allowNull: true, comment: '适用套餐ID列表' }, usageLimit: { type: DataTypes.INTEGER, defaultValue: 0, comment: '使用次数限制' }, usageCount: { type: DataTypes.INTEGER, defaultValue: 0, comment: '已使用次数' }, validStart: { type: DataTypes.DATE, allowNull: false, comment: '有效期开始' }, validEnd: { type: DataTypes.DATE, allowNull: false, comment: '有效期结束' }, status: { type: DataTypes.ENUM('active', 'inactive', 'expired'), defaultValue: 'active', comment: '状态' }, isDeleted: { type: DataTypes.TINYINT(1), defaultValue: 0, comment: '删除状态' }, createTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '创建时间' }, updateTime: { type: DataTypes.DATE, allowNull: false, defaultValue: DataTypes.NOW, comment: '更新时间' } }, { tableName: 'coupons', timestamps: false, indexes: [ { fields: ['code'] }, { fields: ['status'] }, { fields: ['validStart', 'validEnd'] } ], comment: '优惠券表' }); module.exports = Coupon;