Backend Development 13 min read

Design and Implementation of a CPS-Based Promotion System with Settlement and Commission Calculation

The article presents a CPS‑based promotion system for the beauty sector that lets promoters instantly view orders and commissions, employs a responsibility‑chain clearing design and a parent‑child settlement model for delayed‑consumption products, and outlines a scheduled settlement workflow that securely transfers funds from merchants to promoters.

Youzan Coder
Youzan Coder
Youzan Coder
Design and Implementation of a CPS-Based Promotion System with Settlement and Commission Calculation

This article introduces the CPS (Cost Per Sale) model, which converts the actual number of sold products into advertising fees and charges per order or transaction. In the beauty industry, promoters help merchants sell products and earn commissions, making CPS a suitable marketing approach.

The Youzan Beauty promotion system enables merchants to turn employees, customers, and partners into promoters who use their social networks to drive sales. Orders generated through promoters account for more than 50% of total marketing orders, but several issues can cause disputes between merchants and promoters.

Problem Description

Promoters cannot see the orders they generated or the commissions they are owed immediately after a customer places an order, especially for delayed‑delivery items.

The settlement of promotion orders lacks flexibility.

The article proposes solutions to these problems.

Business Model

The system consists of promoters, promoter groups, promoted products, promotion orders, and their binding relationships. Underlying modules such as members, transactions, products, stores, and finance support the promotion system.

Solution Overview

Concepts

Three financial processes are defined:

Clear‑division (清分): Classify transaction data by institution and type, then calculate settlement amounts. Clearance (清算): Net the classified amounts and execute fund transfers. Settlement (结算): Transfer funds according to clearance instructions.

Ordinary Product Settlement Flow

When a promoter’s customer pays for an order, the promoter should see the order and commission immediately. The proposed flow is:

User places and pays for an order; a payment message is sent.

A message‑queue consumer receives the payment message.

The order is fetched and transformed into a settlement entity.

The clearing process evaluates conditions and calculates commissions.

The settlement record is persisted.

This design, however, mixes many responsibilities, violating the Open/Closed Principle.

Improved Flow with Responsibility Chain

By extracting each responsibility (promoter identity verification, postage handling, discount handling, commission calculation) into separate chain nodes, new rules can be added without modifying existing code.

User places and pays for an order; a payment message is sent.

Message‑queue consumer receives the payment message.

Order is transformed into a business object required by the promoter system.

The clearing process starts a responsibility‑chain handling:

The final settlement record is stored.

Delayed‑Consumption (e.g., Card) Settlement Flow

For products like multi‑use cards, immediate commission calculation poses a risk if the customer later requests a refund. A parent‑child settlement model is introduced:

Purchase of a card generates a parent settlement record that is not settled immediately.

Each time the card is used, a child settlement record is created and linked to the parent.

Only the child record is settled, protecting the merchant’s interests.

Final Settlement Process

After the clearing stage, settlement records enter a “pending settlement” state. A scheduled task scans these records, checks whether the current accounting period allows settlement, and then:

Generates a settlement record.

Sends an asynchronous message.

Processes the message, invoking the settlement method.

Calls the financial middle‑platform’s profit‑sharing API to debit the merchant and credit the promoter.

This completes a full closed‑loop for promoter order processing, from order creation to commission payout.

Conclusion

The article demonstrates how to address promoter‑related problems by applying clear‑division, clearance, and settlement processes, and by using the responsibility‑chain pattern to keep the clearing logic extensible. While the core workflow is covered, additional edge cases such as failure handling and reconciliation remain for future work.

Backendsettlementresponsibility chainbusiness modelcommissionCPS
Youzan Coder
Written by

Youzan Coder

Official Youzan tech channel, delivering technical insights and occasional daily updates from the Youzan tech team.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.