DROP TABLE IF EXISTS `dms_seller_bank_account`;
CREATE TABLE IF NOT EXISTS `dms_seller_bank_account` (
  `id` int(10) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `account_name` varchar(100) DEFAULT NULL COMMENT '账户名',
  `bank_name` varchar(100) DEFAULT NULL COMMENT '银行名称',
  `bank_card_num` varchar(50) DEFAULT NULL COMMENT '银行卡号',
  `open_bank_address` varchar(100) DEFAULT NULL COMMENT '开户行地址',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COMMENT='商家银行账户表';


DROP TABLE IF EXISTS `dms_offline_payment_record`;
CREATE TABLE IF NOT EXISTS `dms_offline_payment_record` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `seller_bank_account_id` int(10) DEFAULT NULL COMMENT '商家银行账户id',
  `member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
  `order_id` bigint(20) DEFAULT NULL COMMENT '订单id',
  `order_sn` varchar(64) DEFAULT NULL COMMENT '订单编号',
  `pay_amount` decimal(10,2) DEFAULT NULL COMMENT '支付金额',
  `payment_account_name` varchar(100) DEFAULT NULL COMMENT '支付账户名',
  `payment_bank_name` varchar(100) DEFAULT NULL COMMENT '支付银行名称',
  `payment_bank_card_num` varchar(50) DEFAULT NULL COMMENT '支付银行卡号',
  `confirm_status` int(1) DEFAULT NULL COMMENT '确认状态：0->未确认；1->已确认',
  `confirm_time` datetime DEFAULT NULL COMMENT '确认时间',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `idx_order_id` (`order_id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COMMENT='线下支付记录表';

DROP TABLE IF EXISTS `dms_member_bank_account`;
CREATE TABLE IF NOT EXISTS `dms_member_bank_account` (
  `id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
  `account_name` varchar(100) DEFAULT NULL COMMENT '账户名',
  `bank_name` varchar(100) DEFAULT NULL COMMENT '银行名称',
  `bank_card_num` varchar(50) DEFAULT NULL COMMENT '银行卡号',
  `open_bank_address` varchar(100) DEFAULT NULL COMMENT '开户行地址',
  `default_status` int(1) DEFAULT NULL COMMENT '是否默认：0->否；1->是',
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员银行账户表';

DROP TABLE IF EXISTS `dms_member_withdraw_apply`;
CREATE TABLE IF NOT EXISTS `dms_member_withdraw_apply` (
  `id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
  `value` decimal(10,2) DEFAULT NULL COMMENT '值',
  `poundage` decimal(10,2) DEFAULT NULL COMMENT '手续费',
  `actual_value` decimal(10,2) DEFAULT NULL COMMENT '扣出手续费后的值',
  `account_name` varchar(100) DEFAULT NULL COMMENT '账户名',
  `bank_name` varchar(100) DEFAULT NULL COMMENT '银行名称',
  `bank_card_num` varchar(50) DEFAULT NULL COMMENT '银行卡号',
  `open_bank_address` varchar(100) DEFAULT NULL COMMENT '开户行地址',
  `payment_status` int(1) DEFAULT NULL COMMENT '付款状态：0->未打款；1->已打款；2->打款失败',
  `failed_reason` varchar(255) DEFAULT NULL COMMENT '失败原因',
  `payment_time` datetime DEFAULT NULL COMMENT '付款时间',
  `create_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COMMENT='会员提现申请表';

DROP TABLE IF EXISTS `dms_team_level`;
CREATE TABLE IF NOT EXISTS `dms_team_level` (
  `id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键id',
  `member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
  `parent_id` bigint(20) DEFAULT NULL COMMENT '推荐人id',
  `level_tree` varchar(1000) DEFAULT NULL COMMENT '层级树',
  `level` int(10) DEFAULT NULL COMMENT '当前层级',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=18 DEFAULT CHARSET=utf8 COMMENT='团队层级关系表';


DROP TABLE IF EXISTS `dms_distribution_dictionary`;
CREATE TABLE `dms_distribution_dictionary` (
	`id` INT(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`name` VARCHAR(50) NULL DEFAULT NULL COMMENT '名称',
	`value` VARCHAR(50) NULL DEFAULT NULL COMMENT '参数值',
	`comment` VARCHAR(50) NULL DEFAULT NULL COMMENT '备注',
	`show_status` int(1) NULL DEFAULT '1' COMMENT '显示状态（ 0: 不显示  1: 显示）',
	`update_time` TIMESTAMP NULL DEFAULT NULL COMMENT '更新时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='分销字典表';

DROP TABLE IF EXISTS `dms_member_total_income`;
CREATE TABLE `dms_member_total_income` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`item_type` int(3) NULL DEFAULT NULL COMMENT '项目类型',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员总收入表';

DROP TABLE IF EXISTS `dms_team_total_income`;
CREATE TABLE `dms_team_total_income` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='团队总收入表';

DROP TABLE IF EXISTS `dms_team_total_consume`;
CREATE TABLE `dms_team_total_consume` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='团队累计消费表';

DROP TABLE IF EXISTS `dms_team_member_number`;
CREATE TABLE `dms_team_member_number` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`total` int(10) DEFAULT '0' COMMENT '团队成员总数',
	`consumer` int(10) DEFAULT '0' COMMENT '消费者人数',
	`partner` int(10) DEFAULT '0' COMMENT '经销商人数',
	`one_diamond` int(10) DEFAULT '0' COMMENT '初级合作商人数',
	`two_diamond` int(10) DEFAULT '0' COMMENT '中级合作商人数',
	`three_diamond` int(10) DEFAULT '0' COMMENT '高级合作商人数',
	`four_diamond` int(10) DEFAULT '0' COMMENT '特级合作商人数',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='团队成员数量表';

DROP TABLE IF EXISTS `dms_member_trade_record`;
CREATE TABLE `dms_member_trade_record` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`item_type` int(3) NULL DEFAULT NULL COMMENT '项目类型',
	`type` int(1) NULL DEFAULT NULL COMMENT '收支类型：0->收入；1->支出',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	`title` VARCHAR(100) NULL DEFAULT NULL COMMENT '交易标题',
	`note` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注',
	`customer_id` bigint(20) DEFAULT NULL COMMENT '消费者Id',
	`order_id` bigint(20) DEFAULT NULL COMMENT '订单id',
	`create_time` datetime DEFAULT NULL COMMENT '创建时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员账户交易记录表';

DROP TABLE IF EXISTS `dms_member_freeze_account_record`;
CREATE TABLE `dms_member_freeze_account_record` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`item_type` int(3) NULL DEFAULT NULL COMMENT '项目类型',
	`type` int(1) NULL DEFAULT NULL COMMENT '收支类型：0->收入；1->支出',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	`title` VARCHAR(100) NULL DEFAULT NULL COMMENT '交易标题',
	`note` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注',
	`customer_id` bigint(20) DEFAULT NULL COMMENT '消费者Id',
	`order_id` bigint(20) DEFAULT NULL COMMENT '订单id',
	`create_time` datetime DEFAULT NULL COMMENT '创建时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员冻结账户记录表';

DROP TABLE IF EXISTS `dms_platform_income`;
CREATE TABLE `dms_platform_income` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`order_id` bigint(20) DEFAULT NULL COMMENT '订单id',
	`customer_id` bigint(20) DEFAULT NULL COMMENT '消费者Id',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	`note` VARCHAR(255) NULL DEFAULT NULL COMMENT '备注',
	`create_time` datetime DEFAULT NULL COMMENT '创建时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='平台收入表';

DROP TABLE IF EXISTS `dms_member_transfer_record`;
CREATE TABLE `dms_member_transfer_record` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '转账会员id',
	`member_nickname` VARCHAR(255) DEFAULT NULL COMMENT '转账会员昵称',
	`receiver_id` bigint(20) DEFAULT NULL COMMENT '接收会员Id',
	`receiver_nickname` VARCHAR(255) DEFAULT NULL COMMENT '接收会员昵称',
	`receiver_phone` VARCHAR(64) DEFAULT NULL COMMENT '接收会员手机号',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	`note` VARCHAR(255) DEFAULT NULL COMMENT '备注',
	`create_time` datetime DEFAULT NULL COMMENT '创建时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员转账记录表';

DROP TABLE IF EXISTS `dms_member_month_reward_record`;
CREATE TABLE `dms_member_month_reward_record` (
	`id` bigint(10) NOT NULL AUTO_INCREMENT COMMENT '主键Id',
	`member_id` bigint(20) DEFAULT NULL COMMENT '会员id',
	`value` decimal(10,2) DEFAULT NULL COMMENT '值',
	`year` int(4) NULL DEFAULT NULL COMMENT '年份',
	`month` int(2) NULL DEFAULT NULL COMMENT '月份',
	`create_time` datetime DEFAULT NULL COMMENT '创建时间',
	PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='会员月度奖励发放记录表';


alter table `ums_member` add column `member_level` int(1) null COMMENT '分销会员等级（0->普通用户；1->vip会员；2->店长；3->代理；4->市代；5->中级合作商；6->高级合作商；7->特级合作商））' default '0' AFTER `member_level_id`;
alter table `ums_member` add column `store_status` int(1) null COMMENT '分销实体店状态（0->未开店；1->已开店）' default '0';
alter table `ums_member` add column `balance` decimal(10,2) null COMMENT '余额' default '0.00';
alter table `ums_member` add column `freeze` decimal(10,2) null COMMENT '冻结余额' default '0.00';
alter table `ums_member` add column `order_status` int(1) null COMMENT '排队状态:0->未排队；1->排队中' default '0';

alter table `oms_order` add column settlement_status int(1) null COMMENT '分销结算状态（0->未结算；1->已结算；2->不结算）' default '0';
alter table `oms_order` add column settlement_time datetime null COMMENT '分销结算时间';

alter table `dms_member_withdraw_apply` add column `withdraw_type` int(1) null COMMENT '提现方式(0: 支付宝; 1: 微信; 2: 银行卡)' default null AFTER `open_bank_address`;
alter table `dms_member_withdraw_apply` add column `real_name` varchar(100) null COMMENT '真实姓名' default null AFTER `open_bank_address`;
alter table `dms_member_withdraw_apply` add column `alipay_account` varchar(100) null COMMENT '支付宝账号' default null AFTER `real_name`;
alter table `dms_member_withdraw_apply` add column `wechat_account` varchar(100) null COMMENT '微信账号' default null AFTER `alipay_account`;
alter table `dms_member_withdraw_apply` add column `wechat_nickname` varchar(100) null COMMENT '微信昵称' default null AFTER `wechat_account`;

alter table `ums_member` add column `detail_address` varchar(1000) null COMMENT '详细地址' default null;
alter table `ums_member` add column `real_name` varchar(100) null COMMENT '真实姓名' default null;

alter table `pms_product` add column `distribution_flag` int(1) null COMMENT '分销标志（0->不参与；1->参与）' default 1;

