Section 1, Project Payment Function Practice - WeChat Payment Project Function Design and Library Table Script

Project requirements

The main business of the project is the second-hand car bidding business, which is similar to auction software such as Alibaba Auction and Youxinpai. The specific bidding process is as follows:

  1. User registration mini program account
  2. User real-name information authentication
  3. User pays deposit
  4. Participate in the auction

Margin business concept

When talking about margin business, it is generally linked to the account system. Let’s first talk about the scenarios involved in the use of margin business: The margin system refers to a system established in some trading scenarios to ensure the performance of transactions and risk control. A fund management mechanism. The account system refers to a collection of user information and financial information established in Internet products to identify and manage users. To put it simply, margin is a cushion of funds used by the platform to constrain the behavior of actors and avoid losses to the platform/platform users.

Design process of margin business

The general process is mainly divided into margin account opening process, margin payment process, and margin withdrawal process.
Margin account opening : Margin account opening is relatively simple. The margin system provides an interface for account opening. Business logic such as opening nodes and opening verification are all formulated by the business side.
Margin payment/recharge : The margin payment process is relatively simple and is similar to the account recharge system. The basic process is the same. Here we will talk about some of the lower-level logic under the margin payment process, which mainly includes the formulation of margin payment rules, matching of margin payment rules, etc.
Margin withdrawal: The deposit recharge adopts the order/transaction method to collect payment. There are two implementation solutions for user withdrawals, one is refund and the other is payment. Of the two, the payment solution is more flexible and has simpler logic. , the refund plan is too restrictive. For example, three-party refunds are time-limited and cannot be refunded after a certain period of time. Some workers will let others pay on their behalf. If refunds are used, funds will be confused, etc. The flow chart of margin withdrawal is as follows:
Insert image description here

  • Process: The process of the margin system generally includes the following steps:
    1. Before participating in a certain transaction, users need to pay a certain percentage or amount of deposit to the platform or a third-party payment institution as a guarantee for the transaction.
    2. During the transaction process, the user may need to increase or decrease the margin according to the changes in the transaction to maintain the security of the transaction.
    3. After the transaction is completed, the user may receive a return or deduction of the deposit, or a partial return or deduction, based on the result of the transaction.
    4. In the process of collecting, managing and returning deposits, platforms or third-party payment institutions need to conduct strict risk control and supervision to prevent the misappropriation, loss or abuse of deposits.
  • System: The system of margin system generally includes the following elements:
    1. Margin account: An account used to record the deposit, change and return of the user's margin. It is generally a virtual account and corresponds to the user's actual fund account.
    2. Margin rules: Rules used to stipulate the proportion or amount of margin that users need to pay, as well as the conditions and methods for the addition, deduction and return of margin. They are generally formulated by the platform or a third-party payment institution, and may also be negotiated and determined by both parties to the transaction.
    3. Margin risk control: used to monitor and control margin risks, including risk control of margin adequacy, security and compliance. It is generally the responsibility of the platform or a third-party payment institution, and may also be participated by regulatory agencies or third-party institutions.
  • Architecture: The architecture of the margin system generally includes the following modules:
    1. Margin collection and payment module: used to realize the function of depositing and returning user's margin. Generally, it needs to connect with the payment channels of banks or third-party payment institutions to realize the transfer and settlement of funds.
    2. Margin accounting module: used to realize the function of changing and querying the user's margin. It generally needs to be connected to the account system of the platform or a third-party payment institution to achieve the recording and management of funds.
    3. Margin rule module: used to realize the function of calculating and executing the user's margin. It generally needs to be connected to the business system of the platform or a third-party payment institution to achieve the setting and triggering of rules.
    4. Margin risk control module: used to implement the function of monitoring and controlling the user's margin. It generally needs to be connected to the risk control system of the platform or a third-party payment institution to achieve risk assessment and early warning.

The following figure shows the margin system architecture diagram.
Insert image description here

Account system

The process, system and structure of the account system:

  • Process: The process of the account system generally includes the following steps:
    1. Before using an Internet product, users need to register an account, which serves as the user's unique identification and credentials.
    2. After logging in to the account, users can perform various business operations, such as recharge, consumption, transfer, cash withdrawal, etc., as well as view and modify personal information, account information, accounting information, etc.
    3. After logging out of the account, the user can keep or delete the account, and retrieve or reset the account password or other information.
  • System: The system of the account system generally includes the following elements:
    1. Account information: used to record the user's basic information, such as user name, password, mobile phone number, email, etc., as well as the status, type, level, etc. of the account. It is generally filled in or modified by the user, or may be filled in or modified by the platform or a third-party payment institution. Authentication or authorization.
    2. Account information: used to record the user's fund information, such as balance, points, coupons, etc., as well as account attributes, limits, rules, etc., which are generally generated or managed by the platform or a third-party payment institution, or may be operated or set by the user themselves .
    3. Account information: used to record the user's fund changes, such as recharge, consumption, transfer, cash withdrawal, etc., as well as the account serial number, time, amount, status, etc., which are generally recorded or processed by the platform or a third-party payment institution, and also Users may make inquiries or appeals on their own.
  • Architecture: The architecture of the account system generally includes the following modules:
    1. Account management module: used to realize functions such as registration, login, logout, retrieval, and modification of user accounts. It generally needs to be connected to the user system of the platform or a third-party payment institution to achieve user identification and authentication.
    2. Account management module: used to realize functions such as recharge, consumption, transfer, and cash withdrawal of users' accounts. It generally needs to be connected to the account system of the platform or a third-party payment institution to achieve the recording and management of funds.
    3. Account management module: used to implement functions such as inquiry, appeal, verification, and reconciliation of users' accounts. It generally needs to be connected to the accounting system of the platform or a third-party payment institution to realize changes and inquiries of funds.
    4. Account risk control module: used to realize the security and compliance functions of users' accounts. It generally needs to be connected to the risk control system of the platform or third-party payment institution to achieve account monitoring and control.

The difference and connection between the margin system and the account system:

  • Difference: The difference between the margin system and the account system mainly lies in the following aspects:
    1. Purpose: The purpose of the margin system is to ensure the execution of transactions and risk control, while the purpose of the account system is to identify and manage users.
    2. Scope: The scope of the margin system is for some specific trading scenarios, such as futures, foreign exchange, P2P, etc., while the scope of the account system is for all Internet products.
    3. Form: The form of the margin system is a fund management mechanism, while the form of the account system is a collection of user information and fund information.
    4. Rules: The rules of the margin system are formulated by the platform or a third-party payment institution, or may be determined by negotiation between the parties to the transaction, while the rules of the account system are formulated by the platform or a third-party payment institution, or may be set by the user themselves.
  • Contact: The connection between the margin system and the account system mainly lies in the following aspects:
    1. Association: The margin system and the account system are related to each other, because the user's margin is stored in the user's account, and the user's account is identified and managed through the user's account. Therefore, the margin system and the account system need to be coordinated and coordinated to achieve smooth transactions and convenient use by users. For example, when paying or returning a deposit, users need to log in to their account through their account, then select the payment channel and amount to transfer and settle funds. When users inquire or change the margin, they also need to log in to the account through the account, and then view or modify the margin account information to record and manage the funds. When users participate in or withdraw from transactions, they also need to log in to their accounts through their accounts, and then trigger or execute margin rules to calculate and return funds.

Project function logic design

Above we have understood the business concepts related to margin and account systems. Now let’s actually get into how to design the margin system and select payment channels.

In the margin payment business of this project, we first need to establish a virtual business account for the margin user. The purpose of this business account is to display the total amount, available balance and frozen amount of the user's account. For simplicity, we choose to connect WeChat payment and WeChat refund. Payment is the user's recharge, and refund is the user's cash withdrawal. The margin virtual account mentioned here is not a third-party capital account, but uses a database to create a table instead of an account, that is, a table is created in the database to store the user's actual fund flow.

After the deposit is paid, users will first check whether the available balance of the deposit is sufficient when participating in the auction. If it is sufficient, they can participate in the bidding. After bidding, a part of the deposit will be frozen according to the business bidding rules, and a frozen amount will be generated. At this time, the frozen amount + available balance = total margin amount. The frozen amount will be automatically unfrozen when the user completes the transaction or fails to win the bid. When unfrozen, the frozen amount will be deducted and the available balance will be increased.

Margin function design

1. Display of user account information, mainly including total amount, available balance, and frozen amount. The total amount = available + frozen amount
2. User recharge: Recharge is mainly to activate the logic of WeChat payment
3. User refund: Refund is based on the order paid by the user. Refund can be divided into two methods. The amount of the refunded order ,Partial refund.
4. Margin usage records: Displays the user’s margin usage records, including records of freezing, thawing, payment, cash withdrawal (refund), etc.
5. Deposit refund progress: Shows the processing progress after submitting the refund application. After the user submits the refund application, it will be submitted to the finance department for review. After the review is passed, the WeChat refund interface will be called up for refund.

Library table design

  • Margin user account table: USER_ACCOUNT
  • Margin usage record table: USE_RECORD
  • Margin payment order form: ORDER_INFO
  • Deposit payment schedule: PAYMENT_RECORD
  • Margin withdrawal application form: REFUND_APPLICATION. The user initiates a withdrawal application in the app or mini program and submits it to the seller for review.
  • Margin refund order table: REFUND_INFO. This table is mainly the refund order information generated when the WeChat refund order is called up. The status of the refund order will be updated after the WeChat callback.
  • Exception information table: ERROR_LOG When a business exception occurs, the wrong business type needs to be saved in the exception table to prepare for subsequent manual exception handling.

User account creation table sql

create table USER_AMOUNT
(
    ID               varchar(32)          not null comment '唯一ID'
        primary key,
    TOTAL_MONEY      decimal(16, 2)       null comment '保证金总金额',
    AVAIL_MONEY      decimal(16, 2)       null comment '可用余额',
    FROZEN_MONEY     decimal(16, 2)       null comment '冻结金额',
    USER_ID          varchar(32)          null comment '用户id',
    CREATE_BY        varchar(32)          null comment '创建人id',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_TIME      datetime             null comment '创建时间/报价时间',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间'
)
    comment '保证金账户表';

Margin usage record creation table sql

create table USE_RECORD
(
    ID               varchar(32)          not null comment '记录id'
        primary key,
    EVENT_STATUS     varchar(32)          null comment '保证金使用状态(0 冻结,1,解冻,2 保证金扣减,3 充值,4 退款)',
    USE_MONEY        decimal(16, 2)       null comment '使用金额/充值金额',
    TOTAL_MONEY      decimal(16, 2)       null comment '保证金总金额',
    AVAIL_MONEY      decimal(16, 2)       null comment '可用余额',
    FROZEN_MONEY     decimal(16, 2)       null comment '冻结金额',
    USER_ID          varchar(32)          null comment '用户id',
    REG_ID           varchar(32)          null comment '报名记录id',
    PAY_TRADE_NO     varchar(50)          null comment '交易单号(充值退款时使用该字段)(充值时代表订单号、退款时代表退款单号)',
    ACTUAL_TIME      datetime             null comment '业务数据插入的实际操作时间。如果保证金使用记录表出现异常,
处理成功后插入异常时间作为业务操作时间',
    EVENT_DESC       varchar(255)         null comment '备注/充值异常原因/业务操作描述',
    CREATE_BY        varchar(32)          null comment '创建人id',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_TIME      datetime             null comment '创建时间/报价时间',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间'
)
    comment '保证金使用记录';

Deposit payment order form

create table ORDER_INFO
(
    ID               varchar(32)          not null comment '订单ID'
        primary key,
    ORDER_TITLE      varchar(64)          null comment '订单标题/名称',
    ORDER_NO         varchar(50)          null comment '商户订单编号',
    USER_ID          varchar(32)          null comment '用户id',
    TOTAL_FEE        bigint               null comment '订单金额(分)',
    CODE_URL         varchar(50)          null comment '订单二维码连接(Native支付时使用)',
    ORDER_STATUS     varchar(20)          null comment '订单状态(NOTPAY:未支付、SUCCESS:支付成功、CLOSED:超时已关闭、CANCEL:用户已取消)、
                REFUND_PROCESSING:退款中、退款成功、退款异常)',
    REFUND_FEE       bigint               null comment '当前订单已退金额(分)',
    REFUND_STATUS    varchar(32)          null comment 'REFUND_SUCCESS:已全部退款、
REFUND_PART:部分退款
、NO_REFUND:未退款',
    PREPAY_ID        varchar(64)          null comment '预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时',
    PREPAY_RESPONSE  text                 null comment '支付下单响应数据',
    ERROR_CODE       varchar(20)          null comment '业务错误码',
    ERROR_DESC       varchar(64)          null comment '业务错误描述',
    REMARK           varchar(120)         null comment '备注',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_BY        varchar(32)          null comment '创建人id',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间',
    TRADE_STATE      varchar(50)          null comment '用户前端支付状态用于判断是否能再次支付默认为未支付(NOTPAY),成功(SUCCESS)'
)
    comment '保证金订单信息';

Deposit payment flow record creation table sql

create table PAYMENT_RECORD
(
    ID               varchar(32)          not null comment '支付记录id'
        primary key,
    ORDER_NO         varchar(50)          null comment '商户订单编号',
    TRANSACTION_ID   varchar(50)          null comment '支付系统交易编号',
    PAYMENT_TYPE     varchar(20)          null comment '支付类型(微信)',
    TRADE_TYPE       varchar(20)          null comment '交易类型(小程序、H5、native、js,app,公众号)',
    TRADE_STATE      varchar(50)          null comment '交易状态(SUCCESS:支付成功
REFUND:转入退款
NOTPAY:未支付
CLOSED:已关闭
REVOKED:已撤销(付款码支付)
USERPAYING:用户支付中(付款码支付)
PAYERROR:支付失败(其他原因,如银行返回失败))',
    PAYER_TOTAL      bigint               null comment '支付金额(分)',
    REMARK           varchar(200)         null comment '备注',
    CONTENT          text                 null comment '通知参数',
    CREATE_BY        varchar(32)          null comment '创建人id',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_TIME      datetime             null comment '创建时间/报价时间',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间'
)
    comment '保证金支付记录信息';

Refund application form creation sql

-- auto-generated definition
create table REFUND_APPLICATION
(
    ID                    varchar(32)          not null comment '退款申请单ID'
        primary key,
    REFUND_APPLICATION_NO varchar(50)          null comment '退款申请单编号',
    MONEY                 decimal(16, 2)       null comment '提现金额',
    PHONE                 varchar(32)          null comment '申请人手机号',
    CURRENT_TACHE         varchar(12)          null comment '当前环节( XJ :发起申请、JLSH:经理审核、CWSH:财务审核、GD:归档)',
    ACTUAL_REFUND_STATUS  varchar(32)          null comment '实际退款状态(SUCCESS退款成功,ABNORMAL退款失败,NO_REFUND默认值,未退款、CLOSED 退款关闭)',
    AUDIT_STATUS          varchar(6)           null comment '审核状态(DSH:待审核、BTG:审核不通过、TG:审核通过)',
    USER_ID               varchar(32)          null comment '用户id',
    ORDER_NO              varchar(50)          null comment '商户订单号',
    ACTUAL_REFUND_TIME    datetime             null comment '实际退款时间',
    REMARK                varchar(200)         null comment '备注/业务单失败原因/经理审核驳回时记录驳回原因',
    CREATE_NAME           varchar(32)          null comment '创建人姓名',
    CREATE_TIME           datetime             null comment '创建时间/报价时间',
    UPDATE_BY             varchar(32)          null comment '修改人',
    UPDATE_NAME           varchar(32)          null comment '修改人姓名',
    UPDATE_TIME           datetime             null comment '修改时间'
)
    comment '保证金退款申请单';

Refund order record creation table sql

-- auto-generated definition
create table REFUND_INFO
(
    ID               varchar(32)          not null comment '退款单ID'
        primary key,
    ORDER_NO         varchar(50)          null comment '商户订单编号',
    REFUND_NO        varchar(50)          null comment '商户退款单编号',
    REFUND_ID        varchar(50)          null comment '支付系统退款单号',
    TOTAL_FEE        bigint               null comment '原订单金额(分)',
    REFUND           bigint               null comment '退款金额(分)',
    REASON           varchar(50)          null comment '退款原因',
    REFUND_STATUS    varchar(32)          null comment '退款状态',
    CONTENT_RETURN   text                 null comment '申请退款返回参数',
    CONTENT_NOTIFY   text                 null comment '退款结果通知参数',
    REFUND_TIME      datetime             null comment '退款时间',
    REFUND_APP_ID    varchar(32)          null comment '退款申请单ID',
    CREATE_BY        varchar(32)          null comment '创建人id',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_TIME      datetime             null comment '创建时间/报价时间',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间'
)
    comment '保证金退款记录';

Exception information table creation sql

create table ERROR_LOG
(
    ID               varchar(32)          not null comment '唯一主键ID'
        primary key,
    USER_ID          varchar(32)          null comment '用户id',
    EVENT_TYPE       varchar(20)          null comment '操作类型:充值(支付):PAY、提现(退款):REFUND',
    ERROR_CODE       varchar(20)          null comment '业务错误码(AMOUNT:更新余额,USERECORD:插入保证金记录)',
    ERROR_DESC       varchar(500)         null comment '业务错误描述(更新余额失败、插入保证金使用记录失败)',
    PAY_TRADE_NO     varchar(50)          null comment '关联交易单号',
    REMARK           varchar(120)         null comment '备注',
    CREATE_NAME      varchar(32)          null comment '创建人姓名',
    CREATE_BY        varchar(32)          null comment '创建人id',
    UPDATE_BY        varchar(32)          null comment '修改人',
    UPDATE_NAME      varchar(32)          null comment '修改人姓名',
    UPDATE_TIME      datetime             null comment '修改时间'
)
    comment '异常信息';

Summarize

This article mainly introduces the business concepts, project requirements, margin system architecture and recharge, withdrawal and other processes related to margin. Finally, the code and script of the functional design are posted. In the next section, we will introduce the security architecture design in the system architecture.

Guess you like

Origin blog.csdn.net/superzhang6666/article/details/134775292