Java fresh e-commerce platform - in-depth thinking and practice of starting and sending price of e-commerce
Note: in fresh food e-commerce, starting and sending price is a very common topic. Today we will tell you how to set the starting and sending price, how to write the code of starting and sending price, and how to synchronize the starting and sending price.
Before we start, let's think about a few questions:
1. Business concept
1.1 what is the starting price?
The starting price is how much money you need for this order. For example, if you pay 15 yuan, you can't get 14 yuan.
1.2. Why is there a starting price?
First, to reduce costs
Suppose you wanted to buy two things. If you wanted to buy two things at any price, you might send them by parcel mail twice, using your manpower and money twice. But people who have package price usually choose to place an order together. This saves resources.
Second, to get more benefits
For example, if you buy a 10 yuan package for you, the profit may be only 4 yuan, but the cost of postage (Note: it's cost, non-profit price) may be 4 yuan or more. That's not a lot of money. And people tend to buy more products for free shipping.
Businessmen pay attention to benefits and costs. If you don't understand, think about these two aspects.
Because sellers also need to be profitable. If you buy too little, not enough road fare, then the seller is not dead.
1.3. It is reasonable to set the starting and sending price.
For fresh food e-commerce, this is very particular. It can't be set casually. In general, we actually use the average customer unit price, and then calculate a reasonable value at 2. Finally, we determine that our starting price is 58 yuan.
1.4. How to set the starting and sending price?
The starting and sending price cannot be written down. Because the company needs to be flexible and can change it at any time, but can't change it at will, it needs to have an APP to the management background to synchronize the process. When is the synchronization? How to synchronize?
1.4.1 data is written in the parameter table
1.4.2 every time the APP is started, this interface is called to cache the latest starting and sending price data locally.
CREATE TABLE `sys_params` ( `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'id', `param_code` varchar(32) DEFAULT NULL COMMENT 'Parameter coding', `param_value` varchar(2000) DEFAULT NULL COMMENT 'Parameter value', `param_type` tinyint(3) unsigned DEFAULT '1' COMMENT 'Type 0: system parameter 1: non system parameter', `remark` varchar(200) DEFAULT NULL COMMENT 'Remarks', `creator` bigint(20) DEFAULT NULL COMMENT 'creator', `create_date` datetime DEFAULT NULL COMMENT 'Creation time', `updater` bigint(20) DEFAULT NULL COMMENT 'Reneer', `update_date` datetime DEFAULT NULL COMMENT 'Update time', `del_flag` tinyint(2) DEFAULT '0' COMMENT 'Available or not 0: available 1: not available', PRIMARY KEY (`id`), UNIQUE KEY `uk_param_code` (`param_code`), KEY `idx_create_date` (`create_date`) ) ENGINE=InnoDB AUTO_INCREMENT DEFAULT CHARSET=utf8mb4 COMMENT='Parameter management';
2. Business operation
2.1 usage
We have set the starting and sending price. What is the step to use? The answer is very simple. In the shopping cart page, the order submission function, the APP or applet page, you can judge whether the total amount of the current order is greater than or equal to the starting price. If so, you can submit the order. Otherwise, you can display the amount of the difference, and the function of collecting the order is better.
2.2 how to deal with multiple purchases?
In the actual business, we often find that after the user buys something, for example, the starting and sending price is 100 yuan, but when the user buys 300 yuan, the starting and sending price is enough, and the delivery is also included in the mail, but when the user checks, for example, we find that
Chinese cabbage is less than 10 jin. At this time, the user places an order again and buys 10 jin Chinese cabbage. It's very clear that Chinese cabbage is not enough for the price, so what should we do?
It is mandatory to take the order as the unit. If the order is not satisfied, the order will not be placed. Such a simple and crude way will definitely make the customer unhappy, or lose the customer in the future. So what?
1. Judge whether the user has placed an order today. If the order has been placed, the second order does not need to be priced. Otherwise, the price still needs to be priced.
Let's review:
1. We used to compare the order amount with the starting delivery price in the shopping cart, so where should we judge when we place the order again on the same day that we have placed the order?
The answer is: when entering the shopping cart, you need to provide an interface to judge whether the user has ever placed an order. If you place an order, you can only judge that the amount is greater than 0 this time.
I posted the actual business code:
public class ShoppingCartManager { private ShoppingCartDao shoppingCartDao; public ShoppingCartManager() { shoppingCartDao = BaseApplication.getInstance().getDaoSession().getShoppingCartDao(); } public List<ShoppingCart> getBySeller(long sellerId, long userId) { return shoppingCartDao.queryBuilder().where(ShoppingCartDao.Properties.SellerId.eq(sellerId)) .where(ShoppingCartDao.Properties.BuyerId.eq(userId)).build().list(); } public List<ShoppingCart> getByUser(long userId) { return shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(userId)).build().list(); } public List<ShoppingCart> getByFormat(long sellerId, long userId, long formatId) { return shoppingCartDao.queryBuilder().where(ShoppingCartDao.Properties.SellerId.eq(sellerId)) .where(ShoppingCartDao.Properties.BuyerId.eq(userId)) .where(ShoppingCartDao.Properties.FormatId.eq(formatId)).build().list(); } public void shopping(ShoppingCart goodsCart) { ShoppingCart queryGoods = shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(goodsCart.getBuyerId())) .where(ShoppingCartDao.Properties.FormatId.eq(goodsCart.getFormatId())) .where(ShoppingCartDao.Properties.MethodId.eq(goodsCart.getMethodId())) .where(ShoppingCartDao.Properties.SellerId.eq(goodsCart.getSellerId())) .build().unique(); int count = goodsCart.getGoodsNumber(); if (queryGoods == null) { if (count > 0) { goodsCart.setIsSelected(1); shoppingCartDao.insert(goodsCart); } } else { if (count == 0) { shoppingCartDao.delete(queryGoods); } else { queryGoods.setGoodsNumber(goodsCart.getGoodsNumber()); shoppingCartDao.update(queryGoods); } } } public void update(ShoppingCart goodsCart) { ShoppingCart queryGoods = shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(goodsCart.getBuyerId())) .where(ShoppingCartDao.Properties.FormatId.eq(goodsCart.getFormatId())) .where(ShoppingCartDao.Properties.MethodId.eq(goodsCart.getMethodId())) .where(ShoppingCartDao.Properties.SellerId.eq(goodsCart.getSellerId())) .build().unique(); if (queryGoods != null) { queryGoods.setPrice(goodsCart.getPrice()); queryGoods.setIsSelected(goodsCart.getIsSelected()); shoppingCartDao.update(queryGoods); } } public void deleteBySeller(long userId, long sellerId) { List<ShoppingCart> queryGoods = shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(userId)) .where(ShoppingCartDao.Properties.SellerId.eq(sellerId)) .build().list(); for (ShoppingCart c : queryGoods) { shoppingCartDao.delete(c); } } public void deleteByUser(long userId) { List<ShoppingCart> queryGoods = shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(userId)) .build().list(); for (ShoppingCart c : queryGoods) { shoppingCartDao.delete(c); } } public void deleteItem(ShoppingCart goodsCart) { ShoppingCart queryGoods = shoppingCartDao.queryBuilder() .where(ShoppingCartDao.Properties.BuyerId.eq(goodsCart.getBuyerId())) .where(ShoppingCartDao.Properties.FormatId.eq(goodsCart.getFormatId())) .where(ShoppingCartDao.Properties.MethodId.eq(goodsCart.getMethodId())) .where(ShoppingCartDao.Properties.SellerId.eq(goodsCart.getSellerId())) .build().unique(); if (queryGoods != null) { shoppingCartDao.delete(queryGoods); } } public void insert(ShoppingCart shoppingCart) { shoppingCartDao.insert(shoppingCart); } }