CREATE TABLE `qimall_addons_boss_achievement_level`  (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `mall_id` int(10) NOT NULL DEFAULT 0 COMMENT '商城ID',
  `level` tinyint(4) NOT NULL DEFAULT -1 COMMENT '股东等级',
  `name` varchar(45) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '等级名称',
  `is_auto_upgrade` int(10) NOT NULL DEFAULT 0 COMMENT '是否自动升级【0否，1是】',
  `upgrade_type_condition` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否开启条件升级【0否，1是】',
  `condition_type` tinyint(4) NOT NULL DEFAULT 1 COMMENT '满足条件：1满足其一，2满足所有',
  `checked_condition_values` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '升级条件的值集合',
  `checked_condition_keys` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '被选中的升级条件的key集合',
  `upgrade_type_goods` tinyint(6) NOT NULL DEFAULT 0 COMMENT '是否开启购买商品升级【0否，1是】',
  `goods_ids` varchar(3000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '指定商品id集合',
  `goods_list` varchar(5000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '指定商品信息列表json',
  `goods_type` smallint(6) NOT NULL DEFAULT 0 COMMENT '商品升级类型：1任意商品，2指定商品',
  `buy_goods_type` tinyint(4) NOT NULL DEFAULT 0 COMMENT '购买商品升级条件：0订单完成，1支付完成',
  `explain` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL COMMENT '等级说明',
  `status` tinyint(4) 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,
  INDEX `mall_id+level`(`mall_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '股东业绩等级表' ROW_FORMAT = Dynamic;

CREATE TABLE `qimall_addons_boss_achievement_level_setting`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `mall_id` int(11) NOT NULL COMMENT '商城ID',
  `level_id` int(10) NULL DEFAULT 0 COMMENT '对应qimall_addons_boss_achievement_level.id',
  `level` int(11) NOT NULL DEFAULT 0 COMMENT '等级',
  `commission_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '分佣类型：积分score;佣金：commission',
  `from_type` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '0' COMMENT '分佣类型：股东;',
  `standard_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '达标业绩，单位：元',
  `prize` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '业绩分红，单位：百分比',
  `achievement_goods_ids` varchar(3000) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '指定商品id集合',
  `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 `mall_id+level`(`mall_id`, `level`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '股东业绩等级设置' ROW_FORMAT = Dynamic;

CREATE TABLE `qimall_addons_boss_achievement_month`  (
  `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',
  `achievement` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '当月总业绩，单位：元',
  `bonus` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '可得分红，单位：元',
  `settlement_money` decimal(10, 2) NOT NULL DEFAULT 0.00 COMMENT '结算业绩，单位：元',
  `settlement_num` int(10) NOT NULL DEFAULT 0 COMMENT '结算人数',
  `standard_money` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '结算达标金额，单位：元',
  `month` int(10) NOT NULL DEFAULT 0 COMMENT '月份，如：202207',
  `is_settlement` 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,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `mall_id+user_id+month`(`mall_id`, `user_id`, `month`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '股东每月业绩记录' ROW_FORMAT = Dynamic;

CREATE TABLE `qimall_addons_boss_achievement_team`  (
  `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',
  `goods_id` int(10) NOT NULL DEFAULT 0 COMMENT '购买过的商品id',
  `finish_order_money` decimal(10, 2) NULL DEFAULT 0.00 COMMENT '完成订单支付总金额，单位：元',
  `month` int(10) NOT NULL DEFAULT 0 COMMENT '月份，如：202207',
  `is_settlement` 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,
  `updated_at` int(11) NOT NULL DEFAULT 0,
  PRIMARY KEY (`id`) USING BTREE,
  INDEX `goods_id`(`goods_id`) USING BTREE,
  INDEX `user_id`(`user_id`) USING BTREE,
  INDEX `mall_id+month`(`mall_id`, `month`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '股东业绩团队记录明细' ROW_FORMAT = Dynamic;

CREATE TABLE `qimall_addons_boss_achievement_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',
  `level` tinyint(4) NOT NULL DEFAULT 0 COMMENT '业绩等级',
  `commission` decimal(10, 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) 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,
  INDEX `user_id`(`user_id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用户表' ROW_FORMAT = Dynamic;

