CREATE TABLE IF NOT EXISTS `YB_TABLE_PREFIX_sys_admin_user` (
    `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '自增id',
    `admin_id` int(11) NOT NULL DEFAULT 0 COMMENT '员工id',
    `user_id` int(11) NOT NULL DEFAULT 0 COMMENT '用户id',
    `mch_id` int(11) NOT NULL COMMENT '关联的主应用id',
    `shop_id` int(11) NOT NULL DEFAULT 0 COMMENT '店铺ID',
    `create_time` int(11) DEFAULT '0' COMMENT '创建时间',
    `update_time` int(11) DEFAULT '0' COMMENT '更新时间',
    `delete_time` int(11) DEFAULT '0' COMMENT '删除时间',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='员工客户绑定表';

CREATE TABLE IF NOT EXISTS `YB_TABLE_PREFIX_sys_department` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
    `name` VARCHAR(100) NOT NULL COMMENT '部门名称',
    `pid` INT(11) NOT NULL DEFAULT 0 COMMENT '上级ID',
    `level` INT(11) NOT NULL DEFAULT 1 COMMENT '级别',
    `sort` INT(11) NOT NULL DEFAULT 0 COMMENT '排序',
    `status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否启用：0-否，1-是',
    `mch_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '应用ID',
    `shop_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '店铺ID',
    `create_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建时间',
    `update_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '更新时间',
    `delete_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '删除时间',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='商家员工部门表';

CREATE TABLE IF NOT EXISTS `YB_TABLE_PREFIX_sys_department_admin_relate` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
    `admin_id` INT(11) NOT NULL COMMENT '员工ID',
    `department_id` INT(11) NOT NULL COMMENT '部门ID',
    `sort` INT(11) NOT NULL DEFAULT 0 COMMENT '部门内排序值，数值越大排序越前面',
    `mch_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '应用ID',
    `shop_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '店铺ID',
    `create_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建时间',
    `update_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '更新时间',
    `delete_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '删除时间',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='员工-部门关联表';

CREATE TABLE IF NOT EXISTS `YB_TABLE_PREFIX_sys_department_leader` (
    `id` INT(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
    `department_id` INT(11) NOT NULL COMMENT '部门ID',
    `leader_id` INT(11) NOT NULL COMMENT '负责人ID',
    `leader_type` TINYINT(2) NOT NULL DEFAULT 1 COMMENT '负责人类型：1-主负责人，2-副负责人',
    `status` TINYINT(1) NOT NULL DEFAULT 1 COMMENT '是否启用：0-否，1-是',
    `mch_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '应用ID',
    `shop_id` BIGINT UNSIGNED NOT NULL DEFAULT 0 COMMENT '店铺ID',
    `create_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '创建时间',
    `update_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '更新时间',
    `delete_time` INT UNSIGNED NOT NULL DEFAULT 0 COMMENT '删除时间',
    PRIMARY KEY (`id`)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='部门负责人关联表';