ayangzy/laravel-sales-commission
Composer 安装命令:
composer require ayangzy/laravel-sales-commission
包简介
A comprehensive sales commission calculation and management package for Laravel
README 文档
README
What is Laravel Sales Commission?
Laravel Sales Commission is a comprehensive, enterprise-grade commission calculation and management package designed specifically for Laravel SaaS applications. It provides a complete solution for businesses that need to track, calculate, and pay commissions to sales representatives, affiliates, partners, or any type of agent.
Unlike simple percentage calculators, this package handles the entire commission lifecycle — from initial calculation through clawbacks (refunds) to final payout processing. It's built to handle real-world complexity including team-based sales, tiered commission structures, and flexible payout schedules.
Whether you're building an e-commerce platform with sales reps, a SaaS with an affiliate program, or a network marketing application, this package provides the foundation you need without reinventing the wheel.
Key Features
🎯 Flexible Commission Plans
Create unlimited commission plans tailored to different agent types, products, or sales channels. Each plan can have its own rules, tiers, and payout settings. Perfect for businesses with diverse sales structures — one plan for in-house sales reps, another for external affiliates.
📊 Multi-Tier Commission Structures
Implement progressive commission rates that reward high performers. Agents automatically move through tiers (e.g., Bronze → Silver → Gold) as their cumulative sales increase, unlocking higher commission percentages. This incentivizes continuous performance improvement.
👥 Team Split Commissions
Handle complex team sales where multiple agents contribute to a deal. Split commissions by percentage with role tracking (primary closer, supporting rep, manager override). Ensures fair attribution when sales involve collaboration.
🔄 Clawback Support
Protect your business when sales are refunded or charged back. The clawback system reverses commissions proportionally with configurable grace periods. Supports full clawbacks, partial clawbacks, and automatic clawbacks on refund events.
💰 Payout Management
Complete payout lifecycle management — generate payout batches, require approval workflows, process payments, and track payment status. Supports configurable payout schedules (weekly, bi-weekly, monthly) and minimum payout thresholds.
📈 Performance Bonuses
Reward agents for hitting milestones with bonus rules. Configure one-time or recurring bonuses when agents reach sales targets, close their first deal, or achieve tier upgrades.
🎛️ Extensible Rule Engine
The modular rule system supports percentage-based, flat-rate, tiered, and conditional commissions out of the box. Need custom logic? Extend the base rule class to implement any commission formula your business requires.
📅 Period-Based Tracking
All earnings are tracked by period (week, month, quarter) enabling accurate reporting, forecasting, and historical analysis. Easily query earnings for any time range.
⚡ Event-Driven Architecture
Hooks into Laravel's event system. Listen to CommissionEarned, CommissionClawedBack, PayoutProcessed, and TierAchieved events to trigger notifications, update leaderboards, or integrate with external systems.
Use Cases
Who Needs This Package?
| Platform Type | Why You Need It |
|---|---|
| E-commerce with Sales Reps | Track commissions per order, handle returns/refunds, pay reps monthly |
| SaaS with Affiliate Programs | Recurring commissions on subscriptions, clawback on cancellations |
| Marketplace Platforms | Split commissions between sellers, platform, and referrers |
| Insurance & Real Estate | Complex tiered structures, team overrides, compliance-ready |
| Network Marketing / MLM | Multi-level commission trees, performance tiers, bonus structures |
| Recruitment Agencies | Placement fees, split commissions, clawback on early termination |
| Freelance Platforms | Platform fees, referral bonuses, milestone payments |
How It's Different
| Feature | Laravel Sales Commission | Other Packages |
|---|---|---|
| Full Lifecycle Management | Calculation → Clawback → Payout | Calculation only |
| Team Split Commissions | ✅ Built-in with roles | ❌ Not supported |
| Clawback System | ✅ Full, partial, grace periods | ❌ Not supported |
| Payout Processing | ✅ Generate, approve, process | ❌ Not supported |
| Multi-Tier Structures | ✅ Automatic tier progression | ⚠️ Basic tiers |
| Conditional Rules | ✅ Any condition (category, amount, etc.) | ⚠️ Limited |
| Event System | ✅ 4 lifecycle events | ⚠️ Minimal |
| Period Tracking | ✅ Weekly/Monthly/Quarterly | ❌ Not supported |
| Production Ready | ✅ 31 tests, CI/CD, documented | ⚠️ Varies |
Requirements
- PHP 8.2+
- Laravel 10.x or 11.x
Installation
composer require ayangzy/laravel-sales-commission
Publish the configuration and migrations:
php artisan vendor:publish --tag="sales-commission-config" php artisan vendor:publish --tag="sales-commission-migrations" php artisan migrate
Quick Start
1. Add Traits to Your Models
User/Agent Model:
use SalesCommission\Traits\HasCommissions; class User extends Model { use HasCommissions; }
Order/Sale Model:
use SalesCommission\Traits\Commissionable; class Order extends Model { use Commissionable; public function getCommissionableAmount(): float { return $this->total; } public function getCommissionAgent(): ?Model { return $this->salesRep; } }
2. Create a Commission Plan
use SalesCommission\Models\CommissionPlan; use SalesCommission\Models\CommissionTier; use SalesCommission\Models\CommissionRule; // Create a plan $plan = CommissionPlan::create([ 'name' => 'Standard Sales Plan', 'slug' => 'standard', 'is_active' => true, 'is_default' => true, ]); // Add tiers $plan->tiers()->createMany([ ['name' => 'Bronze', 'min_threshold' => 0, 'max_threshold' => 10000, 'rate' => 5], ['name' => 'Silver', 'min_threshold' => 10001, 'max_threshold' => 50000, 'rate' => 7.5], ['name' => 'Gold', 'min_threshold' => 50001, 'max_threshold' => null, 'rate' => 10], ]); // Add a rule $plan->rules()->create([ 'name' => 'Standard Commission', 'type' => 'percentage', 'value' => 10, // 10% 'is_active' => true, ]);
3. Calculate Commissions
use SalesCommission\Facades\Commission; // Calculate commission for a sale $earning = Commission::calculate($order); // Or with a specific agent $earning = Commission::calculate($order, $salesRep); // Use a specific plan $earning = Commission::forPlan('enterprise') ->calculate($order); // Bulk calculation $earnings = Commission::calculateBatch($orders);
4. Team Split Commissions
Commission::split($order) ->between([ $primaryRep => ['percentage' => 60, 'role' => 'primary'], $supportRep => ['percentage' => 25, 'role' => 'support'], $manager => ['percentage' => 15, 'role' => 'manager'], ]) ->calculate();
5. Handle Clawbacks
use SalesCommission\Services\ClawbackService; $clawbackService = app(ClawbackService::class); // Full clawback $clawback = $clawbackService->clawback($earning, 'refund'); // Partial clawback $clawback = $clawbackService->partialClawback($earning, 50.00, 'partial_refund'); // Clawback all commissions for an order $clawbacks = $clawbackService->clawbackForCommissionable($order, 'chargeback');
6. Process Payouts
use SalesCommission\Models\Payout; // Generate payout for current period $payout = Payout::generate('2026-01'); // Approve and process $payout->approve(auth()->id()); $payout->markAsPaid([ 'reference' => 'PAY-12345', 'method' => 'stripe', ]);
Or use the artisan command:
php artisan commission:process-payouts --period=2026-01
Events
Listen to commission events in your application:
// EventServiceProvider protected $listen = [ \SalesCommission\Events\CommissionEarned::class => [ NotifySalesRep::class, UpdateLeaderboard::class, ], \SalesCommission\Events\CommissionClawedBack::class => [ NotifyFinanceTeam::class, ], \SalesCommission\Events\PayoutProcessed::class => [ SendPayoutConfirmation::class, ], \SalesCommission\Events\TierAchieved::class => [ CelebrateTierUpgrade::class, ], ];
Artisan Commands
# Process payouts php artisan commission:process-payouts --period=2024-01 php artisan commission:process-payouts --dry-run # Recalculate tiers php artisan commission:recalculate-tiers --all php artisan commission:recalculate-tiers --plan=standard
Configuration
See config/sales-commission.php for all options:
return [ 'models' => [ 'agent' => App\Models\User::class, ], 'clawback' => [ 'enabled' => true, 'grace_period_days' => 30, 'auto_on_refund' => true, ], 'payout' => [ 'min_threshold' => 50.00, 'auto_approve' => false, 'schedule' => 'monthly', 'hold_period_days' => 14, ], 'currency' => 'USD', ];
Custom Rules
Create custom commission rules:
use SalesCommission\Rules\BaseRule; use SalesCommission\Contracts\Commissionable; use SalesCommission\Contracts\CommissionAgent; class FirstSaleBonusRule extends BaseRule { public function getType(): string { return 'first_sale_bonus'; } public function calculate(Commissionable $commissionable, CommissionAgent $agent, array $context = []): float { // Check if this is the agent's first sale if ($agent->commissionEarnings()->count() === 0) { return 100.00; // $100 bonus } return 0; } }
Testing
composer test
Admin Dashboard (Filament)
This package includes a beautiful admin panel powered by Filament:
// In your Filament PanelProvider use SalesCommission\Pro\Filament\SalesCommissionPlugin; public function panel(Panel $panel): Panel { return $panel // ... ->plugins([ SalesCommissionPlugin::make(), ]); }
Features include:
- View all commission plans and tiers
- Track earnings by agent, period, status
- Approve and process payouts
- Generate reports
- Manage clawbacks
API Endpoints
RESTful API endpoints are available at /api/commissions:
GET/POST /api/commissions/plans- Manage commission plansGET /api/commissions/earnings- View earningsPOST /api/commissions/calculate- Calculate commissionsGET/POST /api/commissions/payouts- Manage payoutsGET /api/commissions/stats/overview- Get stats
API documentation available at /api/commissions/docs.
Support the Project
If this package helps you, please consider giving it a ⭐ on GitHub - it helps others discover the project!
Author
Ayangzy - GitHub
License
The MIT License (MIT). Please see LICENSE.md for more information.
ayangzy/laravel-sales-commission 适用场景与选型建议
ayangzy/laravel-sales-commission 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 36 次下载、GitHub Stars 达 4, 最近一次更新时间为 2026 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sales」 「laravel」 「saas」 「commission」 「payout」 「earnings」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ayangzy/laravel-sales-commission 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ayangzy/laravel-sales-commission 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ayangzy/laravel-sales-commission 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Laravel Plans is a package for SaaS apps that need management over plans, features, subscriptions, events for plans or limited, countable features.
Integrate Kund24 Api
Paquete adicional de Ventas para Solunes Digital.
Asaas.com PHP API v3 Wrapper
Adaptaçao Asaas.com PHP API Wrapper para PHP 5.6
The «Sales Documents Numeration» extension for Magento 2
统计信息
- 总下载量: 36
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-10