20260730_seckill.sql 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. -- 秒杀核心表:活动批次 / 活动商品版本,以及订单秒杀标识字段
  2. -- 执行前请确认线上库无同名表;xhOrder.hasSeckill / xhOrderGoods.seckillGoodsId 若已存在请跳过对应 ALTER
  3. CREATE TABLE IF NOT EXISTS `xhSeckillActivity` (
  4. `id` int(11) NOT NULL AUTO_INCREMENT,
  5. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  6. `shopId` int(11) NOT NULL DEFAULT 0 COMMENT '门店id',
  7. `title` varchar(32) NOT NULL DEFAULT '' COMMENT '活动标题',
  8. `subtitle` varchar(64) NOT NULL DEFAULT '' COMMENT '活动副标题',
  9. `showCountdown` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否显示倒计时',
  10. `expand` tinyint(4) NOT NULL DEFAULT 0 COMMENT '商品展开',
  11. `startTime` int(11) NOT NULL DEFAULT 0 COMMENT '开始时间unix',
  12. `endTime` int(11) NOT NULL DEFAULT 0 COMMENT '结束时间unix',
  13. `desc` varchar(500) NOT NULL DEFAULT '' COMMENT '活动说明',
  14. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1有效 0无效',
  15. `delStatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '删除状态',
  16. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  17. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  18. PRIMARY KEY (`id`),
  19. KEY `mainId` (`mainId`),
  20. KEY `main_time` (`mainId`,`startTime`,`endTime`)
  21. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='秒杀活动批次';
  22. CREATE TABLE IF NOT EXISTS `xhSeckillGoods` (
  23. `id` int(11) NOT NULL AUTO_INCREMENT,
  24. `activityId` int(11) NOT NULL DEFAULT 0 COMMENT '活动批次id',
  25. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  26. `shopId` int(11) NOT NULL DEFAULT 0 COMMENT '门店id',
  27. `goodsId` int(11) NOT NULL DEFAULT 0 COMMENT '商品id(可含规格子商品)',
  28. `specName` varchar(64) NOT NULL DEFAULT '' COMMENT '规格名',
  29. `price` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '秒杀价',
  30. `originPrice` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '原价快照',
  31. `stock` int(11) NOT NULL DEFAULT 0 COMMENT '秒杀库存',
  32. `limit` int(11) NOT NULL DEFAULT 0 COMMENT '单人限购',
  33. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1展示 0隐藏(历史版本)',
  34. `name` varchar(128) NOT NULL DEFAULT '' COMMENT '商品名快照',
  35. `cover` varchar(255) NOT NULL DEFAULT '' COMMENT '封面快照',
  36. `realStock` int(11) NOT NULL DEFAULT 0 COMMENT '保存时真实库存快照',
  37. `delStatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '删除状态',
  38. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  39. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  40. PRIMARY KEY (`id`),
  41. KEY `activityId` (`activityId`),
  42. KEY `main_goods` (`mainId`,`goodsId`),
  43. KEY `activity_goods_status` (`activityId`,`goodsId`,`status`)
  44. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='秒杀活动商品版本';
  45. -- 订单级:是否包含秒杀商品(合并结算单可能仅部分行是秒杀)
  46. ALTER TABLE `xhOrder`
  47. ADD COLUMN `hasSeckill` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否包含秒杀商品:0不包含,1包含' AFTER `groupBuyId`,
  48. ADD KEY `hasSeckill` (`hasSeckill`);
  49. -- 订单商品行级:关联秒杀活动商品版本,便于追溯价格/库存版本
  50. ALTER TABLE `xhOrderGoods`
  51. ADD COLUMN `seckillGoodsId` int(11) NOT NULL DEFAULT 0 COMMENT '秒杀活动商品版本id(xhSeckillGoods.id),非秒杀为0' AFTER `goodsId`,
  52. ADD KEY `seckillGoodsId` (`seckillGoodsId`);