API and data model
Every affiliate endpoint with its permission, the six database tables and what is unique about each, the hourly evaluation job, and the settings keys the engine reads.
Every route in this addon lives under /api/affiliate or
/api/admin/affiliate. Nothing is served from /api/mlm — that path exists in
the licensing route map but has no handlers behind it.
Member endpoints
Five of these answer without a session: the statistics, the landing page, the rates, the member's own standing (which tells a visitor which switches are set) and the Referral Program. All five read the session when there is one, because what they send depends on who is asking. The rest need a session, and all of them scope their data to the calling user — there is no way for a member to read somebody else's downline or rewards.
Admin endpoints
Referrals
Conditions
A condition that has paid cannot be deleted, because the reward table cascades on the condition: deleting it would delete every reward written under it, claimed ones included, and with them the record of what the affiliates were paid. The delete takes a row lock on the condition and does the count and the delete in one transaction, so a reward written a millisecond earlier is counted.
Applications
Rewards
Reward payout
The four payout settings are saved through the platform settings endpoint like every other key, and only a Super Admin can change them. It refuses a token that is not an active ecosystem token.
Core endpoints the add-on relies on
Two routes outside /api/affiliate take part, and both belong to core.
ref field, a user id or a personal code, once, when the account is created. A reference that names nobody creates the account with no referrerDatabase tables
Six tables, all prefixed mlm_.
mlm_referral
Who referred whom. referrerId, referredId, status of PENDING / ACTIVE
/ REJECTED. Soft-deleting.
Two unique indexes, and they matter:
referredIdis unique. A user can be somebody's referral exactly once, ever. Sponsors cannot be re-assigned, and a soft-deleted row still holds the slot.(referrerId, referredId)is unique. A relationship cannot be duplicated.
A row where referrerId equals referredId is a self-referral: it marks the
top of a chain and is created automatically for members who need a tree root.
The upline walk stops when it reaches one.
mlm_affiliate
Who is an affiliate: one row per member who applied, was added by an admin or
chose a code. userId is unique and code is unique (null repeats), so
a member has one standing and a code has one holder. status is PENDING,
APPROVED or REJECTED; code is 3 to 32 characters of A–Z, 0–9, _ and
-, stored in capitals; message is what the applicant wrote and reviewNote
what the reviewer wrote back (up to 500 characters); reviewedAt and
reviewedBy stamp the decision, the latter a plain id with no foreign key so it
outlives the admin.
It is not soft-deleting, on purpose: a soft-deleted row would keep its user
and its code, so a revoked affiliate could never apply again and their code could
never be given to anyone else. Revoking only marks the row REJECTED (the code
stays reserved to that member and stops resolving); deleting the standing
removes the row. On an install that has not switched on applications, every
member counts as approved without a row; a row is created the first time
somebody chooses a code.
mlm_referral_condition
The commission rules. Unique on name. Not soft-deleting and carrying no
timestamps. Conditions are edited in place; one that is switched off and has
never paid can be deleted, and one that has paid cannot, because the reward table
cascades on it.
Notable columns: type (16-value enum driving the ledger scan), reward and
rewardType, rewardWalletType / rewardCurrency / rewardChain (what the
reward is worth, and where it lands unless every reward is paid in the reward
token), minAmount (a floor on each transaction), status, and period
(DAILY by default; settable on the condition).
The program and schedule columns: program (AFFILIATE by default, or
REFERRAL), scheduleType (LIFETIME by default, INTERVAL or ONE_TIME),
intervalDays (30) and intervalCount (0, no limit) for INTERVAL,
targetAmount (0) — what a referred member's activity must add up to in one
window —, referredReward (0) — the friend's share, in the same type and unit as
reward — and firesOn, the event a condition is paid at when that is not its
own name. They arrive with one schema sync; a row from before it reads as an
Affiliate Program, every-time condition with no target and no share, which is
exactly what it always was.
mlm_referral_reward
Earned commissions. referrerId, conditionId, reward (a DOUBLE),
currency and walletType (what the reward is paid in), isClaimed, and
sourceId. Soft-deleting.
currency and walletType are set when the reward is written: the condition's,
or the reward token and ECO when rewards are paid in a token. The claim pays
exactly that, so a reward never changes currency after it is earned. Rows
written before Core 6.8.6 are filled from their condition by the update's
seeder; a row still NULL there is paid in its condition's currency.
sourceId is unique and is the whole of the duplicate protection. The
hourly evaluator writes condition_referrer_referred_period, or
condition_referrer_referred_I<window> for an every-N-days condition; a one-time
condition writes <condition>:once:<referred>; the multi-level event path
appends :L1, :L2 and so on; the friend's share appends :RF to the
referrer's key; and a condition that rides on an event it does not own writes
<event key>:<condition id>. MySQL permits multiple NULLs in a unique index, so
rewards created without one are unaffected — those fall back to a 60-second,
same-amount duplicate check instead.
Deleting a reward keeps its sourceId, so the evaluator will not recreate it.
mlm_binary_node and mlm_unilevel_node
Tree placement. Both are unique on referralId — one node per referral — and
neither carries timestamps.
mlm_binary_node holds parentId, leftChildId and rightChildId.
mlm_unilevel_node holds only parentId and allows any number of children.
Both payout paths walk mlm_referral.referrerId. These two tables exist to draw
the network diagram. Deleting rows from them corrupts the member-facing tree and
changes nobody's earnings.
The scheduled job
One job, registered only while the mlm extension is enabled and deregistered
within a scheduler cycle when you switch it off — no restart needed either way.
| Property | Value |
|---|---|
| Name | processMlmReferralConditions |
| Title | Process MLM Referral Conditions |
| Category | mlm |
| Interval | Hourly |
| Writes | Reward rows, and empty payout wallets for referrers |
| Reads | Active conditions, active referrals, which referrers are approved affiliates, referred users' wallets and completed transactions |
It never moves money. It creates reward rows and, alongside a new reward, the referrer's payout wallet if they do not have one — so a member is never blocked at claim time for want of a wallet row.
Each run evaluates both the current window and the one just completed — calendar
periods for an every-time condition, a referred member's N-day windows for an
every-N-days one — and reads each one-time condition's unsettled members since they
joined. That double pass is why the deterministic sourceId matters: without it,
the re-scan would pay everything twice. It skips the event-paid conditions, and
the Referral Program's conditions while applications are not required.
Its log is the addon's best diagnostic. It names each reward it creates, each condition it skipped and why, currencies it could not price, and the case where none of the referred users hold any wallet at all. Configuration warnings are rate-limited to roughly every four hours so one misconfiguration across forty conditions produces one line rather than eighty.
Settings the engine reads
All stored as text in the platform settings table.
| Key | Read by |
|---|---|
affiliateMlmSystem |
Structure selection — DIRECT, BINARY, UNILEVEL |
affiliateBinaryLevels |
Level count under BINARY (2–7) |
affiliateBinaryLevel1 … affiliateBinaryLevel7 |
Per-level share under BINARY |
affiliateUnilevelLevels |
Level count under UNILEVEL (2–7) |
affiliateUnilevelLevel1 … affiliateUnilevelLevel7 |
Per-level share under UNILEVEL |
affiliateRequireApproval |
Whether new referrals start PENDING |
affiliateApplicationRequired |
Whether a member must be approved to be an affiliate. Absent or anything but true is the open program |
affiliateShowCommissions |
Whether the rates are shown to everyone. Absent means shown; only an explicit false hides them |
affiliateMaxCommissionRate |
Ceiling on PERCENTAGE condition rewards |
affiliatePayoutThreshold |
Minimum unclaimed balance before claiming, in USD |
affiliateRewardPayoutMode |
CONDITION (each condition's currency) or TOKEN (one ecosystem token) |
affiliateRewardToken |
The ecosystem token code rewards are paid in |
affiliateRewardTokenPriceSource |
MARKET, FIXED or MARKET_OR_FIXED |
affiliateRewardTokenUsdPrice |
USD per token for the fixed price |
Two legacy keys are still read as a fallback when the current ones are absent:
mlmSystem (the structure) and mlmSettings (a JSON blob containing both level
configurations, with the values stored as strings). Saving the settings screen
once writes the current keys, which then take precedence.
Full descriptions and consequences: Programme settings.
Where commissions are triggered from
Event-driven conditions are fired by the code that processed the activity, in core and in other addons. Which means: an addon you do not own cannot pay its commission, and disabling an addon stops its rules firing without disabling the conditions themselves. Those conditions stay active and stay invisible to members, because the members' rates page filters by enabled extension.
The one exception to "conditions belong to addons" is the core set — deposits, spot and binary trading, and investments — which is always available.