分享

电商平台

 quasiceo 2018-09-11

说明:现在电商白热化的程度,无论是生鲜电商还是其他的电商等等,都会有促销的这个体系,目的就是增加订单量与知名度等等

           那么对于Java开源生鲜电商平台而言,我们采用优惠券的这种方式进行促销。(补贴价格战对烧钱而言非常的恐怖的,太烧钱了)


1. 优惠券基础信息表

说明:任何一个优惠券或者说代金券都是有一个基础的说明,比如:优惠券名称,类型,价格,有效期,状态,说明等等基础信息。


  1. CREATE TABLE `coupon` (
  2. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
  3. `region_id` bigint(20) DEFAULT NULL COMMENT '所属区域',
  4. `type` int(11) DEFAULT NULL COMMENT '所属类型,1为满减',
  5. `name` varchar(32) DEFAULT NULL COMMENT '优惠券名称',
  6. `img` varchar(64) DEFAULT NULL COMMENT '图片的URL地址',
  7. `start_time` datetime DEFAULT NULL COMMENT '优惠券开始时间',
  8. `end_time` datetime DEFAULT NULL COMMENT '优惠券结束时间',
  9. `money` decimal(11,2) DEFAULT NULL COMMENT '优惠券金额,用整数,固定值目前。',
  10. `status` int(11) DEFAULT NULL COMMENT '状态,0表示未开始,1表示进行中,-1表示结束',
  11. `remarks` varchar(512) DEFAULT NULL COMMENT '优惠券的说明',
  12. `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  13. `full_money` decimal(12,2) DEFAULT NULL COMMENT '金额满',
  14. PRIMARY KEY (`id`)
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券基础配置表';

说明:业务说可以规定某个区域,做优惠券,而且是纳新后才有,这样增加买家用户。价格可以后端进行设置。

           状态的意义在于,用户需要注册完成后,然后主动认领才有效,为什么要这样设计呢?目的只有一个:让用户在对APP这个软件玩一会儿,增加熟悉程度.

2. 优惠券领取记录表

说明:我们需要记录那个买家,什么时候进行的领取,领取的的时间,券的额度是多少等等,是否已经使用等信息


  1. CREATE TABLE `coupon_receive` (
  2. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
  3. `buyer_id` bigint(20) DEFAULT NULL COMMENT '买家ID',
  4. `coupon_id` bigint(20) DEFAULT NULL COMMENT '优惠券编号',
  5. `coupon_money` decimal(12,2) DEFAULT NULL COMMENT '券额',
  6. `create_time` datetime DEFAULT NULL COMMENT '领取时间',
  7. `full_money` decimal(12,2) DEFAULT NULL COMMENT '金额满',
  8. `status` int(11) DEFAULT NULL COMMENT '状态,1为已使用,0为已领取未使用,-1为已过期',
  9. PRIMARY KEY (`id`)
  10. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券领取记录表';

3.优惠券消费记录表

说明:优惠券消费记录表,是需要知道那个买家,那个优惠券,那个订单使用了优惠券,这边有个特别注意的地方是,这个优惠券的执行在支付成功后的回调。


  1. CREATE TABLE `coupon_logs` (
  2. `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
  3. `buyer_id` bigint(20) DEFAULT NULL COMMENT '买家ID',
  4. `coupon_receive_id` bigint(20) DEFAULT NULL COMMENT '优惠券id',
  5. `order_number` varchar(64) DEFAULT NULL COMMENT '订单号',
  6. `order_original_amount` decimal(12,2) DEFAULT NULL COMMENT '原订单金额',
  7. `coupon_amount` decimal(11,2) DEFAULT NULL COMMENT '优惠券的金额',
  8. `order_final_amount` decimal(12,2) DEFAULT NULL COMMENT '抵扣优惠券之后的订单金额',
  9. `create_time` datetime DEFAULT NULL COMMENT '领取时间',
  10. `status` int(2) DEFAULT '0' COMMENT '日志状态: 默认为0,支付回调成功后为1',
  11. PRIMARY KEY (`id`)
  12. ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券消费记录表';

说明:相对而言,优惠券的难度不算大,重点的是业务方面的指导与学习,包括数据库的架构与设计等等,还有就是思路的学习。

 

相关核心代码如下:

APP需要后台提供以下几个接口:

3.1 查询所有买家的优惠券。

3.2 判断买家是否可以领取优惠券。

3.3 买家主动领取优惠券


  1. /**
  2. * 优惠券controller
  3. */
  4. @RestController
  5. @RequestMapping("/buyer/coupon")
  6. public class CouponController extends BaseController {

  7. private static final Logger logger = LoggerFactory.getLogger(CouponController.class);

  8. @Autowired
  9. private CouponReceiveService couponReceiveService;

  10. @Autowired
  11. private UsersService usersService;

  12. /**
  13. * 查询买家所有优惠券
  14. *
  15. * @param request
  16. * @param response
  17. * @param buyerId
  18. * @return
  19. */
  20. @RequestMapping(value = "/list", method = { RequestMethod.GET, RequestMethod.POST })
  21. public JsonResult getCouponList(HttpServletRequest request, HttpServletResponse response, Long buyerId) {
  22. try {
  23. if (buyerId == null) {
  24. return new JsonResult(JsonResultCode.FAILURE, "买家不存在", "");
  25. }
  26. List<CouponReceive> result = couponReceiveService.selectAllByBuyerId(buyerId);
  27. return new JsonResult(JsonResultCode.SUCCESS, "查询成功", result);
  28. } catch (Exception ex) {
  29. logger.error("[CouponController][getCouponList] exception", ex);
  30. return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
  31. }
  32. }

  33. /**
  34. * 判断买家是否可以领取优惠券
  35. *
  36. * @param request
  37. * @param response
  38. * @param buyerId
  39. * @return
  40. */
  41. @RequestMapping(value = "/judge", method = { RequestMethod.GET, RequestMethod.POST })
  42. public JsonResult judgeReceive(HttpServletRequest request, HttpServletResponse response, Long buyerId) {
  43. try {
  44. // 判断当前用户是否可用
  45. Users users = usersService.getUsersById(buyerId);
  46. if (users == null) {
  47. logger.info("OrderController.judgeReceive.buyerId " + buyerId);
  48. return new JsonResult(JsonResultCode.FAILURE, "你的账号有误,请重新登录", "");
  49. }
  50. int status = users.getStatus();
  51. if (UserStatus.FORBIDDEN == status) {
  52. return new JsonResult(JsonResultCode.FAILURE, "你的账号已经被禁用了,请联系公司客服", "");
  53. }
  54. List<Coupon> result = couponReceiveService.selectByBuyerId(buyerId);
  55. if (CollectionUtils.isEmpty(result)) {
  56. result = new ArrayList<Coupon>();
  57. }
  58. return new JsonResult(JsonResultCode.SUCCESS, "查询成功", result);
  59. } catch (Exception ex) {
  60. logger.error("[CouponController][judgeReceive] exception", ex);
  61. return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
  62. }
  63. }

  64. /**
  65. * 买家领取优惠券
  66. *
  67. * @param request
  68. * @param response
  69. * @param buyerId
  70. * @return
  71. */
  72. @RequestMapping(value = "/add", method = { RequestMethod.GET, RequestMethod.POST })
  73. public JsonResult saveCoupon(HttpServletRequest request, HttpServletResponse response, Long buyerId,
  74. Long couponId) {
  75. try {
  76. // 判断当前用户是否可用
  77. Users users = usersService.getUsersById(buyerId);
  78. if (users == null) {
  79. logger.info("OrderController.saveCoupon.buyerId " + buyerId);
  80. return new JsonResult(JsonResultCode.FAILURE, "你的账号有误,请重新登录", "");
  81. }
  82. //判断当前用户的状态是否可用
  83. int status = users.getStatus();
  84. if (UserStatus.FORBIDDEN == status) {
  85. return new JsonResult(JsonResultCode.FAILURE, "你的账号已经被禁用了,请联系公司客服", "");
  86. }
  87. if (couponId == null) {
  88. return new JsonResult(JsonResultCode.SUCCESS, "活动已经结束", "");
  89. }
  90. //新增
  91. int result = couponReceiveService.insert(buyerId, couponId);
  92. if (result == -1) {
  93. return new JsonResult(JsonResultCode.SUCCESS, "领取失败,已经领取过优惠券了", "");
  94. } else if (result == 0) {
  95. return new JsonResult(JsonResultCode.FAILURE, "领取失败,活动已经结束", "");
  96. } else {
  97. return new JsonResult(JsonResultCode.SUCCESS, "领取成功", "");
  98. }
  99. } catch (Exception ex) {
  100. logger.error("[CouponController][saveCoupon] exception", ex);
  101. return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
  102. }
  103. }
  104. }

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约