Major Features Added: - Complete Plugin Architecture System with financial plugin - Multi-currency support with exchange rates - Course type system (online, classroom, hybrid) - Attendance tracking and QR code scanning - Classroom sessions management - Course sections and content management - Professional video player with authentication - Secure media serving system - Shopping cart and checkout system - Financial dashboard and earnings tracking - Trainee progress tracking - User notes and assignments system Backend Infrastructure: - Plugin loader and registry system - Multi-currency database models - Secure media middleware - Course access middleware - Financial plugin with payment processing - Database migrations for new features - API endpoints for all new functionality Frontend Components: - Course management interface - Content creation and editing - Section management with drag-and-drop - Professional video player - QR scanner for attendance - Shopping cart and checkout flow - Financial dashboard - Plugin management interface - Trainee details and progress views This represents a major evolution of CourseWorx from a basic LMS to a comprehensive educational platform with plugin architecture.
139 lines
3 KiB
JavaScript
139 lines
3 KiB
JavaScript
/**
|
|
* Payout Model for Financial Plugin
|
|
*
|
|
* This model handles instructor payouts including
|
|
* revenue sharing, platform fees, and transfer tracking.
|
|
*/
|
|
|
|
const { DataTypes } = require('sequelize');
|
|
|
|
module.exports = (sequelize) => {
|
|
const Payout = sequelize.define('FinancialPayout', {
|
|
id: {
|
|
type: DataTypes.UUID,
|
|
defaultValue: DataTypes.UUIDV4,
|
|
primaryKey: true
|
|
},
|
|
trainerId: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'users',
|
|
key: 'id',
|
|
onDelete: 'CASCADE'
|
|
}
|
|
},
|
|
orderId: {
|
|
type: DataTypes.UUID,
|
|
allowNull: false,
|
|
references: {
|
|
model: 'financial_orders',
|
|
key: 'id',
|
|
onDelete: 'CASCADE'
|
|
}
|
|
},
|
|
amount: {
|
|
type: DataTypes.DECIMAL(10, 2),
|
|
allowNull: false,
|
|
validate: {
|
|
min: 0
|
|
}
|
|
},
|
|
platformFee: {
|
|
type: DataTypes.DECIMAL(10, 2),
|
|
allowNull: false,
|
|
defaultValue: 0.00,
|
|
validate: {
|
|
min: 0
|
|
}
|
|
},
|
|
trainerShare: {
|
|
type: DataTypes.DECIMAL(10, 2),
|
|
allowNull: false,
|
|
validate: {
|
|
min: 0
|
|
}
|
|
},
|
|
status: {
|
|
type: DataTypes.ENUM('pending', 'processing', 'completed', 'failed'),
|
|
allowNull: false,
|
|
defaultValue: 'pending'
|
|
},
|
|
stripeTransferId: {
|
|
type: DataTypes.STRING(255),
|
|
allowNull: true
|
|
},
|
|
processedAt: {
|
|
type: DataTypes.DATE,
|
|
allowNull: true
|
|
}
|
|
}, {
|
|
tableName: 'financial_payouts',
|
|
timestamps: true,
|
|
indexes: [
|
|
{
|
|
fields: ['trainerId']
|
|
},
|
|
{
|
|
fields: ['orderId']
|
|
},
|
|
{
|
|
fields: ['status']
|
|
}
|
|
]
|
|
});
|
|
|
|
// Instance methods
|
|
Payout.prototype.markAsProcessing = function() {
|
|
this.status = 'processing';
|
|
return this.save();
|
|
};
|
|
|
|
Payout.prototype.markAsCompleted = function(stripeTransferId) {
|
|
this.status = 'completed';
|
|
this.stripeTransferId = stripeTransferId;
|
|
this.processedAt = new Date();
|
|
return this.save();
|
|
};
|
|
|
|
Payout.prototype.markAsFailed = function() {
|
|
this.status = 'failed';
|
|
this.processedAt = new Date();
|
|
return this.save();
|
|
};
|
|
|
|
// Static methods
|
|
Payout.findByTrainer = function(trainerId, options = {}) {
|
|
return this.findAll({
|
|
where: { trainerId },
|
|
order: [['createdAt', 'DESC']],
|
|
...options
|
|
});
|
|
};
|
|
|
|
Payout.getTrainerEarnings = function(trainerId, startDate, endDate) {
|
|
return this.findAll({
|
|
where: {
|
|
trainerId,
|
|
status: 'completed',
|
|
createdAt: {
|
|
[sequelize.Sequelize.Op.between]: [startDate, endDate]
|
|
}
|
|
},
|
|
attributes: [
|
|
[sequelize.fn('COUNT', sequelize.col('id')), 'totalPayouts'],
|
|
[sequelize.fn('SUM', sequelize.col('trainerShare')), 'totalEarnings'],
|
|
[sequelize.fn('SUM', sequelize.col('platformFee')), 'totalPlatformFees']
|
|
]
|
|
});
|
|
};
|
|
|
|
Payout.getPendingPayouts = function() {
|
|
return this.findAll({
|
|
where: { status: 'pending' },
|
|
order: [['createdAt', 'ASC']]
|
|
});
|
|
};
|
|
|
|
return Payout;
|
|
};
|