优惠券数据库设计
https://blog.51cto.com/u_15776740/5916257?articleABtest=1
wx6311aa5a3b0122022-12-06 15:23:59博主文章分类:数据库方面©著作权
CREATE TABLE `coupon` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'ID',
`title` varchar(64) NOT NULL COMMENT '优惠券标题(有图片则显示图片):无门槛50元优惠券 | 单品最高减2000元',
`icon` varchar(128) DEFAULT NULL COMMENT '图片',
`used` int(2) NOT NULL COMMENT '可用于:10店铺优惠券 11新人店铺券 20商品优惠券 30类目优惠券 60平台优惠券 61新人平台券',
`type` int(2) NOT NULL DEFAULT '1' COMMENT '1满减券 2叠加满减券 3无门槛券(需要限制大小)',
`with_special` int(2) NOT NULL DEFAULT '2' COMMENT '1可用于特价商品 2不能 默认不能(商品优惠卷除外)',
`with_sn` varchar(36) DEFAULT NULL COMMENT '店铺或商品流水号',
`with_amount` bigint(20) NOT NULL DEFAULT '0' COMMENT '满多少金额',
`used_amount` bigint(20) NOT NULL COMMENT '用券金额',
`quota` int(10) NOT NULL DEFAULT '1' COMMENT '配额:发券数量',
`take_count` int(10) NOT NULL DEFAULT '0' COMMENT '已领取的优惠券数量',
`used_count` int(10) NOT NULL DEFAULT '0' COMMENT '已使用的优惠券数量',
`start_time` datetime NOT NULL COMMENT '发放开始时间',
`end_time` datetime NOT NULL COMMENT '发放结束时间',
`valid_type` int(1) NOT NULL DEFAULT '2' COMMENT '时效:1绝对时效(领取后XXX-XXX时间段有效) 2相对时效(领取后N天有效)',
`valid_start_time` datetime DEFAULT NULL COMMENT '使用开始时间',
`valid_end_time` datetime DEFAULT NULL COMMENT '使用结束时间',
`valid_days` int(3) NOT NULL DEFAULT '1' COMMENT '自领取之日起有效天数',
`status` int(1) NOT NULL DEFAULT '1' COMMENT '1生效 2失效 3已结束',
`create_user` bigint(20) NOT NULL,
`create_time` datetime NOT NULL COMMENT '创建时间',
`update_user` bigint(20) NOT NULL,
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='优惠券表';
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
说明:现在电商白热化的程度,无论是生鲜电商还是其他的电商等等,都会有促销的这个体系,目的就是增加订单量与知名度等等
那么对于Java开源生鲜电商平台而言,我们采用优惠券的这种方式进行促销。(补贴价格战对烧钱而言非常的恐怖的,太烧钱了)
1. 优惠券基础信息表
说明:任何一个优惠券或者说代金券都是有一个基础的说明,比如:优惠券名称,类型,价格,有效期,状态,说明等等基础信息。
CREATE TABLE `coupon` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
`region_id` bigint(20) DEFAULT NULL COMMENT '所属区域',
`type` int(11) DEFAULT NULL COMMENT '所属类型,1为满减',
`name` varchar(32) DEFAULT NULL COMMENT '优惠券名称',
`img` varchar(64) DEFAULT NULL COMMENT '图片的URL地址',
`start_time` datetime DEFAULT NULL COMMENT '优惠券开始时间',
`end_time` datetime DEFAULT NULL COMMENT '优惠券结束时间',
`money` decimal(11,2) DEFAULT NULL COMMENT '优惠券金额,用整数,固定值目前。',
`status` int(11) DEFAULT NULL COMMENT '状态,0表示未开始,1表示进行中,-1表示结束',
`remarks` varchar(512) DEFAULT NULL COMMENT '优惠券的说明',
`create_time` datetime DEFAULT NULL COMMENT '创建时间',
`full_money` decimal(12,2) DEFAULT NULL COMMENT '金额满',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券基础配置表';
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
说明:业务说可以规定某个区域,做优惠券,而且是纳新后才有,这样增加买家用户。价格可以后端进行设置。
状态的意义在于,用户需要注册完成后,然后主动认领才有效,为什么要这样设计呢?目的只有一个:让用户在对APP这个软件玩一会儿,增加熟悉程度.
2. 优惠券领取记录表
说明:我们需要记录那个买家,什么时候进行的领取,领取的的时间,券的额度是多少等等,是否已经使用等信息
CREATE TABLE `coupon_receive` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
`buyer_id` bigint(20) DEFAULT NULL COMMENT '买家ID',
`coupon_id` bigint(20) DEFAULT NULL COMMENT '优惠券编号',
`coupon_money` decimal(12,2) DEFAULT NULL COMMENT '券额',
`create_time` datetime DEFAULT NULL COMMENT '领取时间',
`full_money` decimal(12,2) DEFAULT NULL COMMENT '金额满',
`status` int(11) DEFAULT NULL COMMENT '状态,1为已使用,0为已领取未使用,-1为已过期',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券领取记录表';
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
3.优惠券消费记录表
说明:优惠券消费记录表,是需要知道那个买家,那个优惠券,那个订单使用了优惠券,这边有个特别注意的地方是,这个优惠券的执行在支付成功后的回调。
CREATE TABLE `coupon_logs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '自动增加ID',
`buyer_id` bigint(20) DEFAULT NULL COMMENT '买家ID',
`coupon_receive_id` bigint(20) DEFAULT NULL COMMENT '优惠券id',
`order_number` varchar(64) DEFAULT NULL COMMENT '订单号',
`order_original_amount` decimal(12,2) DEFAULT NULL COMMENT '原订单金额',
`coupon_amount` decimal(11,2) DEFAULT NULL COMMENT '优惠券的金额',
`order_final_amount` decimal(12,2) DEFAULT NULL COMMENT '抵扣优惠券之后的订单金额',
`create_time` datetime DEFAULT NULL COMMENT '领取时间',
`status` int(2) DEFAULT '0' COMMENT '日志状态: 默认为0,支付回调成功后为1',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='优惠券消费记录表';
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
说明:相对而言,优惠券的难度不算大,重点的是业务方面的指导与学习,包括数据库的架构与设计等等,还有就是思路的学习。
相关核心代码如下:
APP需要后台提供以下几个接口:
3.1 查询所有买家的优惠券。
3.2 判断买家是否可以领取优惠券。
3.3 买家主动领取优惠券
/**
* 优惠券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;
/**
* 查询买家所有优惠券
*
* @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, "买家不存在", "");
}
List<CouponReceive> result = couponReceiveService.selectAllByBuyerId(buyerId);
return new JsonResult(JsonResultCode.SUCCESS, "查询成功", result);
} catch (Exception ex) {
logger.error("[CouponController][getCouponList] exception", ex);
return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
}
}
/**
* 判断买家是否可以领取优惠券
*
* @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 {
// 判断当前用户是否可用
Users users = usersService.getUsersById(buyerId);
if (users == null) {
logger.info("OrderController.judgeReceive.buyerId " + buyerId);
return new JsonResult(JsonResultCode.FAILURE, "你的账号有误,请重新登录", "");
}
int status = users.getStatus();
if (UserStatus.FORBIDDEN == status) {
return new JsonResult(JsonResultCode.FAILURE, "你的账号已经被禁用了,请联系公司客服", "");
}
List<Coupon> result = couponReceiveService.selectByBuyerId(buyerId);
if (CollectionUtils.isEmpty(result)) {
result = new ArrayList<Coupon>();
}
return new JsonResult(JsonResultCode.SUCCESS, "查询成功", result);
} catch (Exception ex) {
logger.error("[CouponController][judgeReceive] exception", ex);
return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
}
}
/**
* 买家领取优惠券
*
* @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 {
// 判断当前用户是否可用
Users users = usersService.getUsersById(buyerId);
if (users == null) {
logger.info("OrderController.saveCoupon.buyerId " + buyerId);
return new JsonResult(JsonResultCode.FAILURE, "你的账号有误,请重新登录", "");
}
//判断当前用户的状态是否可用
int status = users.getStatus();
if (UserStatus.FORBIDDEN == status) {
return new JsonResult(JsonResultCode.FAILURE, "你的账号已经被禁用了,请联系公司客服", "");
}
if (couponId == null) {
return new JsonResult(JsonResultCode.SUCCESS, "活动已经结束", "");
}
//新增
int result = couponReceiveService.insert(buyerId, couponId);
if (result == -1) {
return new JsonResult(JsonResultCode.SUCCESS, "领取失败,已经领取过优惠券了", "");
} else if (result == 0) {
return new JsonResult(JsonResultCode.FAILURE, "领取失败,活动已经结束", "");
} else {
return new JsonResult(JsonResultCode.SUCCESS, "领取成功", "");
}
} catch (Exception ex) {
logger.error("[CouponController][saveCoupon] exception", ex);
return new JsonResult(JsonResultCode.FAILURE, "系统错误,请稍后重试", "");
}
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
- 25.
- 26.
- 27.
- 28.
- 29.
- 30.
- 31.
- 32.
- 33.
- 34.
- 35.
- 36.
- 37.
- 38.
- 39.
- 40.
- 41.
- 42.
- 43.
- 44.
- 45.
- 46.
- 47.
- 48.
- 49.
- 50.
- 51.
- 52.
- 53.
- 54.
- 55.
- 56.
- 57.
- 58.
- 59.
- 60.
- 61.
- 62.
- 63.
- 64.
- 65.
- 66.
- 67.
- 68.
- 69.
- 70.
- 71.
- 72.
- 73.
- 74.
- 75.
- 76.
- 77.
- 78.
- 79.
- 80.
- 81.
- 82.
- 83.
- 84.
- 85.
- 86.
- 87.
- 88.
- 89.
- 90.
- 91.
- 92.
- 93.
- 94.
- 95.
- 96.
- 97.
- 98.
- 99.
- 100.
- 101.
- 102.
- 103.
- 104.
- 105.
- 106.
- 107.
- 108.
- 109.
- 110.
最终总结:用户优惠券会发放在买家的APP中的个人中心里面,然后进行点击查看与领取,然后在支付的时候会自动显示出优惠券的数据,非常的灵活与方便。
更多推荐
所有评论(0)