20260723_group_buy.sql 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. `title` varchar(32) NOT NULL DEFAULT '' COMMENT '活动标题',
  7. `subtitle` varchar(64) NOT NULL DEFAULT '' COMMENT '活动副标题',
  8. `showCountdown` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否显示倒计时',
  9. `expand` tinyint(4) NOT NULL DEFAULT 0 COMMENT '商品展开',
  10. `startTime` int(11) NOT NULL DEFAULT 0 COMMENT '开始时间unix',
  11. `endTime` int(11) NOT NULL DEFAULT 0 COMMENT '结束时间unix',
  12. `desc` varchar(500) NOT NULL DEFAULT '' COMMENT '活动说明',
  13. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1有效 0无效',
  14. `delStatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '删除状态',
  15. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  16. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  17. PRIMARY KEY (`id`),
  18. KEY `mainId` (`mainId`),
  19. KEY `main_time` (`mainId`,`startTime`,`endTime`)
  20. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团购活动批次';
  21. CREATE TABLE IF NOT EXISTS `xhGroupBuyGoods` (
  22. `id` int(11) NOT NULL AUTO_INCREMENT,
  23. `activityId` int(11) NOT NULL DEFAULT 0 COMMENT '活动批次id',
  24. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  25. `goodsId` int(11) NOT NULL DEFAULT 0 COMMENT '商品id(可含规格子商品)',
  26. `specName` varchar(64) NOT NULL DEFAULT '' COMMENT '规格名',
  27. `price` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '团购价',
  28. `originPrice` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '原价快照',
  29. `stock` int(11) NOT NULL DEFAULT 0 COMMENT '团购库存',
  30. `limit` int(11) NOT NULL DEFAULT 0 COMMENT '单人限购',
  31. `groupSize` tinyint(4) NOT NULL DEFAULT 3 COMMENT '成团人数2/3/5',
  32. `virtualGroup` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否虚拟成团',
  33. `virtualMinutes` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟成团分钟数',
  34. `autoRefund` tinyint(4) NOT NULL DEFAULT 1 COMMENT '失败自动退款',
  35. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1展示 0隐藏(历史版本)',
  36. `name` varchar(128) NOT NULL DEFAULT '' COMMENT '商品名快照',
  37. `cover` varchar(255) NOT NULL DEFAULT '' COMMENT '封面快照',
  38. `realStock` int(11) NOT NULL DEFAULT 0 COMMENT '保存时真实库存快照',
  39. `delStatus` tinyint(4) NOT NULL DEFAULT 0 COMMENT '删除状态',
  40. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  41. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  42. PRIMARY KEY (`id`),
  43. KEY `activityId` (`activityId`),
  44. KEY `main_goods` (`mainId`,`goodsId`),
  45. KEY `activity_goods_status` (`activityId`,`goodsId`,`status`)
  46. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='团购活动商品版本';
  47. CREATE TABLE IF NOT EXISTS `xhGroupBuy` (
  48. `id` int(11) NOT NULL AUTO_INCREMENT,
  49. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  50. `shopId` int(11) NOT NULL DEFAULT 0 COMMENT '门店id',
  51. `activityId` int(11) NOT NULL DEFAULT 0 COMMENT '活动批次id',
  52. `activityGoodsId` int(11) NOT NULL DEFAULT 0 COMMENT '活动商品版本id',
  53. `goodsId` int(11) NOT NULL DEFAULT 0 COMMENT '商品id',
  54. `leaderCustomId` int(11) NOT NULL DEFAULT 0 COMMENT '团长客户id',
  55. `needNum` int(11) NOT NULL DEFAULT 0 COMMENT '成团所需人数',
  56. `currentNum` int(11) NOT NULL DEFAULT 0 COMMENT '已支付人数',
  57. `price` decimal(15,2) NOT NULL DEFAULT 0.00 COMMENT '团购价快照',
  58. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1拼团中 2成功 3失败 4已取消',
  59. `virtualGroup` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否虚拟成团',
  60. `deadline` int(11) NOT NULL DEFAULT 0 COMMENT '团截止unix',
  61. `successTime` datetime DEFAULT NULL COMMENT '成团时间',
  62. `failTime` datetime DEFAULT NULL COMMENT '失败时间',
  63. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  64. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  65. PRIMARY KEY (`id`),
  66. KEY `mainId` (`mainId`),
  67. KEY `activityGoodsId` (`activityGoodsId`),
  68. KEY `status_deadline` (`status`,`deadline`),
  69. KEY `goods_status` (`goodsId`,`status`)
  70. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='拼团单';
  71. CREATE TABLE IF NOT EXISTS `xhGroupBuyMember` (
  72. `id` int(11) NOT NULL AUTO_INCREMENT,
  73. `groupBuyId` int(11) NOT NULL DEFAULT 0 COMMENT '拼团单id',
  74. `mainId` int(11) NOT NULL DEFAULT 0 COMMENT '中央id',
  75. `orderId` int(11) NOT NULL DEFAULT 0 COMMENT '订单id',
  76. `orderSn` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  77. `customId` int(11) NOT NULL DEFAULT 0 COMMENT '客户id',
  78. `role` tinyint(4) NOT NULL DEFAULT 2 COMMENT '1团长 2成员',
  79. `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '1待支付 2已支付 3已失效',
  80. `joinTime` datetime DEFAULT NULL COMMENT '加入时间',
  81. `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  82. `updateTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  83. PRIMARY KEY (`id`),
  84. KEY `group_custom` (`groupBuyId`,`customId`),
  85. KEY `orderId` (`orderId`),
  86. KEY `orderSn` (`orderSn`),
  87. KEY `customId` (`customId`)
  88. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='拼团成员';
  89. -- 订单关联拼团单(避开已占用的 groupId 组合字段)
  90. ALTER TABLE `xhOrder`
  91. ADD COLUMN `groupBuyId` int(11) NOT NULL DEFAULT 0 COMMENT '拼团单id' AFTER `id`,
  92. ADD KEY `groupBuyId` (`groupBuyId`);