CREATE TABLE `qimall_addons_lucky_group_activity` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `mall_id` int(11) NOT NULL COMMENT '商城ID',
      `cate_id` int(11) NOT NULL DEFAULT '0' COMMENT '分类id',
      `title` varchar(20) NOT NULL DEFAULT '0' COMMENT '活动标题',
      `start_time` varchar(20) NOT NULL DEFAULT '' COMMENT '活动开始时间',
      `end_time` varchar(20) NOT NULL DEFAULT '0.00' COMMENT '活动结束时间',
      `group_num` int(11) NOT NULL DEFAULT '0' COMMENT '成团人数',
      `random_win_num` int(11) NOT NULL DEFAULT '0' COMMENT '随机拼中人数',
      `virtual_num` int(11) NOT NULL DEFAULT '1' COMMENT '虚拟人数',
      `expend_type` varchar(64) NOT NULL DEFAULT '' COMMENT '消耗类型',
      `expend_num` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '消耗数量',
      `attend_user_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '参团奖励用户 1 全部 2 拼中 3 拼不中',
     `attend_award_setting` text COMMENT '参团奖励设置',
      `attend_prize` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖励金额',
      `win_times` int(11) DEFAULT NULL COMMENT '累计拼中次数',
      `win_award_setting` text COMMENT '拼中奖励设置',
      `is_percent_pool_trans` tinyint(2) DEFAULT NULL COMMENT '是否按百分比算分配奖金池金额【1是 0否】',
      `pool_trans_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '分配奖金池金额',
      `enable_commison` tinyint(2) NOT NULL DEFAULT '0' COMMENT '是否开启分佣【1是 0否】',
      `team_commission_setting` text COMMENT '渠道奖佣金设置',
      `equal_commission_setting` text COMMENT '平级奖佣金设置',
      `over_commission_setting` text COMMENT '越级奖佣金设置',
      `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
      `created_at` int(11) DEFAULT NULL,
      `updated_at` int(11) DEFAULT NULL,
      PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='拼团活动表';

CREATE TABLE `qimall_addons_lucky_group_activity_statistics` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `mall_id` int(10) unsigned NOT NULL,
   `activity_id` int(10) unsigned NOT NULL COMMENT '活动 id',
   `group_amounts` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计成团金额',
   `group_peoples` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '累计成团人数',
   `group_periods` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '成团期数',
   `group_failed_times` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '所有会员累计失败次数',
   `deplete_balances` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计消耗余额',
   `deplete_scores` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计消耗积分',
   `win_reward_balances` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计拼中奖励余额',
  `win_reward_scores` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计拼中奖励积分',
   `distribute_bonus_pool_amounts` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '累计分配奖金池金额',
   `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
   `created_at` int(10) unsigned NOT NULL DEFAULT '0',
   `updated_at` int(10) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
  KEY `idx_ma_id` (`mall_id`,`activity_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='活动数据统计结果记录表';

CREATE TABLE `qimall_addons_lucky_group_attend_times_log` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'id',
 `mall_id` int(11) DEFAULT '0' COMMENT '商城ID',
  `user_id` int(10) DEFAULT '0' COMMENT '用户id',
  `num` int(10) DEFAULT '0' COMMENT '拼团次数(支持负数)',
  `before_num` int(10) NOT NULL DEFAULT '0' COMMENT '变动前次数',
  `desc` varchar(255) NOT NULL COMMENT '描述',
  `type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '0系统赠送 1每日赠送',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int(10) NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='参团次数日志表';
CREATE TABLE `qimall_addons_lucky_group_balance_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
  `user_id` int(11) unsigned NOT NULL DEFAULT '0',
  `order_no` varchar(30) NOT NULL DEFAULT '' COMMENT '订单编号',
  `level` int(11) NOT NULL DEFAULT '0' COMMENT '拼团等级',
  `change_num` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '奖励数量',
  `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
  `capital_type` varchar(255) NOT NULL DEFAULT '' COMMENT '资金类型',
  `is_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放：0：否；1：是；2:无效',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
  `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='余额记录表';

CREATE TABLE `qimall_addons_lucky_group_banners` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) unsigned NOT NULL,
  `sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '序号',
  `title` varchar(255) NOT NULL DEFAULT '' COMMENT '图片标题',
  `pic_link` varchar(255) NOT NULL DEFAULT '' COMMENT '图片跳转链接',
  `pic_path` varchar(255) NOT NULL DEFAULT '' COMMENT '图片保存路径',
  `bgcolor` varchar(100) NOT NULL DEFAULT '' COMMENT '背景色',
  `is_show` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否展示，1：是，0：不是',
  `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0',
  `updated_at` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='广告轮播图记录表';

CREATE TABLE `qimall_addons_lucky_group_bonus_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `user_num` int(11) NOT NULL DEFAULT '0' COMMENT '参与分红人数',
  `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '总金额',
  `after_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '发放后奖金池金额',
  `user_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
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='奖金池分红日志';

CREATE TABLE `qimall_addons_lucky_group_bonus_pool` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖金池剩余金额',
  `total_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖金池总额',
  `virtual_send_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '虚拟发放金额',
  `mall_id` int(11) NOT NULL COMMENT '商城ID',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) DEFAULT NULL,
  `updated_at` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='奖金池金额存储表';

CREATE TABLE `qimall_addons_lucky_group_category` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) unsigned NOT NULL,
  `sort` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '序号',
  `title` varchar(255) NOT NULL DEFAULT '' COMMENT '图片标题',
  `pic_path` varchar(255) NOT NULL DEFAULT '' COMMENT '图片保存路径',
  `bgcolor` varchar(100) NOT NULL DEFAULT '' COMMENT '背景色',
  `pic_adv` varchar(255) NOT NULL DEFAULT '' COMMENT '详情广告图',
  `adv_link` varchar(1000) NOT NULL DEFAULT '' COMMENT '广告图片跳转链接',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0',
  `updated_at` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='分类表';

CREATE TABLE `qimall_addons_lucky_group_commission_log` (
   `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
   `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
   `user_id` int(11) unsigned NOT NULL DEFAULT '0',
   `order_no` varchar(30) NOT NULL DEFAULT '' COMMENT '订单编号',
   `level` int(11) NOT NULL DEFAULT '0' COMMENT '拼团等级',
   `change_num` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '奖励数量',
   `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
   `capital_type` varchar(255) NOT NULL DEFAULT '' COMMENT '资金类型',
   `is_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放：0：否；1：是；2:无效',
   `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
   `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
   `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
   PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='佣金记录表';

CREATE TABLE `qimall_addons_lucky_group_frozen_log` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
    `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
    `level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '拼团等级',
    `source_id` int(11) NOT NULL DEFAULT '0' COMMENT '来源ID',
    `source_table` varchar(45) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '来源表',
    `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '金额',
    `is_send` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否发放  0未发放  1已发放  2部分发放',
    `prize_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT '奖励类型  1参团奖励  2拼中奖励  3奖金池奖励  4渠道奖佣金奖  5平级佣金奖  6越级佣金奖  7推荐奖',
    `money_type` varchar(64) NOT NULL DEFAULT '' COMMENT '资金类型   余额balance  积分score  佣金commission',
    `extra` varchar(1000) NOT NULL DEFAULT '' COMMENT '额外信息',
    `desc` varchar(255) NOT NULL DEFAULT '' 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',
    `has_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '已发放金额',
    `settlement_interval` tinyint(1) NOT NULL DEFAULT '0' COMMENT '结算周期   1 每天  2 每周一  3 每月一号',
    `bonus_pool_sum` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖金池总额',
    `bonus_pool_ratio` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖金池比例',
    `preliminary_win_num` int(10) NOT NULL DEFAULT '0' COMMENT '初步拼中次数',
    `bonus_pool_limit` decimal(10,2) DEFAULT '0.00' COMMENT '奖金池上限',
    `bonus_log_id` int(11) NOT NULL DEFAULT '0' COMMENT '结算奖金池记录id',
    PRIMARY KEY (`id`) USING BTREE,
    KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='幸运拼团冻结资金明细';

CREATE TABLE `qimall_addons_lucky_group_goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `goods_id` int(10) NOT NULL DEFAULT '0' COMMENT '商品id',
  `activity_id` int(10) NOT NULL DEFAULT '0' COMMENT '活动ID',
  `join_num` int(11) NOT NULL DEFAULT '0' COMMENT '参团人数',
  `open_times` int(11) NOT NULL DEFAULT '0' COMMENT '成团期数，每开一次算一期',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) NOT NULL DEFAULT '0',
  `updated_at` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='幸运拼团商品表';

CREATE TABLE `qimall_addons_lucky_group_level` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城ID',  `level` int(11) NOT NULL DEFAULT '0' COMMENT '等级权重',
  `name` varchar(32) NOT NULL DEFAULT '' COMMENT '等级名称',
  `team_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '渠道奖佣金',
  `is_percent_team` tinyint(1) NOT NULL DEFAULT '0' COMMENT '渠道奖类型 0百分比 1 固定金额',
  `equal_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '平级奖佣金',
  `is_percent_equal` tinyint(1) NOT NULL DEFAULT '0' COMMENT '平级奖类型 0百分比 1 固定金额',
  `over_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '越级奖佣金',
  `is_percent_over` tinyint(1) NOT NULL DEFAULT '0' COMMENT '越级奖类型 0百分比 1 固定金额',
  `is_auto_upgrade` int(11) NOT NULL DEFAULT '0' COMMENT '是否开启升级设置【1是 0否】',
   `upgrade_type_goods` int(11) NOT NULL DEFAULT '0' COMMENT '开启商品升级【1是 0否】',
  `upgrade_type_condition` int(11) NOT NULL DEFAULT '0' COMMENT '开启条件升级【1是 0否】',
  `checked_condition_values` longtext COMMENT '升级条件设置值列表',
  `checked_condition_keys` text COMMENT '选中条件的key值集合',
  `condition_type` tinyint(3) NOT NULL DEFAULT '0' COMMENT '条件升级选项【0未选择 1满足其一 2满足所有】',
  `goods_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '商品升级类型，1- 任意商品 2- 指定商品',
  `goods_ids` text COMMENT '指定升级商品的ID集合',
  `buy_goods_type` tinyint(1) NOT NULL DEFAULT '2' COMMENT '购买商品升级时间场景【0订单完成 1支付】',
  `init_attend_times` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '每日参团次数',
  `desc` longtext COMMENT '等级权益描述',
  `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 '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='幸运拼团等级';

CREATE TABLE `qimall_addons_lucky_group_lottery_period` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `open_reward_log_id` int(11) NOT NULL DEFAULT '0' COMMENT '开团日志id',
  `activity_id` int(11) NOT NULL DEFAULT '0' COMMENT '活动D',
  `goods_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品ID',
  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '会员ID',
  `order_id` int(10) NOT NULL DEFAULT '0' COMMENT '订单id',
  `number` int(10) NOT NULL DEFAULT '0' COMMENT '期数',
  `win_order_ids` varchar(1000) DEFAULT NULL COMMENT '拼中订单集',
  `loss_order_ids` varchar(1000) DEFAULT NULL COMMENT '拼不中订单集',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) NOT NULL DEFAULT '0',
  `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='幸运拼团开奖期数';

CREATE TABLE `qimall_addons_lucky_group_mall_open_group_statistics` (
   `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
   `mall_id` int(10) unsigned NOT NULL,
   `win_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '拼中金额',
   `loss_money` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '拼不中金额',
   `attend_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '参团人数',
   `win_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '拼中人数',
   `loss_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '拼不中人数',
   `statistics_date` varchar(255) NOT NULL DEFAULT '' COMMENT '统计日期',
   `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
   `created_at` int(10) unsigned NOT NULL DEFAULT '0',
   `updated_at` int(10) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (`id`),
   KEY `idx_mall_id` (`mall_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商城开团数据统计';

CREATE TABLE `qimall_addons_lucky_group_mall_statistics` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) unsigned NOT NULL,
  `attend_commission` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '参团奖金',
  `attend_money` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '参团金额',
  `win_money` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '拼中金额',
  `attend_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '参团人数',
  `win_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '拼中人数',
  `total_attend_commission` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总发放参团奖金',
  `total_attend_money` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总参团金额',
  `total_win_money` decimal(14,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '总拼中金额',
  `total_attend_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '总参团人数',
  `total_win_peoples` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '总拼中人数',
  `statistics_month` varchar(255) NOT NULL DEFAULT '' COMMENT '统计月份',
  `status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0',
  `updated_at` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `idx_mall_id` (`mall_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COMMENT='商城默认汇总数据统计';

CREATE TABLE `qimall_addons_lucky_group_open_reward_log` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'id',
      `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
      `activity_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '活动ID',
      `goods_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商品ID',
      `order_id` varchar(1000) NOT NULL DEFAULT '' COMMENT '订单ID',
      `win_order_ids` varchar(1000) NOT NULL DEFAULT '0' COMMENT '本次开奖拼中订单',
      `group_require_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '开团需要人数',
      `virtual_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '活动设置的虚拟人数',
      `real_group_require_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '真实开团需要人数',
      `attend_order_num` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '本次可开奖订单数（人数）',
      `expend_type` varchar(50) NOT NULL DEFAULT '0' COMMENT '消耗类型',
      `expend_num` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '消耗量',
      `win_reward_scores` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '拼中奖励积分',
      `win_reward_balances` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '拼中奖励余额',
      `distribute_bonus_pool_amounts` decimal(12,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '分配奖金池金额',
      `attend_reward_amounts` decimal(12,2) unsigned 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' COMMENT '创建时间',
      `updated_at` int(11) DEFAULT '0',
      PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='开奖日志';

CREATE TABLE `qimall_addons_lucky_group_order` (
     `id` int(10) NOT NULL AUTO_INCREMENT COMMENT 'id',
     `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
     `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
     `order_no` varchar(100) NOT NULL COMMENT '订单编号',
     `activity_id` int(10) NOT NULL DEFAULT '0' COMMENT '拼团活动id',
     `goods_id` int(10) NOT NULL DEFAULT '0' COMMENT '商品id',
     `goods_attr_id` int(11) NOT NULL DEFAULT '0' COMMENT '商品规格id',
     `group_status` tinyint(1) NOT NULL DEFAULT '0' COMMENT '拼团状态 0待支付 1参团中  2拼团成功  3拼团失败',
     `attend_type` tinyint(1) NOT NULL DEFAULT '1' COMMENT '拼团方式    1手动拼团   2自动拼团',
     `money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单金额',
     `buy_nums` int(10) NOT NULL DEFAULT '0' COMMENT '购买数量',
     `win_time` int(10) NOT NULL DEFAULT '0' COMMENT '拼中时间',
     `win_nums` int(10) NOT NULL DEFAULT '0' COMMENT '拼中次数',
     `payment_type` tinyint(1) NOT NULL DEFAULT '0' COMMENT '支付方式：1.在线支付 2.货到付款 3.余额支付',
     `pay_at` int(11) NOT NULL DEFAULT '0' COMMENT '支付时间',
     `order_id` varchar(255) NOT NULL DEFAULT '' COMMENT '主订单id,多个订单使用逗号隔开',
     `mch_id` int(11) NOT NULL DEFAULT '0' COMMENT '多商户id，0表示商城订单',
     `total_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单总金额(含运费)',
     `total_pay_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '实际支付总费用(含运费）',
     `shipping_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '运费',
     `total_goods_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单商品总金额(优惠后)',
     `total_goods_original_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单商品总金额(优惠前)',
     `remark` varchar(255) CHARACTER SET utf8mb4 NOT NULL DEFAULT '' COMMENT '用户订单备注',
     `is_pay` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否支付：0.未支付|1.已支付',
     `address_id` int(11) NOT NULL DEFAULT '0' COMMENT '地址id',
     `major_data` text COMMENT '主订单数据',
     `extra` text COMMENT '额外信息',
     `open_times` int(11) NOT NULL DEFAULT '0' COMMENT '开奖次数',
     `yu_attend_times` int(11) NOT NULL DEFAULT '0' COMMENT '预扣参团次数',
     `expend_type` varchar(64) NOT NULL DEFAULT '' COMMENT '消耗类型',
     `consume` 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' COMMENT '创建时间',
     `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
     PRIMARY KEY (`id`) USING BTREE,
     KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE,
     KEY `idx_order_no` (`order_no`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='拼团订单';
CREATE TABLE `qimall_addons_lucky_group_order_marketing` (
     `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '主键',
     `order_id` int(10) NOT NULL DEFAULT '0' COMMENT 'lucky_group_order表id',
     `give_score` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '赠送积分',
     `give_balance` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '赠送余额',
     `give_currency` text COMMENT '赠送货币(json字符串保存)',
     `deduct_score` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '减扣积分',
     `deduct_currency` text COMMENT '减扣货币(json字符串保存)',
     `pay_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '商品实际付款金额，单位：元',
     `full_reduce_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '满减金额，单位：元',
     `coupon_discount_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '优惠券优惠金额，单位：元',
     `member_price_deduct` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '会员价优惠',
     `user_coupon_id` varchar(1000) NOT NULL DEFAULT '' COMMENT '用户优惠券id map',
     `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
     `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
     `updated_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '修改时间',
     PRIMARY KEY (`id`) USING BTREE,
     KEY `order_id` (`order_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='幸运拼团订单营销赠扣表';
CREATE TABLE `qimall_addons_lucky_group_score_log` (
      `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
      `mall_id` int(11) unsigned NOT NULL DEFAULT '0',
      `user_id` int(11) unsigned NOT NULL DEFAULT '0',
      `order_no` varchar(30) NOT NULL DEFAULT '' COMMENT '订单编号',
      `level` int(11) NOT NULL DEFAULT '0' COMMENT '拼团等级',
      `change_num` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '奖励数量',
      `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '变动说明',
      `capital_type` varchar(255) NOT NULL DEFAULT '' COMMENT '资金类型',
      `is_send` tinyint(1) NOT NULL DEFAULT '0' COMMENT '是否发放：0：否；1：是；2:无效',
      `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
      `created_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '添加时间戳',
      `updated_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间戳',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `idx_mall_user` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='积分记录表';

CREATE TABLE `qimall_addons_lucky_group_user` (
   `id` int(11) NOT NULL AUTO_INCREMENT,
   `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
   `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
   `level` tinyint(3) NOT NULL DEFAULT '0' COMMENT '拼团等级',
   `attend_times` int(11) NOT NULL DEFAULT '0' COMMENT '参团次数',
   `has_attend_times` int(11) NOT NULL DEFAULT '0' COMMENT '已参团次数',
   `pool_commission` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '奖金池奖金',
   `attend_money` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '参团金额',
   `invited_num` int(11) NOT NULL DEFAULT '0' COMMENT '邀请用户数',
   `win_orders` int(11) NOT NULL DEFAULT '0' COMMENT '拼中订单数，如果一个订单有多次拼中，累加算总和',
   `max_order_money` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '单笔订单最大金额',
   `win_num` int(11) NOT NULL DEFAULT '0' COMMENT '中奖次数',
   `balance` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '余额',
   `score` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '积分',
   `commission` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '佣金',
   `frozen_commission` decimal(11,2) NOT NULL DEFAULT '0.00' COMMENT '冻结佣金',
   `clear_attend_times_at` int(11) NOT NULL DEFAULT '0' COMMENT '清零参与次数时间',
   `give_attend_times_at` int(11) NOT NULL DEFAULT '0' COMMENT '最后赠送次数时间',
   `upgrade_status` tinyint(1) NOT NULL DEFAULT '3' COMMENT '升级方式，1条件升级 2 购买指定商品升级 3手动升级',
   `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 '更新时间',
   `upgrade_level_at` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '最后升级时间',
   PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='拼团用户';

CREATE TABLE `qimall_addons_lucky_group_visit_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) NOT NULL COMMENT '商城ID',
  `visit_user_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '访问者用户ID',
  `view_num` int(11) NOT NULL DEFAULT '0' COMMENT '浏览次数',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
   PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='拼团访问日志表';

CREATE TABLE `qimall_addons_lucky_group_win_log` (
  `id` smallint(6) unsigned NOT NULL AUTO_INCREMENT COMMENT '表id',
  `mall_id` int(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `activity_id` int(11) NOT NULL DEFAULT '0' COMMENT '活动id',
  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
  `win_num` int(11) NOT NULL DEFAULT '0' COMMENT '累计拼中次数',
  `loss_num` int(11) NOT NULL DEFAULT '0' COMMENT '连续拼不中次数',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(11) DEFAULT '0' COMMENT '创建时间',
  `updated_at` int(11) DEFAULT '0' COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPACT COMMENT='幸运拼团拼中与拼不中记录表';


INSERT INTO `qimall_link_category`( `name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES ('lucky_group_activity', '幸运拼团活动', 19, 1, '', 1, 1652868522, 1652868522);
INSERT INTO `qimall_link_category`( `name`, `title`, `pid`, `is_list`, `remark`, `status`, `created_at`, `updated_at`) VALUES ('lucky_group_cate', '幸运拼团分类', 19, 1, '', 1, 1652868551, 1652868551);

