-- ----------------------------
-- Table structure for qimall_addons_group_buy_active
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_group_buy_active`;
CREATE TABLE `qimall_addons_group_buy_active`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '拼团商品活动id',
  `mall_id` int(11) NOT NULL COMMENT '商城id',
  `cate_id` int(11) NOT NULL DEFAULT 0 COMMENT '拼团分类id',
  `goods_id` int(11) NOT NULL COMMENT '商品id;对应goods主表',
  `start_at` int(11) NOT NULL DEFAULT 0 COMMENT '拼团开始时间',
  `end_at` int(11) NOT NULL DEFAULT 0 COMMENT '拼团结束时间',
  `effective_time` int(11) NOT NULL DEFAULT 0 COMMENT '拼团有效时间(分钟)',
  `group_size` int(11) NOT NULL DEFAULT 0 COMMENT '成团人数',
  `give_score` int(11) NOT NULL DEFAULT 0 COMMENT '团长赠送积分',
  `give_balance` int(11) NOT NULL DEFAULT 0 COMMENT '团长赠送余额',
  `virtual_group_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '虚拟成团类型【1全部 2拼团人数大于】',
  `virtual_group_size` int(11) NOT NULL DEFAULT 0 COMMENT '虚拟成团人数',
  `gt_group_size` int(11) NOT NULL DEFAULT 0 COMMENT '拼团人数大于N，则虚拟成团',
  `goods_stock` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '拼团库存',
  `limit_buy_num` int(11) NOT NULL DEFAULT 0 COMMENT '限制购买数量',
  `commander_level_limit` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '团长等级限制',
  `user_level_limit` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '团员等级限制',
  `is_virtual` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否开启虚拟成团',
  `group_status` int(1) NOT NULL DEFAULT 0 COMMENT '拼团商品状态;0未开始;1开团中;已结束2',
  `total_num` int(11) NOT NULL DEFAULT 0 COMMENT '已团件数',
  `total_orders` int(11) NOT NULL DEFAULT 0 COMMENT '成团订单数',
  `total_orders_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '成团订单金额',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mall_id_goods_id`(`mall_id`, `goods_id`) USING BTREE,
  INDEX `idx_cate_id`(`cate_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团活动商品表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_group_buy_active_goods_attr
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_group_buy_active_goods_attr`;
CREATE TABLE `qimall_addons_group_buy_active_goods_attr`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城id',
  `group_buy_active_id` int(11) NOT NULL DEFAULT 0 COMMENT 'qimall_addons_group_buy_active.id',
  `goods_id` int(11) NOT NULL COMMENT '商品id;对应goods主表',
  `attr_id` int(11) NOT NULL COMMENT '商品规格id;对应goods_attr.id;',
  `group_buy_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '价格',
  `stock` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '拼团库存',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_group_buy_active_id`(`group_buy_active_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团活动商品规格表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_group_buy_cate
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_group_buy_cate`;
CREATE TABLE `qimall_addons_group_buy_cate`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城id',
  `name` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '名称',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mall_id`(`mall_id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团分类表' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- Table structure for qimall_addons_group_buy_order
-- ----------------------------
DROP TABLE IF EXISTS `qimall_addons_group_buy_order`;
CREATE TABLE `qimall_addons_group_buy_order`  (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'id',
  `mall_id` int(11) NOT NULL DEFAULT 0 COMMENT '商城ID',
  `mch_id` int(11) NOT NULL DEFAULT 0 COMMENT '商户id',
  `user_id` int(11) NOT NULL DEFAULT 0 COMMENT '用户ID',
  `order_id` int(11) NOT NULL DEFAULT 0 COMMENT '主订单表id',
  `order_no` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '订单编号',
  `out_trade_no` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '外部交易单号',
  `group_buy_active_id` int(10) NOT NULL DEFAULT 0 COMMENT '拼团活动id',
  `open_group_id` int(10) NOT NULL DEFAULT 0 COMMENT '开团id',
  `commander_id` int(10) NOT NULL DEFAULT 0 COMMENT '拼团长id',
  `is_commander` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否团长 0：否：1:是',
  `goods_id` int(10) NOT NULL DEFAULT 0 COMMENT '商品id',
  `goods_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品名称',
  `goods_attr_id` int(11) NOT NULL DEFAULT 0 COMMENT '商品规格id',
  `goods_attr_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品规格名称',
  `pic_url` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '商品主图',
  `order_status` tinyint(1) NOT NULL DEFAULT 0 COMMENT '拼团状态 0待支付 1参团中  2拼团成功  3拼团失败 4未支付关闭',
  `price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '商品原售价',
  `group_buy_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '拼团商品价格',
  `num` int(10) NOT NULL DEFAULT 0 COMMENT '购买数量',
  `win_time` int(10) NOT NULL DEFAULT 0 COMMENT '拼中时间',
  `payment_type` tinyint(1) NOT NULL DEFAULT 0 COMMENT '支付方式：1.在线支付 2.货到付款 3.余额支付',
  `pay_time` int(11) NOT NULL DEFAULT 0 COMMENT '支付时间',
  `shipping_type` tinyint(1) NOT NULL DEFAULT 1 COMMENT '订单配送方式【1物流配送 2买家自提 3货到付款 4本地配送】',
  `shipping_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '运费',
  `total_pay_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '实际支付总费用(含运费）',
  `remark` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '用户订单备注',
  `is_pay` tinyint(1) NOT NULL DEFAULT 0 COMMENT '是否支付：0.未支付|1.已支付',
  `status` tinyint(1) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) NOT NULL DEFAULT 0 COMMENT '创建时间',
  `updated_at` int(11) NOT NULL DEFAULT 0 COMMENT '更新时间',
  `mobile` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人的手机号码',
  `receiver_name` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人姓名',
  `province` int(11) NULL DEFAULT 0 COMMENT '收货人所在省',
  `city` int(11) NULL DEFAULT 0 COMMENT '收货人所在城市',
  `area` int(11) NULL DEFAULT 0 COMMENT '收货人所在街道',
  `zip` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '收货人邮编',
  `address` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '详细地址',
  `region_name` varchar(200) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '地区名称（省市区[乡/镇]）',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `idx_mall_user`(`mall_id`, `user_id`) USING BTREE,
  INDEX `idx_order_sn`(`order_no`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '拼团订单' ROW_FORMAT = DYNAMIC;

-- ----------------------------
-- 插入定时任务表
-- ----------------------------
INSERT INTO `qimall_crontab_task`(`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES 
('拼团订单自动取消', 'group-buy-order/auto-close', 2, '0 */1 * * * *', 0, 1, 1640316846, 1640317959),
('自动结束拼团订单-已支付不能成团', 'group-buy-order/auto-finish', 2, '0 */5 * * * *', 0, 1, 1640316939, 1641267421),
('自动结束过期拼团活动', 'group-buy-order/auto-finish-active', 2, '0 30 0 * * *', 0, 1, 1640317086, 1640762873);

-- ----------------------------
-- 链接分类
-- ----------------------------
INSERT INTO `qimall_link_category` (`id`, `name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES
(18, 'group_activity', '拼团活动', 19, 1, NULL, 1, 1639814136, 1639814255),
(20, 'group_cate', '拼团分类', 19, 1, NULL, 1, 1639814497, 1640312920);

-- ----------------------------
-- 装修组件
-- ----------------------------
INSERT INTO `qimall_diy_components` (`code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES
('group-goods', '拼团商品', 'marketing', '', 999, 0, '{\"is_drag\":\"true\",\"is_up\":\"true\",\"id_down\":\"true\",\"is_copy\":\"true\"}', 999, 'GroupBuy', 1, 1634538238, 1634538238);

INSERT INTO `qimall_global_var_map`(`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES
('GroupBuy', '拼团', 'FromTypeMap', 1, 1, 1654569888, 1654569888),
('GroupBuy', '拼团', 'MarketingTypeMap', 1, 1, 1654569888, 1654569888);

