INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('write_off_prize', '核销奖励', 'CapitalTypeMap', '0', '1', '1654569888', '1654569888');
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('manage_prize', '管理奖励', 'CapitalTypeMap', '0', '1', '1654569888', '1654569888');
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('promote_prize', '促销奖励', 'CapitalTypeMap', '0', '1', '1654569888', '1654569888');
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('achievement_promote_prize', '业绩促销奖励', 'CapitalTypeMap', '0', '1', '1654569888', '1654569888');
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('WriteOff', '核销员', 'IncomeMap', '1', '1', '1654569888', '1654569888');
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `status`, `created_at`, `updated_at`) VALUES ('WriteOff', '核销员', 'FromTypeMap', '1', '1', '1654569888', '1654569888');
INSERT INTO `qimall_crontab_task` (`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('核销员促销业绩奖励结算', 'write-off/write-off-crontab/settle', '2', '0 */60 * * * *', '0', '1', '1691749140', '1693563705');

CREATE TABLE `qimall_addons_write_off_award_log` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL DEFAULT '0',
  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
  `achievement_sum` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '总业绩',
  `award_money` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖励金额',
  `rate` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖励比例',
  `is_settlement` tinyint(4) DEFAULT '0' COMMENT '是否已结算打款 1：是',
  `created_at` int(11) NOT NULL DEFAULT '0',
  `updated_at` int(11) NOT NULL DEFAULT '0',
  `status` tinyint(1) NOT NULL DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `mall_id` (`mall_id`) USING BTREE,
  KEY `user_id` (`user_id`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=COMPACT COMMENT='奖励明细';

CREATE TABLE `qimall_addons_write_off_commission_job` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `date_limit` varchar(45) NOT NULL DEFAULT '' COMMENT '结算开始~结束日期',
  `compute_period` tinyint(1) NOT NULL DEFAULT '0' COMMENT '结算周期：1天，2周，3月',
  `status` tinyint(4) 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` (`mall_id`,`date_limit`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='核销员已结算日期记录表';

CREATE TABLE `qimall_addons_write_off_level` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT '0' COMMENT '商城ID',
  `level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '等级',
  `name` varchar(45) NOT NULL DEFAULT '' COMMENT '等级名称',
  `is_enable_write_off_reward` tinyint(4) DEFAULT '0' COMMENT '核销阶梯式奖励设置[0:关闭;1启用]',
  `write_off_reward_proportion` text COMMENT '奖励比例集合',
  `is_enable_promote_reward` tinyint(4) DEFAULT '0' COMMENT '促销奖励设置[0:关闭;1启用]',
  `promote_reward_prize` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '促销奖励比例',
  `is_enable_promote_reward_achievement` tinyint(4) DEFAULT '0' COMMENT '促销业绩阶梯奖励设置[0:关闭;1启用]',
  `promote_achievement_reward_proportion` text COMMENT '促销奖励比例集合',
  `status` tinyint(4) 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` (`mall_id`) USING BTREE,
  KEY `mall_id+level` (`mall_id`,`level`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC COMMENT='股东等级表';

CREATE TABLE `qimall_addons_write_off_member` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
  `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `num` int(10) NOT NULL DEFAULT '0' COMMENT '核销数量',
  `total_num` int(10) NOT NULL DEFAULT '0' COMMENT '累计核销数量',
  `code` int(8) NOT NULL DEFAULT '0' COMMENT '核销码',
  `code_url` varchar(255) NOT NULL DEFAULT '' COMMENT '核销二维码',
  `status` tinyint(4) 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`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

CREATE TABLE `qimall_addons_write_off_member_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
  `setting_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '设置ID',
  `goods_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商品ID',
  `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `change_type` char(12) NOT NULL DEFAULT '' COMMENT '操作类型：add-增加，sub-减少',
  `change_num` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '操作数量',
  `current_num` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '当前数量',
  `order_no` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  `store_id` int(11) NOT NULL DEFAULT '0' COMMENT '门店id',
  `source_table` varchar(255) NOT NULL DEFAULT '' COMMENT '来源表',
  `source_table_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '操作来源业务id',
  `desc` varchar(255) NOT NULL DEFAULT '' COMMENT '说明',
  `status` tinyint(4) 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`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

CREATE TABLE `qimall_addons_write_off_promote_order_log` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
  `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `order_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单ID',
  `order_no` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '订单编号',
  `order_detail_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '订单详情ID',
  `pay_money` decimal(10,2) DEFAULT NULL COMMENT '订单实付金额',
  `buy_user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '购买用户ID',
  `status` tinyint(4) 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`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

CREATE TABLE `qimall_addons_write_off_setting` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
  `is_enable` tinyint(4) NOT NULL DEFAULT '0' COMMENT '启用状态[0禁用; 1启用]',
  `goods_id` int(11) NOT NULL COMMENT '商品ID',
  `give_num` decimal(10,2) unsigned NOT NULL DEFAULT '0.00' COMMENT '奖励数量',
  `is_enable_promote_reward` tinyint(4) DEFAULT '0' COMMENT '促销奖励设置[0:关闭;1启用]',
  `promote_reward_prize` decimal(12,2) NOT NULL DEFAULT '0.00' COMMENT '促销奖励比例',
  `settlement_method` tinyint(4) NOT NULL DEFAULT '0' COMMENT '计算方式[0订单完成, 1订单支付]',
  `status` tinyint(4) 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`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

CREATE TABLE `qimall_addons_write_off_user` (
  `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',
  `store_id` int(11) NOT NULL DEFAULT '0' COMMENT '门店id',
  `level` tinyint(4) NOT NULL DEFAULT '0' COMMENT '等级',
  `commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '核销佣金，单位：元',
  `promote_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '促销佣金，单位：元',
  `manage_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '管理佣金，单位：元',
  `total_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '累计总佣金，单位：元',
  `total_num` int(10) NOT NULL DEFAULT '0' COMMENT '累计核销数量',
  `is_enable_manage_reward` tinyint(4) DEFAULT '0' COMMENT '是否开启管理奖[0:关闭;1启用]',
  `status` tinyint(4) DEFAULT '1' COMMENT '状态[-1:删除;0:禁用;1启用]',
  `created_at` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  `updated_at` int(10) NOT NULL DEFAULT '0' COMMENT '修改时间',
  `promote_achievement_commission` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '促销业绩佣金，单位：元',
  PRIMARY KEY (`id`) USING BTREE,
  KEY `mall_id` (`mall_id`) USING BTREE,
  KEY `user_id` (`user_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='核销员用户表';

CREATE TABLE `qimall_addons_write_off_member_code` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `mall_id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT '商城ID',
  `user_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '用户ID',
  `code` int(8) NOT NULL DEFAULT '0' COMMENT '核销码',
  `is_used` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否已核销[0否; 1是]',
  `status` tinyint(4) 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`),
  KEY `user_id` (`user_id`) USING BTREE,
  KEY `mall_id + code` (`mall_id`,`code`) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4 COMMENT='会员核销码记录表';