20260730_seckill.sql 3.3 KB

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