update
This commit is contained in:
87
models/UserSubscription.js
Normal file
87
models/UserSubscription.js
Normal file
@@ -0,0 +1,87 @@
|
||||
const { DataTypes } = require('sequelize');
|
||||
const { sequelize } = require('../config/database');
|
||||
|
||||
/**
|
||||
* UserSubscription Model - Quản lý subscription của từng user
|
||||
*/
|
||||
const UserSubscription = sequelize.define('user_subscriptions', {
|
||||
id: {
|
||||
type: DataTypes.UUID,
|
||||
defaultValue: DataTypes.UUIDV4,
|
||||
primaryKey: true,
|
||||
},
|
||||
user_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'users_auth',
|
||||
key: 'id',
|
||||
},
|
||||
comment: 'User mua gói',
|
||||
},
|
||||
plan_id: {
|
||||
type: DataTypes.UUID,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'subscription_plans',
|
||||
key: 'id',
|
||||
},
|
||||
comment: 'Gói đã mua',
|
||||
},
|
||||
start_date: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false,
|
||||
comment: 'Ngày bắt đầu',
|
||||
},
|
||||
end_date: {
|
||||
type: DataTypes.DATEONLY,
|
||||
allowNull: false,
|
||||
comment: 'Ngày kết thúc',
|
||||
},
|
||||
status: {
|
||||
type: DataTypes.ENUM('active', 'expired', 'cancelled'),
|
||||
defaultValue: 'active',
|
||||
allowNull: false,
|
||||
comment: 'Trạng thái subscription',
|
||||
},
|
||||
transaction_id: {
|
||||
type: DataTypes.STRING(100),
|
||||
comment: 'Mã giao dịch để đối soát',
|
||||
},
|
||||
payment_method: {
|
||||
type: DataTypes.STRING(50),
|
||||
comment: 'Phương thức thanh toán: momo, vnpay, banking',
|
||||
},
|
||||
payment_amount: {
|
||||
type: DataTypes.DECIMAL(10, 2),
|
||||
comment: 'Số tiền đã thanh toán',
|
||||
},
|
||||
auto_renew: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
defaultValue: false,
|
||||
comment: 'Tự động gia hạn',
|
||||
},
|
||||
created_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
updated_at: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW,
|
||||
},
|
||||
}, {
|
||||
tableName: 'user_subscriptions',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
indexes: [
|
||||
{ fields: ['user_id'] },
|
||||
{ fields: ['status'] },
|
||||
{ fields: ['end_date'] },
|
||||
{ fields: ['transaction_id'] },
|
||||
],
|
||||
comment: 'Bảng quản lý subscription của user',
|
||||
});
|
||||
|
||||
module.exports = UserSubscription;
|
||||
Reference in New Issue
Block a user