CREATE TABLE `housing_estate` (
	`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	`housing_estate_id` VARCHAR(32) NULL DEFAULT '' COMMENT '小区id',
	`merchant_no` VARCHAR(32) NULL DEFAULT '' COMMENT '所属商户',
	`label` VARCHAR(16) NULL DEFAULT '' COMMENT '地址标签',
	`province_id` INT(10) NULL DEFAULT '0' COMMENT '省id',
	`city_id` INT(10) NULL DEFAULT '0' COMMENT '城市id',
	`district_id` INT(10) NULL DEFAULT '0' COMMENT '区id',
	`town_id` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '街道id',
	`lat` DECIMAL(10,6) NULL DEFAULT '0.000000' COMMENT '纬度',
	`lng` DECIMAL(10,6) NULL DEFAULT '0.000000' COMMENT '经度',
	`detail` VARCHAR(255) NULL DEFAULT '' COMMENT '地址明细',
	`partner_id` VARCHAR(32) NOT NULL DEFAULT '' COMMENT '小区合伙人',
	`regional_agent_id` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '区域总代理id',
	`created_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '创建时间',
	`created_by` VARCHAR(20) NULL DEFAULT '' COMMENT '创建者',
	`updated_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '更新时间',
	`updated_by` VARCHAR(20) NULL DEFAULT '' COMMENT '更新者',
	`status` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态',
	`del_flag` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除标识',
	`remark` VARCHAR(255) NULL DEFAULT NULL,
	`amap_lng` DECIMAL(10,6) NULL DEFAULT '0.000000' COMMENT '高德经度',
	`amap_lat` DECIMAL(10,6) NULL DEFAULT '0.000000' COMMENT '高德纬度',
	PRIMARY KEY (`id`)
)
COMMENT='小区信息维护表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=COMPACT
AUTO_INCREMENT=0
;

CREATE TABLE `partner` (
	`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	`user_id` VARCHAR(32) NULL DEFAULT '' COMMENT '用户id',
	`nick_name` VARCHAR(255) NULL DEFAULT '' COMMENT '昵称',
	`age` INT(5) NULL DEFAULT '0' COMMENT '年龄',
	`mobile` VARCHAR(16) NULL DEFAULT '' COMMENT '手机号',
	`full_address` VARCHAR(128) NULL DEFAULT '' COMMENT '完整住址',
	`merchant_no` VARCHAR(32) NULL DEFAULT '' COMMENT '所属商户',
	`province_id` INT(10) NULL DEFAULT '0' COMMENT '省id',
	`city_id` INT(10) NULL DEFAULT '0' COMMENT '城市id',
	`district_id` INT(10) NULL DEFAULT '0' COMMENT '区id',
	`town_id` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '街道id',
	`detail` VARCHAR(255) NULL DEFAULT '' COMMENT '地址明细',
	`regional_agent_id` VARCHAR(255) NOT NULL DEFAULT '' COMMENT '区域总代理id',
	`created_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '创建时间',
	`created_by` VARCHAR(20) NULL DEFAULT '' COMMENT '创建者',
	`updated_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '更新时间',
	`updated_by` VARCHAR(20) NULL DEFAULT '' COMMENT '更新者',
	`status` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态',
	`del_flag` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除标识',
	`remark` VARCHAR(255) NULL DEFAULT NULL,
	`accumulative_total` BIGINT(20) NULL DEFAULT '0' COMMENT '累计收益',

	PRIMARY KEY (`id`)
)
COMMENT='小区合伙人信息表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=COMPACT
AUTO_INCREMENT=0
;

CREATE TABLE `regional_agent` (
	`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
	`user_id` VARCHAR(32) NULL DEFAULT '' COMMENT '用户id',
	`nick_name` VARCHAR(255) NULL DEFAULT '' COMMENT '昵称',
	`age` INT(5) NULL DEFAULT '0' COMMENT '年龄',
	`mobile` VARCHAR(16) NULL DEFAULT '' COMMENT '手机号',
	`full_address` VARCHAR(128) NULL DEFAULT '' COMMENT '完整住址',
	`merchant_no` VARCHAR(32) NULL DEFAULT '' COMMENT '所属商户',
	`province_id` INT(10) NULL DEFAULT '0' COMMENT '省id',
	`city_id` INT(10) NULL DEFAULT '0' COMMENT '城市id',
	`district_id` INT(10) NULL DEFAULT '0' COMMENT '区id',
	`town_id` INT(10) UNSIGNED NULL DEFAULT '0' COMMENT '街道id',
	`detail` VARCHAR(255) NULL DEFAULT '' COMMENT '地址明细',
	`created_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '创建时间',
	`created_by` VARCHAR(20) NULL DEFAULT '' COMMENT '创建者',
	`updated_at` BIGINT(20) UNSIGNED NULL DEFAULT '0' COMMENT '更新时间',
	`updated_by` VARCHAR(20) NULL DEFAULT '' COMMENT '更新者',
	`status` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '状态',
	`del_flag` TINYINT(4) UNSIGNED NOT NULL DEFAULT '0' COMMENT '删除标识',
	`remark` VARCHAR(255) NULL DEFAULT NULL,
	`division_proportion` INT(11) NULL DEFAULT '0' COMMENT '通用分成比例 万分比',
	`accumulative_total` BIGINT(20) NULL DEFAULT '0' COMMENT '累计收益',

	PRIMARY KEY (`id`)
)
COMMENT='区域总代理信息表'
COLLATE='utf8_general_ci'
ENGINE=InnoDB
ROW_FORMAT=COMPACT
AUTO_INCREMENT=0
;

-- 订单表增加小区标识
ALTER TABLE `vorder`
	ADD COLUMN `housing_estate_id` VARCHAR(32) NULL DEFAULT '' COMMENT '小区id' AFTER `salesman_id`;
ALTER TABLE `vorder`
	ADD INDEX `housing_estate_id` (`housing_estate_id`);
	
-- 客户注册增加小区标识
ALTER TABLE `consumer_info`
	ADD COLUMN `housing_estate_id` VARCHAR(32) NULL DEFAULT '' COMMENT '小区id' AFTER `salesman_id`;
ALTER TABLE `consumer_info`
	ADD INDEX `housing_estate_id` (`housing_estate_id`);	
