rentease-backend-new/models/Order.js

128 lines
2.6 KiB
JavaScript
Raw Normal View History

2026-04-20 06:43:09 +00:00
const { DataTypes } = require('sequelize');
const sequelize = require('../config/db');
const Order = sequelize.define('Order', {
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
2026-06-11 13:45:33 +00:00
comment: 'Order ID'
2026-04-20 06:43:09 +00:00
},
orderNo: {
type: DataTypes.STRING(50),
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Order number'
2026-04-20 06:43:09 +00:00
},
tenantId: {
type: DataTypes.INTEGER,
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Tenant ID'
2026-04-20 06:43:09 +00:00
},
planId: {
type: DataTypes.INTEGER,
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Plan ID'
2026-04-20 06:43:09 +00:00
},
planName: {
type: DataTypes.STRING(100),
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Plan name snapshot'
2026-04-20 06:43:09 +00:00
},
months: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 1,
2026-06-11 13:45:33 +00:00
comment: 'Purchased months'
},
billingCycle: {
type: DataTypes.ENUM('monthly', 'yearly', 'custom'),
allowNull: false,
defaultValue: 'monthly',
comment: 'Billing cycle'
},
periodStart: {
type: DataTypes.DATE,
allowNull: true,
comment: 'Subscription period start'
},
periodEnd: {
type: DataTypes.DATE,
allowNull: true,
comment: 'Subscription period end'
},
subscriptionId: {
type: DataTypes.INTEGER,
allowNull: true,
comment: 'Subscription ID'
2026-04-20 06:43:09 +00:00
},
amount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Order amount'
2026-04-20 06:43:09 +00:00
},
discountAmount: {
type: DataTypes.DECIMAL(10, 2),
defaultValue: 0.00,
2026-06-11 13:45:33 +00:00
comment: 'Discount amount'
2026-04-20 06:43:09 +00:00
},
actualAmount: {
type: DataTypes.DECIMAL(10, 2),
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Payable amount'
2026-04-20 06:43:09 +00:00
},
status: {
type: DataTypes.ENUM('pending', 'paid', 'cancelled'),
defaultValue: 'pending',
2026-06-11 13:45:33 +00:00
comment: 'Order status'
2026-04-20 06:43:09 +00:00
},
paidTime: {
type: DataTypes.DATE,
allowNull: true,
2026-06-11 13:45:33 +00:00
comment: 'Paid time'
2026-04-20 06:43:09 +00:00
},
expireTime: {
type: DataTypes.DATE,
allowNull: false,
2026-06-11 13:45:33 +00:00
comment: 'Order expiration time'
2026-04-20 06:43:09 +00:00
},
remark: {
type: DataTypes.STRING(255),
allowNull: true,
2026-06-11 13:45:33 +00:00
comment: 'Remark'
2026-04-20 06:43:09 +00:00
},
createBy: {
type: DataTypes.INTEGER,
allowNull: true,
2026-06-11 13:45:33 +00:00
comment: 'Created by'
2026-04-20 06:43:09 +00:00
},
updateBy: {
type: DataTypes.INTEGER,
allowNull: true,
2026-06-11 13:45:33 +00:00
comment: 'Updated by'
2026-04-20 06:43:09 +00:00
},
isDeleted: {
type: DataTypes.INTEGER,
allowNull: false,
defaultValue: 0,
2026-06-11 13:45:33 +00:00
comment: 'Soft delete flag'
2026-04-20 06:43:09 +00:00
},
createTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
2026-06-11 13:45:33 +00:00
comment: 'Created time'
2026-04-20 06:43:09 +00:00
},
updateTime: {
type: DataTypes.DATE,
allowNull: false,
defaultValue: DataTypes.NOW,
2026-06-11 13:45:33 +00:00
comment: 'Updated time'
2026-04-20 06:43:09 +00:00
}
}, {
tableName: 'orders',
timestamps: false,
2026-06-11 13:45:33 +00:00
comment: 'Orders'
2026-04-20 06:43:09 +00:00
});
module.exports = Order;