INSERT INTO `qimall_global_var_map`(`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES
('DoubleCopy', '二二复制', 'IncomeMap', 1, 1, 1654569888, 1654569888),
('DoubleCopy', '二二复制', 'FromTypeMap', 1, 1, 1654569888, 1654569888),
('equal_prize', '培育奖', 'CapitalTypeMap', 0, 1, 1654569888, 1654569888),
('freeze_fund', '冻结基金', 'CapitalTypeMap', 0, 1, 1654569888, 1654569888),
('second_prize', '平台补贴', 'CapitalTypeMap', 0, 1, 1654569888, 1654569888);


ALTER TABLE `qimall_addons_double_copy_commission`
MODIFY COLUMN `setting` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '生成数据时配置',
MODIFY COLUMN `settlement_type` tinyint(2) NOT NULL DEFAULT 0 COMMENT '结算状态[-1:已失效,0:未结算,1:已结算,2:部分结算]';

ALTER TABLE `qimall_addons_double_copy_level`
ADD COLUMN `open_ladder` tinyint(1) NULL DEFAULT 0 COMMENT '是否开启阶梯解冻设置[0=否,1=是]',
ADD COLUMN `ladder_setting` longtext NULL COMMENT '阶梯解冻设置';

ALTER TABLE `qimall_addons_double_copy_user`
ADD COLUMN `thaw_percent` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '上次解冻比例，单位：百分比',
ADD COLUMN `achievement` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '业绩，单位：元',
MODIFY COLUMN `frozen_fund` decimal(10, 2) NULL DEFAULT 0 COMMENT '冻结基金，单位：元';

INSERT INTO `qimall_crontab_task`(`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES
('二二复制分红池发放', 'double-copy/pool/send', 2, '0 50 0 * * *', 0, 1, 1663664792, 1663664792);


DROP TABLE IF EXISTS `qimall_addons_double_copy_achievement`;
CREATE TABLE `qimall_addons_double_copy_achievement` (
 `id` int(10) NOT NULL AUTO_INCREMENT,
 `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
 `user_id` int(10) NOT NULL DEFAULT '0' COMMENT '用户id',
 `order_detail_id` int(10) NOT NULL DEFAULT '0' COMMENT '订单详情id',
 `money` decimal(10,2) DEFAULT '0.00' 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,
 KEY `mall_id+user_id` (`mall_id`,`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='业绩记录';

DROP TABLE IF EXISTS `qimall_addons_double_copy_pool_level`;
CREATE TABLE `qimall_addons_double_copy_pool_level`  (
 `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
 `mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
 `name` varchar(250) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '名称',
 `level` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
 `achievement` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '所需一二市场总业绩,单位:元',
 `single_market` decimal(12, 2) NULL DEFAULT 0.00 COMMENT '单个市场业绩,单位:元',
 `current_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '当前池金额,单位:元',
 `total_money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '累计池金额,单位:元',
 `bonus_num` int(10) NOT NULL DEFAULT 0 COMMENT '当前分红人数(预留字段暂时没用)',
 `goods_setting` text CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL COMMENT '商品设置',
 `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
 `created_at` int(10) NULL DEFAULT 0 COMMENT '创建时间',
 `updated_at` int(10) NULL DEFAULT 0 COMMENT '更新时间',
 PRIMARY KEY (`id`) USING BTREE,
 INDEX `mall_level`(`mall_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '二二复制分红池等级' ROW_FORMAT = Dynamic;

DROP TABLE IF EXISTS `qimall_addons_double_copy_pool_log`;
CREATE TABLE `qimall_addons_double_copy_pool_log`  (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`send_id` int(10) NOT NULL DEFAULT 0 COMMENT 'double_copy_pool_send.id',
`mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
`user_id` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
`level` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
`total_bonus_money` decimal(12, 2) NULL DEFAULT 0.00 COMMENT '本次分红总额,单位:元',
`bonus_num` int(10) NULL DEFAULT 0 COMMENT '分红人数',
`bonus_money` decimal(12, 2) NULL DEFAULT 0.00 COMMENT '可得分红金额,单位:元',
`status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
`created_at` int(10) NULL DEFAULT 0 COMMENT '创建时间',
`updated_at` int(10) NULL DEFAULT 0 COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `send_id_user_id_level`(`send_id`, `user_id`, `level`) USING BTREE,
INDEX `mall_id`(`mall_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '二二复制分红池发放收益记录' ROW_FORMAT = Dynamic;

DROP TABLE IF EXISTS `qimall_addons_double_copy_pool_send`;
CREATE TABLE `qimall_addons_double_copy_pool_send`  (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
`level` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
`total_bonus_money` decimal(12, 2) NULL DEFAULT 0.00 COMMENT '本次分红总额,单位:元',
`bonus_num` int(10) NULL DEFAULT 0 COMMENT '分红人数',
`bonus_money` decimal(12, 2) NULL DEFAULT 0.00 COMMENT '每人可得分红金额,单位:元',
`cycle_type` int(10) NOT NULL DEFAULT 0 COMMENT '分红周期[1=日，2=周，3=月]',
`date` int(6) NOT NULL DEFAULT 0 COMMENT '执行日期，如:20220919',
`status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
`created_at` int(10) NULL DEFAULT 0 COMMENT '创建时间',
`updated_at` int(10) NULL DEFAULT 0 COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `mall_level`(`mall_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '二二复制分红池发放记录' ROW_FORMAT = Dynamic;

DROP TABLE IF EXISTS `qimall_addons_double_copy_pool_source`;
CREATE TABLE `qimall_addons_double_copy_pool_source`  (
  `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
  `level` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
  `order_detail_id` int(10) NOT NULL DEFAULT 0 COMMENT '订单详情ID',
  `money` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '插入金额,单位:元',
  `status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) NULL DEFAULT 0 COMMENT '创建时间',
  `updated_at` int(10) NULL DEFAULT 0 COMMENT '更新时间',
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `mall_id_level`(`mall_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '二二复制分红池资金来源记录' ROW_FORMAT = Dynamic;

DROP TABLE IF EXISTS `qimall_addons_double_copy_pool_user`;
CREATE TABLE `qimall_addons_double_copy_pool_user`  (
`id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
`user_id` int(10) NOT NULL DEFAULT 0 COMMENT '用户ID',
`level` int(10) NOT NULL DEFAULT 0 COMMENT '等级(权重)',
`pool_income` decimal(12, 2) NOT NULL DEFAULT 0.00 COMMENT '分红池总收益,单位:元',
`upgrade_status` smallint(6) NOT NULL DEFAULT 0 COMMENT '1条件升级，2购买指定商品升级，3手动升级',
`upgrade_level_at` int(10) NOT NULL DEFAULT 0 COMMENT '等级升级时间',
`status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '状态[-1:删除;0:禁用;1启用]',
`created_at` int(10) NULL DEFAULT 0 COMMENT '创建时间',
`updated_at` int(10) NULL DEFAULT 0 COMMENT '更新时间',
PRIMARY KEY (`id`) USING BTREE,
INDEX `mall_user_id_level`(`mall_id`, `user_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 17 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT = '二二复制分红池用户' ROW_FORMAT = Dynamic;


/** 奖励类型：积分*/
ALTER TABLE `qimall_addons_double_copy_commission`
ADD COLUMN `reward_currency`  varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'commission' COMMENT '奖励类型：佣金-commission，积分-score' AFTER `updated_at`;

ALTER TABLE `qimall_addons_double_copy_user`
ADD COLUMN `score`  decimal(10,2) NOT NULL DEFAULT 0 COMMENT '已结算积分' AFTER `achievement`,
ADD COLUMN `frozen_score`  decimal(10,2) NOT NULL DEFAULT 0 COMMENT '未结算积分' AFTER `score`,
ADD COLUMN `frozen_fund_score`  decimal(10,2) NOT NULL DEFAULT 0 COMMENT '冻结基金积分' AFTER `frozen_score`;



ALTER TABLE  `qimall_addons_double_copy_pool_source`  ADD COLUMN `reward_currency`  varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'commission' COMMENT '奖励类型：佣金-commission，积分-score' AFTER `updated_at`;
ALTER TABLE  `qimall_addons_double_copy_pool_log`  ADD COLUMN `reward_currency`  varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'commission' COMMENT '奖励类型：佣金-commission，积分-score' AFTER `updated_at`;
ALTER TABLE  `qimall_addons_double_copy_pool_send`  ADD COLUMN `reward_currency`  varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'commission' COMMENT '奖励类型：佣金-commission，积分-score' AFTER `updated_at`;

ALTER TABLE `qimall_addons_double_copy_pool_level`
ADD COLUMN `current_score`  decimal(12,2) NOT NULL DEFAULT 0 COMMENT '当前池积分' AFTER `user_level`,
ADD COLUMN `total_score`  decimal(12,2) NOT NULL DEFAULT 0 COMMENT '累计池积分' AFTER `current_score`;

