Java Open Source Fresh E-commerce Platform - Coupon Design and Architecture (Source Downloadable)
Explanation: At present, the degree of white-hot e-commerce, whether fresh e-commerce or other e-commerce, will have this system of promotion, the purpose is to increase the order quantity and popularity, and so on.
For the Java open source fresh e-commerce platform, we use coupons to promote it. (Subsidy price war is terrible for money burning, too much money burning)
1. Basic information sheet of coupons
Note: Any coupon or voucher has a basic description, such as: the name of the coupon, type, price, expiration date, status, description and other basic information.
CREATE TABLE `coupon` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatic increase ID', `region_id` bigint(20) DEFAULT NULL COMMENT 'Respective region', `type` int(11) DEFAULT NULL COMMENT 'Type of ownership,1 Full reduction', `name` varchar(32) DEFAULT NULL COMMENT 'Title of coupon', `img` varchar(64) DEFAULT NULL COMMENT 'Picture URL address', `start_time` datetime DEFAULT NULL COMMENT 'Coupon start time', `end_time` datetime DEFAULT NULL COMMENT 'Coupon End Time', `money` decimal(11,2) DEFAULT NULL COMMENT 'The amount of coupon, in integer, fixed value at present.', `status` int(11) DEFAULT NULL COMMENT 'State, 0 means no start, and 1 means in progress.-1 End', `remarks` varchar(512) DEFAULT NULL COMMENT 'Notes on coupons', `create_time` datetime DEFAULT NULL COMMENT 'Creation time', `full_money` decimal(12,2) DEFAULT NULL COMMENT 'Full amount', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Coupon Foundation Configuration Table';
Description: Business can specify a certain area, do coupons, and only after the adoption of new, so as to increase the number of buyers. Prices can be set at the back end.
The significance of the state is that the user needs to register after completion, and then actively claim to be valid. Why do we design this way? There is only one purpose: to let users play with APP software for a while to increase familiarity.
2. Coupon Receiving Record Form
Description: We need to record the buyer, when to collect, the time to collect, the amount of vouchers and so on, whether they have been used or not.
CREATE TABLE `coupon_receive` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatic increase ID', `buyer_id` bigint(20) DEFAULT NULL COMMENT 'Buyer ID', `coupon_id` bigint(20) DEFAULT NULL COMMENT 'Coupon Number', `coupon_money` decimal(12,2) DEFAULT NULL COMMENT 'Amount of coupon', `create_time` datetime DEFAULT NULL COMMENT 'Time to collect', `full_money` decimal(12,2) DEFAULT NULL COMMENT 'Full amount', `status` int(11) DEFAULT NULL COMMENT 'State, 1 is used, 0 is received and not used.-1 Has expired', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Coupon Receiving Record Form';
3. Coupon Consumption Record
Note: The coupon consumption record is to know the buyer, the coupon, and the order using the coupon. Here is a special note that the implementation of the coupon callback after successful payment.
CREATE TABLE `coupon_logs` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Automatic increase ID', `buyer_id` bigint(20) DEFAULT NULL COMMENT 'Buyer ID', `coupon_receive_id` bigint(20) DEFAULT NULL COMMENT 'Coupon id', `order_number` varchar(64) DEFAULT NULL COMMENT 'Order number', `order_original_amount` decimal(12,2) DEFAULT NULL COMMENT 'Amount of original order', `coupon_amount` decimal(11,2) DEFAULT NULL COMMENT 'The amount of the coupon', `order_final_amount` decimal(12,2) DEFAULT NULL COMMENT 'Order amount after deduction of coupons', `create_time` datetime DEFAULT NULL COMMENT 'Time to collect', `status` int(2) DEFAULT '0' COMMENT 'Log status: Default is 0, payment callback is 1 after success', PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Coupon Consumption Record';
Note: Relatively speaking, the difficulty of coupons is not too big, the focus is on business guidance and learning, including the structure and design of the database, and the learning of ideas.
The relevant core codes are as follows:
APP needs to provide the following interfaces in the background:
3.1 Search for coupons from all buyers.
3.2 Judge whether the buyer can get the coupon.
3.3 Buyers take the initiative to receive coupons
/** * Coupon controller */ @RestController @RequestMapping("/buyer/coupon") public class CouponController extends BaseController { private static final Logger logger = LoggerFactory.getLogger(CouponController.class); @Autowired private CouponReceiveService couponReceiveService; @Autowired private UsersService usersService; /** * Check all coupons from buyers * * @param request * @param response * @param buyerId * @return */ @RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST }) public JsonResult getCouponList(HttpServletRequest request, HttpServletResponse response, Long buyerId) { try { if (buyerId == null) { return new JsonResult(JsonResultCode.FAILURE, "Buyer does not exist", ""); } List<CouponReceive> result = couponReceiveService.selectAllByBuyerId(buyerId); return new JsonResult(JsonResultCode.SUCCESS, "query was successful", result); } catch (Exception ex) { logger.error("[CouponController][getCouponList] exception", ex); return new JsonResult(JsonResultCode.FAILURE, "System error,Please try again later.", ""); } } /** * Judging whether a buyer can get a coupon * * @param request * @param response * @param buyerId * @return */ @RequestMapping(value = "/judge", method = { RequestMethod.GET, RequestMethod.POST }) public JsonResult judgeReceive(HttpServletRequest request, HttpServletResponse response, Long buyerId) { try { // Determine whether the current user is available Users users = usersService.getUsersById(buyerId); if (users == null) { logger.info("OrderController.judgeReceive.buyerId " + buyerId); return new JsonResult(JsonResultCode.FAILURE, "Your account is incorrect. Please log in again.", ""); } int status = users.getStatus(); if (UserStatus.FORBIDDEN == status) { return new JsonResult(JsonResultCode.FAILURE, "Your account has been disabled,Please contact company customer service", ""); } List<Coupon> result = couponReceiveService.selectByBuyerId(buyerId); if (CollectionUtils.isEmpty(result)) { result = new ArrayList<Coupon>(); } return new JsonResult(JsonResultCode.SUCCESS, "query was successful", result); } catch (Exception ex) { logger.error("[CouponController][judgeReceive] exception", ex); return new JsonResult(JsonResultCode.FAILURE, "System error,Please try again later.", ""); } } /** * Buyers receive coupons * * @param request * @param response * @param buyerId * @return */ @RequestMapping(value = "/add", method = { RequestMethod.GET, RequestMethod.POST }) public JsonResult saveCoupon(HttpServletRequest request, HttpServletResponse response, Long buyerId, Long couponId) { try { // Determine whether the current user is available Users users = usersService.getUsersById(buyerId); if (users == null) { logger.info("OrderController.saveCoupon.buyerId " + buyerId); return new JsonResult(JsonResultCode.FAILURE, "Your account is incorrect. Please log in again.", ""); } //Determine whether the current user's status is available int status = users.getStatus(); if (UserStatus.FORBIDDEN == status) { return new JsonResult(JsonResultCode.FAILURE, "Your account has been disabled,Please contact company customer service", ""); } if (couponId == null) { return new JsonResult(JsonResultCode.SUCCESS, "The activity is over.", ""); } //Newly added int result = couponReceiveService.insert(buyerId, couponId); if (result == -1) { return new JsonResult(JsonResultCode.SUCCESS, "Fail to receive,I've already got a coupon.", ""); } else if (result == 0) { return new JsonResult(JsonResultCode.FAILURE, "Fail to receive,The activity is over.", ""); } else { return new JsonResult(JsonResultCode.SUCCESS, "Successful reception", ""); } } catch (Exception ex) { logger.error("[CouponController][saveCoupon] exception", ex); return new JsonResult(JsonResultCode.FAILURE, "System error,Please try again later.", ""); } } }
Final summary: User coupons will be placed in the personal center of the buyer's APP, then click to view and collect, and then automatically display the coupon data when paying, which is very flexible and convenient.
Java open source fresh e-commerce platform - coupon design and architecture (source code can be downloaded), if you need to download, you can download it under my github.