Behind the top-up promotion
1. The background
In most game products, we will see a variety of recharge free similar activities, such as King of Glory. It also exists in other product classes.
The main purpose of demand is to ensure product flow, bring product revenue, and at the same time give users other satisfaction.
Get other rewards through recharge, for example, after recharge, there will be bonus points. Then these points can be exchanged for some other goods.
2. Business analysis of recharge promotion
Here is a simple analysis of the business:
- On the recharge interface, highlight the recharge gift logic;
- After users recharge, there will be corresponding recharge rewards to the account;
- Recharge strategy includes recharge every time, the first time every day, accumulative recharge, etc.
- Recharge free is not limited to points, happy coins, happy coins, etc.
- Ensure the scalability of recharge policies and giveaways
Figure 1 (Recharge interface: I can’t use Pinta, so I can only do this)
3. Program planning
1) Main directions
1. The promotion business depends on the recharge and payment business, so it is better not to affect the performance of the original recharge business
2. The background can manage the recharge strategy to facilitate the operation of the strategy
3. After the recharge to ensure that not more send and so on
2) Project architecture:
This business mainly involves two services: 1, payment system and 2, main business systems.
Figure 2(The entire Payment structure and main business processes)
Here is 3
- The solution,
Use the responsibility chain mode to connect the ordinary recharge and recharge gifting strategy business, use the strategy mode to determine the gifting, and asynchronously judge whether the promotion conditions are met after the user finishes the recharge. Mq can be used to uncouple related asynchronous operations, insert the recharge promotion to obtain records, and insert the corresponding complimentary flow table (such as the happy coin).
After the success of the business system receives the payment system, through the chain of responsibility to join common top-up and prepaid phone promotions, when implement the promotion business logic, by getting between the operation of prepaid phone sales promotion activity to determine what are the logical top-up, there will be other logic, in the execution logic is still use the strategy pattern to judgment call
Figure 3(Partition logic), drawing tools)
4. Logical design of database tables
Configuration table of recharge promotion activities:
field | The data type | instructions |
---|---|---|
id | bigint(20) | A primary key |
title | varchar(32) | Activity title |
icon | varchar(511) | Activity icon |
desc | varchar(255) | describe |
reward_type | int(11) | Given type |
reward_value | bigint(20) | Present numerical |
condition_value | bigInt(20) | Achieve the required value |
start_time | datatime | The start time |
end_time | datatime | The end of time |
create_time | datatime | Creation time |
create_admin_id | bigint(20) | Creating an Administrator ID |
is_delete | tinyint(1) | Whether or not to delete |
Record:
field | The data type | instructions |
---|---|---|
id | bigint(20) | A primary key |
user_id | bigint(20) | The user id |
type | int(11) | Reward type |
value | bigint(20) | Reward numerical |
create_time | datatime | Creation time |
is_delete | tinyint(1) | Whether or not to delete |
5. The relevant code
Ps: Make a note of it (fear of forgetting)
/ * * *@authorYi xian *@Description**/ in the chain of responsibility mode
@Slf4j
public abstract class PayCoin {
/** * Record a chain */
private PayCoin next;
/** * Adaptation service currency *@param payNoticeDto
* @return* /
private final void handlerCoin(PayNoticeDto payNoticeDto) {
// Todo implementation
// Continue processing if there is a next chain
if(Objects.nonNull(next)) { coinCount += next.handlerCoin(payNoticeDto); }}/** * Set the next chain */
protected void setNext(PayCoin payHandler) {
this.next = payHandler; }}Copy the code
/ * * *@authorYi xian *@DescriptionTODO context policy **/
@Service
public class RewardPayContext {
@Resource
private final Map<String, RewardPayStrategy> strategyMap = new ConcurrentHashMap<>();
/ * * * *@param map
*/
public RewardPayContext(Map<String, RewardPayStrategy> map){
this.strategyMap.clear();
map.forEach((k,v)->this.strategyMap.put(k,v));
}
/** * Obtain policy *@paramStrategyId Indicates the ID * of the policy@returnThe corresponding policy */
public RewardPayStrategy getStrategy(String strategyId){
returnstrategyMap.get(strategyId); }}Copy the code
/ * * *@authorYi xian *@DescriptionTODO policy pattern implementation **/
public interface RewardPayStrategy {
/** * A series of operations */
void todoString(CommonUserInfoDo commonUserInfoDo, PayNoticeDto payNoticeDto);
}
Copy the code