CREATE TABLE `qimall_addons_reservation_service_goods` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `created_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间',
    `mall_id` INT(10) UNSIGNED NOT NULL COMMENT '商城ID',
    `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '状态0禁用，-1删除，1正常',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `goods_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '绑定的商品ID',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `goods_id` (`goods_id`) USING BTREE
)
    COMMENT='技师绑定的项目'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_goods_setting` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `created_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间',
    `mall_id` INT(10) UNSIGNED NOT NULL COMMENT '商城ID',
    `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '状态0禁用，-1删除，1正常',
    `item_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '绑定的商品ID',
    `item_type` VARCHAR(50) NOT NULL DEFAULT 'goods' COMMENT '类型、goods/order' COLLATE 'utf8mb4_general_ci',
    `commission_type` VARCHAR(50) NOT NULL DEFAULT '' COMMENT 'commission/score' COLLATE 'utf8mb4_general_ci',
    `is_enable` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否启用',
    `is_percent` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '是否为百分比',
    `commission` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '奖励金额',
    `is_enable_distribution` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否启用分销奖励',
    `distribution_config` JSON NULL DEFAULT NULL COMMENT '奖励配置',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `goods_id` (`item_id`) USING BTREE
)
    COMMENT='商品独立设置'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_level` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商城ID',
    `name` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '名称' COLLATE 'utf8mb4_general_ci',
    `level` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '等级',
    `item_commission` DECIMAL(8,2) NOT NULL DEFAULT '0.00' COMMENT '项目佣金',
    `item_commission_type` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '0百分比；1固定值',
    `enable_distribution_commission` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '享受分销提成奖励; 0关闭，1开启',
    `level1_commission` DECIMAL(8,2) NOT NULL DEFAULT '0.00' COMMENT '一级佣金',
    `level1_commission_type` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '0百分比；1固定值',
    `level2_commission` DECIMAL(8,2) NOT NULL DEFAULT '0.00' COMMENT '一级佣金',
    `level2_commission_type` 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 '更新时间',
    PRIMARY KEY (`id`) USING BTREE
)
    COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_notice` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Mall 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 '更新时间',
    `user_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `send_at` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '发送时间',
    `content` JSON NULL DEFAULT NULL COMMENT '发送内容',
    `res` JSON NULL DEFAULT NULL COMMENT '响应内容',
    `mobile` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '接收号码' COLLATE 'utf8mb4_general_ci',
    `area_code` VARCHAR(10) NOT NULL DEFAULT '' COMMENT '区号' COLLATE 'utf8mb4_general_ci',
    `gateway` VARCHAR(20) NOT NULL DEFAULT '' COMMENT '网关' COLLATE 'utf8mb4_general_ci',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `send_at` (`send_at`) USING BTREE
)
    COMMENT='短信通知'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;


CREATE TABLE `qimall_addons_reservation_service_order` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `created_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商城ID',
    `store_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '门店ID',
    `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '状态0禁用，-1删除，1正常',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `staff_user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '技师用户ID',
    `order_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '订单ID',
    `service_status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '服务状态',
    `order_no` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '订单编号' COLLATE 'utf8mb4_general_ci',
    `service_start_at` INT(11) NOT NULL DEFAULT '0' COMMENT '服务开始时间',
    `service_end_at` INT(11) NOT NULL DEFAULT '0' COMMENT '服务结束时间',
    `remark` TEXT NULL DEFAULT NULL COMMENT '备注信息' COLLATE 'utf8mb4_general_ci',
    `commission` DECIMAL(10,2) NOT NULL DEFAULT '0.00' COMMENT '佣金信息',
    `order_detail_id` INT(11) NOT NULL DEFAULT '0' COMMENT '订单详情ID',
    `goods_id` INT(11) NOT NULL DEFAULT '0' COMMENT '商品ID',
    `refund_at` INT(11) NOT NULL DEFAULT '0' COMMENT '退款时间',
    `is_refund` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否已经退款',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `staff_user_id` (`staff_user_id`) USING BTREE,
    INDEX `service_start_at` (`service_start_at`, `service_end_at`) USING BTREE,
    INDEX `refund_at` (`refund_at`) USING BTREE
)
    COMMENT='预约记录'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_user` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `mall_id` INT(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
    `user_id` INT(11) NOT NULL COMMENT '用户ID',
    `level` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '等级',
    `idcard` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '身份证' COLLATE 'utf8mb4_general_ci',
    `idcard_front` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '身份证正面' COLLATE 'utf8mb4_general_ci',
    `idcard_back` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '身份证反面' COLLATE 'utf8mb4_general_ci',
    `address` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '地址' COLLATE 'utf8mb4_general_ci',
    `longitude` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '经度' COLLATE 'utf8mb4_general_ci',
    `latitude` VARCHAR(64) NOT NULL DEFAULT '' COMMENT '纬度' COLLATE 'utf8mb4_general_ci',
    `name` VARCHAR(100) NOT NULL DEFAULT '' COMMENT '姓名' COLLATE 'utf8mb4_general_ci',
    `mobile` VARCHAR(16) NOT NULL DEFAULT '' COMMENT '手机号' COLLATE 'utf8mb4_general_ci',
    `qualification_certificate` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '资格证书' COLLATE 'utf8mb4_general_ci',
    `commission` DECIMAL(12,2) NOT NULL DEFAULT '0.00' COMMENT '佣金',
    `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '状态；1正常，0禁用，-1删除',
    `check_status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '审核状态：0：待审核；1：已通过；2：未通过',
    `check_remark` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '审核备注' COLLATE 'utf8mb4_general_ci',
    `created_at` INT(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(11) NOT NULL DEFAULT '0' COMMENT '更新时间',
    `store_id` INT(11) NOT NULL DEFAULT '0' COMMENT '门店ID',
    `store_status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '门店接单状态0不接单，1接单',
    `service_rating` DECIMAL(3,2) NOT NULL DEFAULT '5.00' COMMENT '服务评分',
    `store_lng` DECIMAL(10,7) NOT NULL DEFAULT '0.0000000' COMMENT '门店经度',
    `store_lat` DECIMAL(10,7) NOT NULL DEFAULT '0.0000000' COMMENT '门店纬度',
    `gender` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '性别，0保密，1男，2女',
    `age` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '年龄',
    `desc` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '个人简介' COLLATE 'utf8mb4_general_ci',
    `avatar` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '头像' COLLATE 'utf8mb4_general_ci',
    `is_working` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '是否接单中',
    `order_num` INT(11) NOT NULL DEFAULT '0' COMMENT '订单量',
    `store_order_num` INT(11) NOT NULL DEFAULT '0' COMMENT '门店订单量',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `store_id` (`store_id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE
)
    COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_user_book_time` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `mall_id` INT(11) NOT NULL DEFAULT '0' COMMENT '商城ID',
    `user_id` INT(11) NOT NULL COMMENT '用户ID',
    `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '状态；1正常，0禁用，-1删除',
    `start_time` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '预约开始时间戳',
    `end_time` INT(11) UNSIGNED NULL DEFAULT '0' COMMENT '预约结束时间戳',
    `order_id` INT(11) NULL DEFAULT '0' COMMENT '预约对应订单id',
    `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,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `order_id` (`order_id`) USING BTREE
)
    COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

CREATE TABLE `qimall_addons_reservation_service_work_time` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `created_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '更新时间',
    `mall_id` INT(10) UNSIGNED NOT NULL COMMENT '商城ID',
    `status` TINYINT(3) NOT NULL DEFAULT '1' COMMENT '状态0禁用，-1删除，1正常',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `week_day` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '工作日，0-周日，1-周一',
    `start_time` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT '开始时间，小时*100+分钟',
    `end_time` SMALLINT(6) NULL DEFAULT '0' COMMENT '结束时间，小时*100+分钟',
    `text` VARCHAR(50) NOT NULL DEFAULT '' COMMENT '显示' COLLATE 'utf8mb4_general_ci',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `week_day` (`week_day`) USING BTREE
)
    COMMENT='工作时间'
COLLATE='utf8mb4_general_ci'
ENGINE=InnoDB;

INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('ReservationService', '预约服务', 'FromTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('ReservationService', '预约服务', 'MarketingTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('ReservationService', '预约服务', 'IncomeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('reserve_commission', '项目佣金', 'CapitalTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('reserve_commission_first', '一级佣金', 'CapitalTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall`.`qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('reserve_commission_second', '二级佣金', 'CapitalTypeMap', 1, 1654569888, 165456988);

INSERT INTO `qimall_crontab_task` (`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('服务预约 - 每分钟检测一次短信发送', 'reservation-service/notice-task/send', 2, '0 */1 * * * *', 0, 1, 1673594361, 1673594361);
INSERT INTO `qimall_crontab_task` (`name`, `command`, `type`, `rule`, `is_warning`, `status`, `created_at`, `updated_at`) VALUES ('服务预约 - 每分钟检测一次预约是否过期', 'reservation-service/refund-task/refund', 2, '0 */1 * * * *', 0, 1, 1673594361, 1673594361);