20260723_group_buy.sql 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. -- 拼团(团购)核心表:活动批次 / 活动商品版本 / 拼团单 / 拼团成员
  2. -- 执行前请确认线上库无同名表;xhOrder.groupBuyId 若已存在请跳过对应 ALTER
  3. CREATE TABLE IF NOT EXISTS `xhGroupBuyActivity` (
  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 `xhGroupBuyGoods` (
  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. `groupSize` tinyint(4) NOT NULL DEFAULT 3 COMMENT '成团人数2/3/5',
  34. `virtualGroup` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否虚拟成团',
  35. `virtualMinutes` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟成团分钟数',
  36. `autoRefund` tinyint(4) NOT NULL DEFAULT 1 COMMENT '失败自动退款',
  37. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1展示 0隐藏(历史版本)',
  38. `name` varchar(128) NOT NULL DEFAULT '' COMMENT '商品名快照',
  39. `cover` varchar(255) NOT NULL DEFAULT '' COMMENT '封面快照',
  40. `realStock` int(11) NOT NULL DEFAULT 0 COMMENT '保存时真实库存快照',
  41. `delStatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '删除状态',
  42. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  43. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  44. PRIMARY KEY (`id`),
  45. KEY `activityId` (`activityId`),
  46. KEY `main_goods` (`mainId`,`goodsId`),
  47. KEY `activity_goods_status` (`activityId`,`goodsId`,`status`)
  48. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团购活动商品版本';
  49. CREATE TABLE IF NOT EXISTS `xhGroupBuy` (
  50. `id` int(11) NOT NULL AUTO_INCREMENT,
  51. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  52. `shopId` int(11) NOT NULL DEFAULT 0 COMMENT '门店id',
  53. `activityId` int(11) NOT NULL DEFAULT 0 COMMENT '活动批次id',
  54. `activityGoodsId` int(11) NOT NULL DEFAULT 0 COMMENT '活动商品版本id',
  55. `goodsId` int(11) NOT NULL DEFAULT 0 COMMENT '商品id',
  56. `leaderCustomId` int(11) NOT NULL DEFAULT 0 COMMENT '团长客户id',
  57. `needNum` int(11) NOT NULL DEFAULT 0 COMMENT '成团所需人数',
  58. `currentNum` int(11) NOT NULL DEFAULT 0 COMMENT '已支付人数',
  59. `price` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '团购价快照',
  60. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1拼团中 2成功 3失败 4已取消',
  61. `virtualGroup` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否虚拟成团',
  62. `deadline` int(11) NOT NULL DEFAULT 0 COMMENT '团截止unix',
  63. `successTime` datetime DEFAULT NULL COMMENT '成团时间',
  64. `failTime` datetime DEFAULT NULL COMMENT '失败时间',
  65. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  66. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  67. PRIMARY KEY (`id`),
  68. KEY `mainId` (`mainId`),
  69. KEY `activityGoodsId` (`activityGoodsId`),
  70. KEY `status_deadline` (`status`,`deadline`),
  71. KEY `goods_status` (`goodsId`,`status`)
  72. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='拼团单';
  73. CREATE TABLE IF NOT EXISTS `xhGroupBuyMember` (
  74. `id` int(11) NOT NULL AUTO_INCREMENT,
  75. `groupBuyId` int(11) NOT NULL DEFAULT 0 COMMENT '拼团单id',
  76. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  77. `shopId` int(11) NOT NULL DEFAULT 0 COMMENT '门店id',
  78. `orderId` int(11) NOT NULL DEFAULT 0 COMMENT '订单id',
  79. `orderSn` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  80. `customId` int(11) NOT NULL DEFAULT 0 COMMENT '客户id',
  81. `role` tinyint(4) NOT NULL DEFAULT 2 COMMENT '1团长 2成员',
  82. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1待支付 2已支付 3已失效',
  83. `joinTime` datetime DEFAULT NULL COMMENT '加入时间',
  84. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  85. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  86. PRIMARY KEY (`id`),
  87. KEY `group_custom` (`groupBuyId`,`customId`),
  88. KEY `orderId` (`orderId`),
  89. KEY `orderSn` (`orderSn`),
  90. KEY `customId` (`customId`)
  91. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='拼团成员';
  92. -- 订单关联拼团单(避开已占用的 groupId 组合字段)
  93. ALTER TABLE `xhOrder`
  94. ADD COLUMN `groupBuyId` int(11) NOT NULL DEFAULT 0 COMMENT '拼团单id' AFTER `id`,
  95. ADD KEY `groupBuyId` (`groupBuyId`);