20260723_group_buy.sql 5.6 KB

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