CREATE TABLE `qimall_addons_community_goods` (
     `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
     `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Mall ID',
     `goods_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Goods ID',
     `community_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Community 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`) USING BTREE,
     INDEX `idx_mall_goods_id` (`mall_id`, `goods_id`) USING BTREE,
     INDEX `idx_mall_community_id` (`mall_id`, `community_id`) USING BTREE
)COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_goods_mode_setting` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商城ID',
    `commission_type` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '分佣类型; score积分分佣, commission佣金分佣' COLLATE 'utf8mb4_general_ci',
    `enable` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否参与自提奖励[0:否, 1:是]',
    `is_alone` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '是否独立设置[0:否, 1:是]',
    `is_percent` TINYINT(1) NOT NULL DEFAULT '0' COMMENT '类型 0百分比 1 固定金额',
    `item_type` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '项目类型：商品goods' COLLATE 'utf8mb4_general_ci',
    `item_id` INT(11) NOT NULL DEFAULT '0' COMMENT '项目id',
    `give_num` DECIMAL(12,2) NOT NULL DEFAULT '0.00' COMMENT '赠送数额',
    `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
)COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_goods_setting` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Mall ID',
    `goods_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Goods ID',
    `enable` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否开启社区社区团购[0关闭,1开启]',
    `supported_logistics` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '支持物流方式' COLLATE 'utf8mb4_general_ci',
    `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '状态[0禁用 1启用 -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,
    INDEX `idx_mall_goods_id` (`mall_id`, `goods_id`) USING BTREE
)COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_head` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Mall ID',
    `user_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'User ID',
    `contacts` VARCHAR(30) NOT NULL DEFAULT '' COMMENT '联系人姓名' COLLATE 'utf8mb4_general_ci',
    `mobile` VARCHAR(15) NOT NULL DEFAULT '' COMMENT '联系人手机号' COLLATE 'utf8mb4_general_ci',
    `name` VARCHAR(60) NOT NULL DEFAULT '' COMMENT '名称' COLLATE 'utf8mb4_general_ci',
    `desc` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '简介' COLLATE 'utf8mb4_general_ci',
    `logo` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'logo' COLLATE 'utf8mb4_general_ci',
    `license_img` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '营业执照' COLLATE 'utf8mb4_general_ci',
    `idcard_img` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '身份证' COLLATE 'utf8mb4_general_ci',
    `province_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '省',
    `city_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '市',
    `district_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '区',
    `address` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '详细地址' COLLATE 'utf8mb4_general_ci',
    `longitude` VARCHAR(60) NOT NULL DEFAULT '' COMMENT '经度' COLLATE 'utf8mb4_general_ci',
    `latitude` VARCHAR(60) NOT NULL DEFAULT '' COMMENT '维度' COLLATE 'utf8mb4_general_ci',
    `check_status` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '审核状态：0：待审核；1：已通过；2：未通过',
    `check_remark` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '审核备注' COLLATE 'utf8mb4_general_ci',
    `status` TINYINT(4) NOT NULL DEFAULT '1' COMMENT '状态[0禁用 1启用 -1删除]',
    `created_at` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '创建时间',
    `updated_at` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '修改时间',
    `is_home_delivery` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否提供送货上门',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_mall_id` (`mall_id`) USING BTREE
)COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_head_apply` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `status` TINYINT(4) 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 '修改时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属商城',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `name` VARCHAR(10) NOT NULL DEFAULT '' COMMENT '自提点名称' COLLATE 'utf8mb4_general_ci',
    `intro` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '自提点简介' COLLATE 'utf8mb4_general_ci',
    `logo` VARCHAR(255) NOT NULL DEFAULT '' COMMENT 'logo' COLLATE 'utf8mb4_general_ci',
    `license_pic` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '营业执照' COLLATE 'utf8mb4_general_ci',
    `id_card_pic` VARCHAR(500) NOT NULL DEFAULT '' COMMENT '身份证照' COLLATE 'utf8mb4_general_ci',
    `contact_name` VARCHAR(10) NOT NULL DEFAULT '' COMMENT '联系人姓名' COLLATE 'utf8mb4_general_ci',
    `contact_phone` VARCHAR(11) NOT NULL DEFAULT '' COMMENT '手机号码' COLLATE 'utf8mb4_general_ci',
    `province_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '省份id',
    `city_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '城市ID',
    `district_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '地区id',
    `street` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '详细地址' COLLATE 'utf8mb4_general_ci',
    `lng` DECIMAL(10,7) NOT NULL DEFAULT '0.0000000' COMMENT '经度',
    `lat` DECIMAL(10,7) NOT NULL DEFAULT '0.0000000' COMMENT '纬度',
    `area` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '省市区' COLLATE 'utf8mb4_general_ci',
    `submit_count` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '提交次数',
    `check_count` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '审核次数',
    `apply_status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1待审核，50被拒绝，100审核通过',
    `step` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '当前步骤',
    `is_home_delivery` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '是否提供送货上门',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `mall_id` (`mall_id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE
)COMMENT='团长申请' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_head_check` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `status` TINYINT(4) 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 '修改时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属商城',
    `apply_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '申请ID',
    `admin_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '管理员ID',
    `remark` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '审核备注' COLLATE 'utf8mb4_general_ci',
    `check_status` TINYINT(3) UNSIGNED NOT NULL DEFAULT '0' COMMENT '审核后状态',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `mall_id` (`mall_id`) USING BTREE,
    INDEX `apply_id` (`apply_id`) USING BTREE
)COMMENT='审核日志' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_head_commission` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `status` TINYINT(4) 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 '修改时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属商城',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属用户',
    `head_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '自提点ID',
    `commission` BIGINT(20) UNSIGNED NOT NULL DEFAULT '0' COMMENT '提成金额',
    `order_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '订单ID',
    `intro` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '提成说明' COLLATE 'utf8mb4_general_ci',
    `buyer_user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '买家ID',
    `is_inflow` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '是否为流入',
    `reward_type` TINYINT(3) UNSIGNED NOT NULL DEFAULT '1' COMMENT '1佣金，2积分，3嗨呗，4嗨呗',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `mall_id` (`mall_id`) USING BTREE,
    INDEX `user_id` (`user_id`) USING BTREE,
    INDEX `head_id` (`head_id`) USING BTREE,
    INDEX `created_at` (`created_at`) USING BTREE
) COMMENT='团长分佣记录表' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_head_order` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `status` TINYINT(4) 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 '修改时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属商城',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '团长ID',
    `head_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '自提点ID',
    `order_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '订单ID',
    `buyer_user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '买家ID',
    `order_status` TINYINT(3) NOT NULL DEFAULT '0' COMMENT '同步主订单状态',
    `order_no` CHAR(30) NOT NULL DEFAULT '' COMMENT '订单编号' COLLATE 'utf8mb4_general_ci',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `buyer_user_id` (`buyer_user_id`) USING BTREE,
    INDEX `user_id` (`user_id`, `order_status`) USING BTREE,
    INDEX `mall_id` (`mall_id`, `order_id`) USING BTREE,
    INDEX `order_no` (`order_no`) USING BTREE
)COMMENT='团长订单' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_sign_log` (
    `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '主键',
    `status` TINYINT(4) 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 '修改时间',
    `mall_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '所属子系统',
    `user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '核销用户',
    `order_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '核销的订单',
    `head_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '自提点ID',
    `buyer_user_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT '买家ID',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `mall_id` (`mall_id`) USING BTREE
)COMMENT='核销记录' COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;

CREATE TABLE `qimall_addons_community_user` (
    `id` INT(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'ID',
    `mall_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '商城ID',
    `user_id` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT '用户ID',
    `community_id` INT(11) 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 '更新时间',
    `is_checked` TINYINT(4) NOT NULL DEFAULT '0' COMMENT '是否选中[0未选中 1选中]',
    PRIMARY KEY (`id`) USING BTREE,
    INDEX `idx_mall_user_id` (`mall_id`, `user_id`) USING BTREE
)COLLATE='utf8mb4_general_ci' ENGINE=InnoDB;


INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('Community', '社区团购', 'FromTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('community_pickup_prize', '社区团购', 'CapitalTypeMap', 1, 1654569888, 1654569888);
INSERT INTO `qimall_global_var_map` (`name`, `title`, `type`, `is_addons`, `created_at`, `updated_at`) VALUES ('Community', '社区团购', 'IncomeMap', 1, 1654569888, 1654569888);