Download the PHP package hejunjie/trade-splitter without Composer
On this page you can find all versions of the php package hejunjie/trade-splitter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download hejunjie/trade-splitter
More information about hejunjie/trade-splitter
Files in hejunjie/trade-splitter
Package trade-splitter
Short Description 一个灵活、可扩展的交易/利润分账组件,提供百分比、固定金额、阶梯与递归分账等内置策略,并支持注册自定义策略 | A flexible and scalable transaction/profit sharing component, offering built-in strategies such as percentage, fixed amount, tiered, and recursive sharing, and supporting the registration of custom strategies
License MIT
Informations about the package trade-splitter
PHP Trade Splitter
A flexible and extensible trade/profit distribution component.
Built-in strategies include Percentage, Fixed Amount, Ladder, and Recursive, and you can easily register custom strategies.
Perfect for multi-level commissions, e-commerce settlements, platform fees, and agent profit sharing.
This project has been parsed by Zread. If you need a quick overview of the project, you can click here to view it:Understand this project
✨ Features
- 🔧 Multiple Strategies – 4 common built-in distribution modes
- 🧩 Extensible Design – easily register your own strategy
- ⚡ Simple to Use – one static method does it all
- 🧠 Clean Architecture – object-oriented with the Strategy pattern
📦 Installation
🚀 Quick Start
Example output:
🧩 Core Concepts
| Concept | Description |
|---|---|
| Splitter | The main entry point — selects the strategy and performs the split |
| StrategyInterface | Contract every strategy must implement:split(SplitContext $context): array |
| SplitContext | Contains the split context (totalandparticipants) |
| Allocation | Represents a split result withname,amount, andratio; providestoArray() |
🧮 Built-in Strategies
Percentage Split percentage
Distributes amounts by percentage. The sum of all rate values must equal 1.0.
Fixed Amount Split fixed
Splits by fixed amounts. The total of all fixed values must not exceed the total amount.
Ladder Split ladder
Applies different percentage rates based on amount tiers.
Use null for no upper limit.
Recursive Split recursive
Each level’s share is calculated based on the remaining amount from the previous level.
Useful for multi-tier agent or channel commission systems.
🧠 Custom Strategy
Implement the Hejunjie\TradeSplitter\Contracts\StrategyInterface and register it:
🧪 Run the Demo
A demo script is included in the repository:
This script demonstrates all four built-in strategies.
💡 Motivation
This component was born from my frustration with rigid, hard-coded profit-sharing logic in various projects.
I wanted a clear, pluggable, and reusable solution that could be integrated into any project — without reinventing the wheel each time.
If you’ve encountered strange or complex split scenarios in your business,
feel free to collaborate and help make this tool even more powerful!
🤝 Contributing
Got ideas, feedback, or found a bug? PRs and Issues are always welcome 🙌
If you find this project helpful, please consider giving it a ⭐ Star — that’s the biggest motivation for me to keep improving it!