CREATE TABLE `qimall_addons_deposit_presale_active`  (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '拼团商品活动id',
  `presale_total` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '预定人数',
  `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) NULL DEFAULT 0 COMMENT '拼团开始时间',
  `end_at` int(11) NULL DEFAULT 0 COMMENT '拼团结束时间',
  `deposit_start_at` int(11) NULL DEFAULT 0 COMMENT '定金开始时间',
  `deposit_end_at` int(11) NULL DEFAULT 0 COMMENT '定金结束时间',
  `final_payment_start_at` int(11) NULL DEFAULT 0 COMMENT '尾款开始时间',
  `final_payment_end_at` int(11) NULL DEFAULT 0 COMMENT '尾款结束时间',
  `send_goods_start_at` int(11) NULL DEFAULT 0 COMMENT '发货开始时间',
  `send_goods_end_at` int(11) NULL DEFAULT 0 COMMENT '尾款结束时间',
  `effective_time` int(11) NULL DEFAULT 0 COMMENT '拼团有效时间(分钟)',
  `group_size` int(11) NULL DEFAULT 0 COMMENT '成团人数',
  `give_score` int(11) NULL DEFAULT 0 COMMENT '团长赠送积分',
  `give_balance` int(11) NULL DEFAULT 0 COMMENT '团长赠送余额',
  `virtual_group_type` tinyint(1) NULL DEFAULT 1 COMMENT '虚拟成团类型【1全部 2拼团人数大于】',
  `virtual_group_size` int(11) NULL DEFAULT 0 COMMENT '虚拟成团人数',
  `gt_group_size` int(11) NULL DEFAULT 0 COMMENT '拼团人数大于N，则虚拟成团',
  `goods_stock` int(10) UNSIGNED NULL DEFAULT 0 COMMENT '拼团库存',
  `limit_buy_num` int(11) 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 NULL DEFAULT '0' COMMENT '团员等级限制',
  `is_virtual` tinyint(1) NULL DEFAULT 0 COMMENT '是否开启虚拟成团',
  `group_status` int(1) NULL DEFAULT 0 COMMENT '拼团商品状态;0未开始;1开团中;已结束2',
  `total_num` int(11) NULL DEFAULT 0 COMMENT '已团件数',
  `total_orders` int(11) NULL DEFAULT 0 COMMENT '成团订单数',
  `total_orders_price` decimal(10, 2) 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,
  `presale_name` varchar(255) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '预售名称',
  `presale_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '预售价格',
  `deposit_price` decimal(10, 2) NULL DEFAULT NULL COMMENT '定金金额',
  `virtual_payment_num` int(10) NULL DEFAULT 0 COMMENT '虚拟付款人数',
  `virtual_paid_num` int(10) NULL DEFAULT 0 COMMENT '虚拟已付款人数',
  `purchase_limit_num` int(10) NULL DEFAULT 0 COMMENT '限购数量',
  `presale_rules` mediumtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '预售规则',
  `shipping_days` tinyint(3) UNSIGNED NULL DEFAULT 0 COMMENT '多少天后发货',
  `delivery_time_way` tinyint(1) UNSIGNED NOT NULL DEFAULT 0 COMMENT '发货方式',
  `minimum_purchase` smallint(3) UNSIGNED NOT NULL DEFAULT 0 COMMENT '最多起购',
  `activity_start_at` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活动开始时间',
  `activity_end_at` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '活动结束时间',
  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 AUTO_INCREMENT = 91 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团活动商品表' ROW_FORMAT = Dynamic;


CREATE TABLE `qimall_addons_deposit_presale_active_goods_attr`  (
  `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城id',
  `deposit_presale_active_id` int(11) NOT NULL DEFAULT 0 COMMENT 'qimall_addons_deposit_presale_active.id',
  `goods_id` int(11) NOT NULL COMMENT '商品id;对应goods主表',
  `attr_id` int(11) NOT NULL COMMENT '商品规格id;对应goods_attr.id;',
  `deposit_presale_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '价格',
  `deposit_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '定金',
  `stock` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '拼团库存',
  `purchase_limit_num` smallint(3) 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`(`deposit_presale_active_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 103 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团活动商品规格表' ROW_FORMAT = Dynamic;


CREATE TABLE `qimall_addons_deposit_presale_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 AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '拼团分类表' ROW_FORMAT = Dynamic;


CREATE TABLE `qimall_addons_deposit_presale_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 '外部交易单号',
  `final_out_trade_no` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '' COMMENT '外部交易单号(尾款)',
  `deposit_presale_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 '商品原售价',
  `deposit_presale_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '定金预售商品价格',
  `deposit_price` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '应付定金(活动创建时设定的)',
  `actual_deposit_paid` 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 '支付时间',
  `final_payment_time` int(11) UNSIGNED 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 AUTO_INCREMENT = 68 CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '拼团订单' ROW_FORMAT = Dynamic;




ALTER TABLE `qimall_addons_deposit_presale_active` 
ADD COLUMN `sales_num` int(10) UNSIGNED NOT NULL DEFAULT 0 COMMENT '销量' AFTER `activity_end_at`;

----2022/08/05-------
----插件链接分类------
INSERT INTO `qimall_link_category`(`name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES ('presale_activity', '预售活动', 19, 1, NULL, 1, 1649758396, 1649758812), 
  ('presale_cate', '预售分类', 19, 1, NULL, 1, 1649759024, 1649759024);

----2022/08/06-------
----商城装修---------
INSERT INTO `qimall_diy_components`(`code`, `title`, `group`, `icon`, `count`, `is_top`, `permission`, `sort`, `source`, `status`, `created_at`, `updated_at`) VALUES ('presale-goods', '预售商品', 'marketing', '', 999, 0, '{\"is_drag\":\"true\",\"is_up\":\"true\",\"id_down\":\"true\",\"is_copy\":\"true\"}', 999, 'DepositPresale', 1, 1634538238, 1634538238);
----插件定时任务-----
INSERT INTO `qimall_crontab_task`(`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('预售活动错过付尾款时间订单退款', 'deposit-presale/presale/deal-order', 2, '0 */40 * * * *', 0, 1, 1651160137, 1651160137);


