SpringBoot actual combat e-commerce project mall (18K + STAR) Address: github.com/macrozheng/…
Abstract
This paper mainly analyzes the shopping cart function related table, introduces the whole process from adding goods to shopping cart to placing an order, involving shopping cart discount calculation process, confirmation form generation process, placing an order process and order cancellation process.
The cart table
Used to store the information of each commodity in the shopping cart, which can be used to calculate the amount of commodity discount.
create table oms_cart_item
(
id bigint not null auto_increment,
product_id bigint comment 'Product ID',
product_sku_id bigint comment 'Id of commodity SKU',
member_id bigint comment 'user id',
quantity int comment 'Purchase Quantity',
price decimal(10.2) comment 'Add price to cart',
sp1 varchar(200) comment 'Sales Attribute 1',
sp2 varchar(200) comment 'Sales Attribute 2',
sp3 varchar(200) comment 'Sales Attribute 3',
product_pic varchar(1000) comment 'Merchandise Master Chart',
product_name varchar(500) comment 'Trade Name',
product_brand varchar(200) comment 'Merchandise Brand',
product_sn varchar(200) comment 'Barcode of commodity',
product_sub_title varchar(500) comment 'Product subtitle (Selling point)',
product_sku_code varchar(200) comment 'Commodity SKU barcode',
member_nickname varchar(500) comment 'Member nickname',
create_date datetime comment 'Creation time',
modify_date datetime comment 'Modification time',
delete_status int(1) default 0 comment 'Delete or not',
product_category_id bigint comment 'Classification of goods',
product_attr varchar(500) comment 'commodity sales attributes: [{" key ":" color ", "value" : "silver"}, {" key ":" capacity ", "value" : "4 g"}]',
primary key (id));Copy the code
Shopping order process
Overall flow diagram
Mobile terminal process display
- Members select product specifications
- Select the items in the shopping cart to pay
- View confirmation sheet
- Payment order
- Pay for success
- To view the order
Implementation logic
Add to shopping cart
The main function of shopping cart is to store the information of goods selected by users and calculate the discount of goods in shopping cart.
Shopping cart discount calculation process
Relevant points to note
- Because the product discount is designed with the commodity as the unit, not the SKU as the unit, so it must be calculated with the commodity as the unit;
- The code implementation logic can refer to the calcCartPromotion method in the OmsPromotionServiceImpl class.
Generate confirmations
Confirmation sheet is mainly used for users to confirm the commodity information, discount information, price information, and select the delivery address, select coupons and use points.
Generate confirmation sheet flow
Relevant points to note
- Calculation of the total amount: the total value of all items in the shopping cart;
- Calculation of the activity discount: the discount amount of all goods in the shopping cart is accumulated;
- Calculation of amount payable: Amount payable = total amount – activity preference;
- Code implementation logic can reference OmsPortalOrderServiceImpl generateConfirmOrder method in class.
To generate orders
Process the information in the shopping cart and synthesize the information of users to generate orders.
Place the order process
Relevant points to note
- Inventory lock-in: Inventory has been acquired from shopping cart offers
pms_sku_stock
The lock_stock field represents the number of locked inventory. The number of items seen by the member is the real inventory minus the locked inventory. - Processing of decomposable amount of coupons: Calculate the decomposable amount of coupons for general use, designated categories and designated commodities:
- Universal: all orders in the shopping cart are evenly distributed;
- Designated classification: the goods in the shopping cart are evenly divided according to the classification;
- Designated items: The designated items contained in the shopping cart are evenly distributed.
- Calculation of the actual payment amount of each commodity in the order: original price – promotional offer – coupon deduction – integral deduction, promotional offer is the discount amount calculated in the process of shopping cart calculation;
- Order number generation: redis is used to generate the order number. The generation rule is as follows: 8-digit date + 2-digit platform number + 2-digit payment method + 6-digit self-increment ID;
- After the completion of the use of coupons need to modify the use of coupons;
- Code implementation logic can reference OmsPortalOrderServiceImpl generateOrder method in class.
Cancel the order
After the order is generated, you need to start a delay task to cancel the timed order.
Order Cancellation Process
Relevant points to note
- Code implementation logic can reference OmsPortalOrderServiceImpl cancelOrder method in class.
The public,
Mall project full set of learning tutorials serialized, attention to the public number the first time access.