CREATE TABLE `sys_rpay_merchant_apply` (
  `merchant_app_id` varchar(50) NOT NULL,
  `client_id` int(11) NOT NULL,
  `merchant_shortname` varchar(20) NOT NULL,
  `business_category` varchar(20) NOT NULL,
  `sub_merchant_id` varchar(20) DEFAULT NULL,
  `create_time` datetime NOT NULL,
  `operator` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`merchant_app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 AVG_ROW_LENGTH=244;

ALTER TABLE `pmt_refunds`
  MODIFY COLUMN `refund_id`  varchar(50) NOT NULL COMMENT '退款编号' FIRST ;

ALTER TABLE `pmt_refund_applies`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST ,
  MODIFY COLUMN `refund_id`  varchar(50) NOT NULL COMMENT 'refund order id' AFTER `order_id`;

ALTER TABLE `pmt_transactions`
  MODIFY COLUMN `transaction_id`  varchar(50) NOT NULL COMMENT '交易流水编号' FIRST ,
  MODIFY COLUMN `refund_id`  varchar(50) NULL DEFAULT NULL COMMENT '退款单号' AFTER `order_id`;

ALTER TABLE `log_wechat_template_msg`
  MODIFY COLUMN `send_id`  varchar(50) NOT NULL FIRST ,
  MODIFY COLUMN `account_id`  varchar(50) NOT NULL AFTER `client_id`;


ALTER TABLE `log_wechat_error`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `log_notify_error`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `log_manager_login`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `log_client_login`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST ,
  MODIFY COLUMN `account_id`  varchar(50) NOT NULL AFTER `client_id`;

ALTER TABLE `log_client_review`
  MODIFY COLUMN `review_id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `log_app_msg`
  MODIFY COLUMN `send_id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `sys_accounts`
  MODIFY COLUMN `account_id`  varchar(50) NOT NULL COMMENT '登录账户编号' FIRST ;

ALTER TABLE `sys_clients_devices`
  MODIFY COLUMN `account_id`  varchar(50) NULL DEFAULT NULL COMMENT '目前登录的账号' AFTER `version`;

ALTER TABLE `financial_bd_config`
  MODIFY COLUMN `manager_id`  varchar(50) NOT NULL FIRST ;

ALTER TABLE `sys_client_bd`
  MODIFY COLUMN `bd_id`  varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL AFTER `client_id`;

ALTER TABLE `sys_client_bd`
  MODIFY COLUMN `create_id`  varchar(50) DEFAULT NULL FIRST ;

ALTER TABLE `sys_managers`
  MODIFY COLUMN `manager_id`  varchar(50) NOT NULL COMMENT '管理员账户编号' FIRST ;

ALTER TABLE `sys_client_rates`
  MODIFY COLUMN `manager_id`  varchar(50) DEFAULT NULL FIRST ;

ALTER TABLE `log_manager_login`
  MODIFY COLUMN `manager_id`  varchar(50) NOT NULL AFTER `id`;

ALTER TABLE `financial_bd_commission_config`
  MODIFY COLUMN `bd_id`  varchar(50) NOT NULL DEFAULT 0 COMMENT 'bd id';

ALTER TABLE `financial_bd_config`
  MODIFY COLUMN `bd_group`  varchar(50) NULL DEFAULT NULL COMMENT 'BD Leader manger_id' AFTER `get_prize`;

ALTER TABLE `financial_bd_prize_detail`
  MODIFY COLUMN `manager_id`  varchar(50) NOT NULL AFTER `client_id`;

ALTER TABLE `bd_access_log`
  MODIFY COLUMN `bd_id`  varchar(50) NOT NULL AFTER `date`;

ALTER TABLE `sys_clients`
  MODIFY COLUMN `creator`  varchar(50) NOT NULL COMMENT '创建者' AFTER `logo_thumbnail`,
  MODIFY COLUMN `bd_user`  varchar(300) DEFAULT NULL COMMENT '所属BD用户' AFTER `logo_thumbnail`,
  MODIFY COLUMN `approver`  varchar(50) DEFAULT NULL AFTER `logo_thumbnail`;


ALTER TABLE `pat_goods`
  MODIFY COLUMN `creator`  varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL AFTER `is_using`;

ALTER TABLE `sys_notice`
  MODIFY COLUMN `create_id`  varchar(50) NOT NULL AFTER `status`,
  MODIFY COLUMN `send_id`  varchar(50) NULL DEFAULT NULL AFTER `create_name`;

ALTER TABLE `sys_notice_client`
  MODIFY COLUMN `read_id`  varchar(50) NULL DEFAULT NULL AFTER `read_time`;

ALTER TABLE `act_sign_events_sign_log`
  MODIFY COLUMN `sign_user_id`  varchar(50) NULL DEFAULT NULL AFTER `sign_time`;

ALTER TABLE `act_red_packets_wechat`
  MODIFY COLUMN `relation_id`  varchar(50) NOT NULL FIRST ,
  MODIFY COLUMN `update_id`  varchar(50) NULL DEFAULT NULL AFTER `create_time`;


ALTER TABLE `pat_goods`
  MODIFY COLUMN `id`  varchar(50) NOT NULL FIRST;

ALTER TABLE `pat_goods_sale`
  MODIFY COLUMN `good_id`  varchar(50) NOT NULL AFTER `client_id`;

ALTER TABLE `commodities`
  MODIFY COLUMN `create_id`  varchar(50) DEFAULT NULL;

ALTER TABLE `sys_accounts`
  MODIFY COLUMN `creator`  varchar(50) NOT NULL COMMENT '开户者';

ALTER TABLE `sys_clients_audit_process`
  MODIFY COLUMN `operator_id`  tinyint(1) NOT NULL ;

ALTER TABLE `pmt_refunds`
  MODIFY COLUMN `operator_id`  varchar(50)  DEFAULT NULL COMMENT '退款操作者账号';

ALTER TABLE `sys_clients_apply`
  MODIFY COLUMN `short_name`  varchar(100)   DEFAULT NULL COMMENT '公司简称';

ALTER TABLE `cashback_draw_deposits`
  MODIFY COLUMN `operator_id`  varchar(50) NOT NULL ;

  ALTER TABLE `sys_clients`
  ADD COLUMN `local_merchant` tinyint(1) DEFAULT 0;

--用户画像

ALTER TABLE sys_clients_customers ADD COLUMN headimg VARCHAR(200) DEFAULT NULL COMMENT '头像地址';

ALTER TABLE sys_clients_customers ADD COLUMN nick_name VARCHAR(80) DEFAULT NULL COMMENT '昵称';

ALTER TABLE sys_clients_customers ADD COLUMN tag VARCHAR(100) DEFAULT NULL COMMENT '标签';

ALTER TABLE sys_clients_customers ADD COLUMN payment_times INT DEFAULT 1 COMMENT '消费次数';

ALTER TABLE sys_clients_customers ADD COLUMN total_amount decimal(10 , 2) DEFAULT NULL COMMENT '消费总金额';

ALTER TABLE sys_clients_customers ADD COLUMN update_time datetime default NULL COMMENT '创建时间';

ALTER TABLE sys_clients_customers ADD COLUMN channel varchar(15) not NULL ;

ALTER TABLE sys_clients_customers ADD COLUMN last_payment_time datetime DEFAULT NULL COMMENT '最后一次付款时间';

ALTER TABLE sys_org ADD COLUMN parent_org_id int(11) DEFAULT NULL;
ALTER TABLE sys_org ADD COLUMN min_wechat_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低微信费率';
ALTER TABLE sys_org ADD COLUMN min_alipay_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低支付宝费率';
ALTER TABLE sys_org ADD COLUMN min_alipayonline_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低支付宝线上费率';
ALTER TABLE sys_org ADD COLUMN min_bestpay_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低翼支付费率';
ALTER TABLE sys_org ADD COLUMN min_jd_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低京东费率';
ALTER TABLE sys_org ADD COLUMN commission_type SMALLINT(1) DEFAULT '1' COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';


--agent_commission

CREATE TABLE `financial_agent_commission` (
  `record_id` varchar(50) NOT NULL,
  `org_id` int(11) NOT NULL,
  `year` smallint(6) NOT NULL,
  `month` smallint(6) NOT NULL,
  `create_time` datetime NOT NULL,
  `org_rate` decimal(5,2) DEFAULT NULL COMMENT '保底费率（RoyalPay抽取）',
  `gross_amount` decimal(12,2) NOT NULL COMMENT '支付-退款',
  `total_charge` decimal(12,2) NOT NULL COMMENT '总手续费',
  `org_charge` decimal(12,2) NOT NULL COMMENT '合伙人手续',
  `channel` varchar(12) NOT NULL,
  `org_net_charge` decimal(12,2) DEFAULT NULL COMMENT '净值',
  PRIMARY KEY (`record_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='二级代理商提成';

CREATE TABLE `financial_agent_commission_detail` (
  `detail_id` varchar(50) NOT NULL,
  `year` smallint(6) NOT NULL,
  `month` smallint(6) NOT NULL,
  `record_id` varchar(50) NOT NULL,
  `client_id` int(11) NOT NULL,
  `client_rate` decimal(5,2) NOT NULL,
  `date_from` date NOT NULL,
  `date_to` date NOT NULL,
  `gross_amount` decimal(12,2) NOT NULL COMMENT '总支付-总退款',
  `total_charge` decimal(12,2) NOT NULL COMMENT '总手续费',
  `org_charge` decimal(12,2) NOT NULL COMMENT '合伙人所得手续费',
  `channel` varchar(15) NOT NULL,
  `org_net_charge` decimal(12,2) DEFAULT NULL COMMENT '净值',
  PRIMARY KEY (`detail_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 ROW_FORMAT=DYNAMIC;


alter table financial_partner_commission add column commission_type smallint(1) DEFAULT 1 COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';
alter table financial_partner_commission_detail add column commission_type smallint(1) DEFAULT 1 COMMENT '提成类型 1:渠道计算法 2:总交易额比例 3:收益比例';



INSERT INTO `royalpay_production`.`sys_configs`(`config_key` , `config_value`)


VALUES
	(
		'android_version_content' ,
		'近期更新：\n\n1、修复了付款二维码的保存可能会失败的错误\n2、新增多种渠道订单及清算\n3、修复清算记录显示错误'
	);

INSERT INTO `royalpay_production`.`sys_configs`(`config_key` , `config_value`)
VALUES
	(
		'android_version' ,
		'2.8.1'
	);

INSERT INTO `royalpay_production`.`sys_configs`(`config_key` , `config_value`)
VALUES
	(
		'android_update' ,
		'true'
	);



CREATE TABLE `sys_wx_merchant_apply` (
  `merchant_app_id` varchar(50) NOT NULL,
  `client_id` int(11) NOT NULL,
  `merchant_name` varchar(50) NOT NULL,
  `merchant_shortname` varchar(20) NOT NULL,
  `office_phone` varchar(20) NOT NULL,
  `contact_name` varchar(50) DEFAULT NULL,
  `contact_phone` varchar(20) DEFAULT NULL,
  `contact_email` varchar(50) DEFAULT NULL,
  `business_category` varchar(20) NOT NULL,
  `merchant_remark` varchar(20) NOT NULL,
  `website` varchar(100) DEFAULT NULL,
  `merchant_introduction` varchar(256) DEFAULT NULL,
  `merchant_id` varchar(20) NOT NULL,
  `sub_merchant_id` varchar(20) DEFAULT NULL,
  `create_time` datetime NOT NULL,
  `operator` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`merchant_app_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

alter table statistics_customer_order add column refund_orders int(10) DEFAULT NULL COMMENT '' AFTER `orders`;
alter table statistics_customer_order add column refund_amount DECIMAL(20,2) DEFAULT NULL COMMENT '' AFTER `total`;

ALTER TABLE `financial_bd_prize_log`
  MODIFY COLUMN `manager_id`  varchar(50) NOT NULL COMMENT 'bd user id' AFTER `record_id`;

CREATE TABLE act_mon_delay_settle
(
    id VARCHAR(50) PRIMARY KEY NOT NULL,
    client_id INT(11) NOT NULL,
    account_id VARCHAR(50) NOT NULL,
    account_name VARCHAR(100) COMMENT '商户账户名称',
    create_time DATETIME NOT NULL COMMENT '参与开始时间(若在周一，下周生效)',
    expire_time DATETIME COMMENT '结束时间',
    is_valid TINYINT DEFAULT 1,
    rate DECIMAL(4,2) COMMENT '年化收益率'
);

CREATE TABLE act_mon_delay_settle_redpack
(
  id VARCHAR(50) PRIMARY KEY NOT NULL,
  client_id INT(11) NOT NULL,
  settle_amount DECIMAL(10,2) NOT NULL,
  rate DECIMAL(4,2) COMMENT '收益率',
  redpack_amount DECIMAL(10,2) COMMENT '奖励金额',
  create_time DATETIME NOT NULL,
  send_time DATETIME COMMENT '奖励发放时间'
);

CREATE TABLE `act_app_list` (
  `act_id` varchar(50) NOT NULL,
  `act_name` varchar(100) NOT NULL COMMENT '活动名称',
  `act_url` varchar(400) DEFAULT NULL COMMENT '活动链接',
  `is_valid` tinyint(1) NOT NULL DEFAULT 0,
  `params_json` text DEFAULT NULL COMMENT '活动参数',
  `create_time` datetime DEFAULT NULL,
  `desc` varchar(400) DEFAULT NULL COMMENT '活动简介',
  `act_content` text DEFAULT NULL COMMENT 'html',
  `show_type` smallint(6) DEFAULT 0 COMMENT '0:url;1:content',
  `is_show_window` tinyint(4) DEFAULT 0 COMMENT 'app是否弹框',
  `act_img` varchar(200) DEFAULT NULL COMMENT '广告位图片',
  `window_img` varchar(200) DEFAULT NULL COMMENT 'app弹框图片',
  `update_time` datetime DEFAULT NULL,
  `active_date` date NOT NULL COMMENT '生效日期',
  `expire_date` date DEFAULT NULL COMMENT '活动结束日期',
  PRIMARY KEY (`act_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='app活动'


ALTER TABLE sys_notice ADD merchants_type TINYINT(1) DEFAULT 0 NOT NULL COMMENT '商户范围0：全部商户 1：自定义商户';
ALTER TABLE sys_notice ADD is_app_window TINYINT(1) DEFAULT 0 COMMENT '是否需要APP弹框';


ALTER TABLE sys_notice MODIFY end_time DATE NOT NULL COMMENT '截止日期';
ALTER TABLE sys_notice ADD `desc` VARCHAR(1000) NULL COMMENT '简介';






ALTER TABLE sys_files DROP INDEX UK_sys_files;

create table sys_clients_contract(
id varchar(50) not null,
client_id int(11) not null,
create_time datetime not null,
expiry_date date not null,
has_sign TINYINT(1) DEFAULT 0 not null,
sign_channel varchar(10) not null ,
sign_account_id varchar(50) DEFAULT null,
signatory varchar(20) DEFAULT null,
PRIMARY key (`id`)
);


alter table sys_clients_devices add column is_offline  tinyint(1) NOT NULL DEFAULT '0';

ALTER TABLE `sys_customer_relation`
ADD COLUMN `globalpay_openid`  varchar(100) NULL AFTER `kanga_openid`;


ALTER TABLE act_app_list ADD banner_img VARCHAR(200) NULL COMMENT 'App首页banner图片';


alter table act_app_list add column  `msg_start_date` date DEFAULT NULL;
alter table act_app_list add column  `msg_end_date` date DEFAULT NULL;
alter table act_app_list add column  `msg_interval` smallint(3) DEFAULT NULL;

alter table sys_clients add column `manual_settle` tinyint(1) DEFAULT 0;


create table log_clients_operation(
id varchar(50) not null,
client_id int(11) not null,
operator_id varchar(50) not null comment '操作人者 账户ID',
operator_type SMALLINT (2) not null comment '操作人者类型',
create_time datetime not null,
operation varchar(50) DEFAULT NULL,
PRIMARY key(`id`)
);
alter table act_app_list MODIFY column is_show_window  tinyint(1) DEFAULT 0 COMMENT 'app是否弹框'


alter table sys_clients_contract add column confirm_time datetime DEFAULT null comment '合同确认时间';


alter table act_app_list
	add show_place smallint(3) default '111' not null comment '1:app顶部 10:banner 100:列表'
;

ALTER TABLE `sys_clients_apply`
  MODIFY COLUMN `bd_user`  varchar(300) DEFAULT NULL COMMENT '所属BD用户';


ALTER TABLE `pmt_orders`
ADD COLUMN `surcharge_rate`  decimal(10,5) NULL AFTER `customer_surcharge`;
ALTER TABLE `pmt_orders`
ADD COLUMN `custom_surcharge_rate`  decimal(10,5) NULL AFTER `surcharge_rate`;

ALTER TABLE `pmt_transactions`
ADD COLUMN `input_amount`  decimal(20,2) NULL AFTER `clearing_amount`;

ALTER TABLE `pmt_transactions`
ADD COLUMN `surcharge_cashback` decimal(10,4) default 0 after `royalpay_surcharge` comment '返现至营销账户';



ALTER TABLE sys_clients ADD store_photo VARCHAR(200) NULL;

CREATE TABLE `log_client_sub_merchant_id` (
  `id` varchar(50) NOT NULL,
  `sub_merchant_id_before` varchar(30) DEFAULT NULL COMMENT '修改之前的sub_merchant_id',
  `sub_merchant_id_after` varchar(30) NOT NULL COMMENT '修改之后的sub_merchant_id',
  `operator` varchar(30) NOT NULL COMMENT '操作人',
  `create_time` datetime NOT NULL COMMENT '创建时间',
  `client_id` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `pmt_sub_merchant_id` (
  `sub_merchant_id` varchar(30) NOT NULL,
  `merchant_id` varchar(30) NOT NULL,
  `is_valid` tinyint(1) DEFAULT 1,
  `operator` varchar(30) DEFAULT '',
  `create_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`sub_merchant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


alter table sys_clients add column common_sub_merchant_id tinyint(1) default 0 comment '是否使用通用子商户号';


CREATE TABLE `cli_sub_merchant_id` (
  `sub_merchant_id` varchar(30) NOT NULL,
  `merchant_id` varchar(30) DEFAULT NULL,
  `client_count` int(8) DEFAULT NULL,
  `temp_sub_merchant` tinyint(1) DEFAULT 0,
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`sub_merchant_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `sys_clients` ADD COLUMN `business_hours` varchar(100) DEFAULT '';
ALTER TABLE `sys_clients` ADD COLUMN `merchant_introduction` varchar(500) DEFAULT '';
ALTER TABLE `sys_clients` ADD COLUMN  `merchant_tag` varchar(100) DEFAULT '';
ALTER TABLE `sys_clients` ADD COLUMN `merchant_video_url` varchar(200) DEFAULT '';




create table risk_merchant_record(
    id                        varchar(50)       not null        comment 'id',
    create_time               datetime             not null         comment '创建时间',
    expiry_time               datetime             not null         comment '过期时间',
    client_id                 int(11)          	not null        comment '商户id',
    client_moniker            varchar(20)       not null        comment '商户code',
    status                    varchar(5)        not null        comment '记录状态 0:未处理,1已处理,2处理中',
    risk_types                varchar(50)        not null        comment '触发的风控类型 "," 号分割',
    risk_counts               varchar(70)        null             comment '对应类型触发次数 "," 号分割',
    primary key(id),
    key(client_id) using BTREE
);


create table risk_white_list(
    client_id                 int(11)          	not null        comment '商户id',
    client_moniker            varchar(20)       not null        comment '商户code',
    create_time 	      datetime		not null	comment '创建时间',
    is_valid		      TINYINT(1)	DEFAULT 1	COMMENT '是否可用',
    primary key(client_id),
    key(client_id) USING BTREE,
    key(client_moniker)
);


create table risk_merchant_detail_log(
    id                        varchar(50)       not null        comment 'id',
    record_id                 varchar(50)       not null        comment '商户风控记录id',
    create_time               datetime          not null         comment '创建时间',
    client_id                 int(11)          	not null        comment '商户id',
    auditor                   varchar(30)       not null        comment '操作者',
    auditor_id                varchar(50)       not null        comment '操作者id',
    files                     varchar(500)      null            comment '上传附件 "," 号分割',
    remark                    varchar(100)      null            comment '备注',
    primary key(id),
    key(client_id) using BTREE,
    key(record_id)

);


create table risk_transaction_log(
    id                        varchar(50)       not null        comment 'id',
    order_id                  varchar(500)      not null        comment '问题订单id',
    record_id                 varchar(50)       not null        comment '商户风控记录id',
    amount                    DECIMAL(10,2)     not null        comment '过期时间',
    channel                   varchar(15)       NULL 		COMMENT '订单支付通道',
    client_id                 int(11)          	not null        comment '商户id',
    risk_types                varchar(50)        not null        comment '触发的风控类型 ","号分割 ',
    create_time		      datetime		not null,
    primary key(id),
    key(order_id),
    key(record_id),
    key(client_id)



);

insert into `royalpay_production`.`sys_configs` ( `config_key`, `config_value`) values ( 'risk_counts', '3');
insert into `royalpay_production`.`sys_configs` ( `config_key`, `config_value`) values ( 'risk_total_amout', '5000');


CREATE TABLE `pmt_directed_bill_code` (
  `bill_code_id` varchar(50) NOT NULL DEFAULT '',
  `client_id` int(15) not NULL,
  `client_order_id` varchar(50) DEFAULT NULL,
  `status` int(10) DEFAULT '1'  COMMENT '账单状态 1：可用，2：关闭 3:完成',
  `customer_id` varchar(200) DEFAULT NULL COMMENT 'open_id',
  `create_time` datetime not NULL  DEFAULT now() comment '账单创建时间',
  `currency` varchar(10) not NULL,
  `remark` varchar(200) DEFAULT NULL,
  `cancle_time` datetime DEFAULT NULL,
  `channel` varchar(10) DEFAULT NULL,
  `nickname` varchar(80) DEFAULT NULL,
  `headimg` varchar(200) DEFAULT NULL,
  `code_url` varchar(200) DEFAULT '',
  `order_id` varchar(50) DEFAULT '',
  `order_amount` decimal(10,4) not NULL comment '账单金额',
  `pay_amount` decimal(10,4) DEFAULT NULL comment '订单支付金额',
  `pay_time` datetime DEFAULT NULL comment '支付时间',
  `order_status` int(10) DEFAULT NULL COMMENT '订单状态(0-New,1-OrderFailed,2-WaitingForPayment,3-OrderCanceled,4-PaymentFailed,5-PaymentSuccess,6-PartialRefund,7-FullRefund)',
  PRIMARY KEY (`bill_code_id`),
  KEY `client_id` (`client_id`),
  KEY `order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `act_red_packets_customer` ADD COLUMN `rule_max_num_limit` tinyint(1) DEFAULT 1 COMMENT '0:Whole Activity,1：day';



CREATE TABLE `sys_mail_send` (
  `id` int(11) NOT NULL,
  `mail_address` varchar(100) NOT NULL COMMENT '邮箱地址',
  `cc_mail_address` varchar(100) NOT NULL COMMENT '邮箱地址',
  `message_id` varchar(60) NOT NULL COMMENT 'Mailgun Message id',
  `status` int(9) NOT NULL DEFAULT 0,
  `create_time` datetime not null DEFAULT now(),
  `title` varchar(50) NOT NULL comment '邮件标题',
  PRIMARY KEY (`id`,`mail_address`),
  KEY `mail_address` (`mail_address`),
  KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4

alter table sys_clients add column mail_confirm tinyint(1) default '0' COMMENT '0: 未验证，1已验证';

CREATE TABLE `sys_client_pre_apply` (
  `client_pre_apply_id` int(11) NOT NULL AUTO_INCREMENT,
  `password` varchar(20) DEFAULT '',
  `contact_person` varchar(50) DEFAULT NULL,
  `contact_phone` varchar(20) DEFAULT '',
  `contact_email` varchar(255) DEFAULT NULL,
  `company_name` varchar(100) DEFAULT NULL,
  `abn` varchar(20) DEFAULT NULL,
  `short_name` varchar(50) DEFAULT NULL,
  `address` varchar(200) DEFAULT NULL,
  `suburb` varchar(50) DEFAULT NULL,
  `state` varchar(20) DEFAULT NULL,
  `postcode` varchar(20) DEFAULT NULL,
  `industry` varchar(50) DEFAULT NULL,
  `bank_no` varchar(20) DEFAULT NULL,
  `bank_name` varchar(50) DEFAULT NULL,
  `bsb_no` varchar(6) DEFAULT NULL,
  `clean_days` smallint(6) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `agree` tinyint(1) DEFAULT NULL,
  `company_phone` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`client_pre_apply_id`),
  UNIQUE KEY `username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


alter table sys_accounts add COLUMN nation_code VARCHAR(5) DEFAULT NULL ;

alter table sys_client_pre_apply add COLUMN `client_moniker` varchar(20) DEFAULT NULL COMMENT '客户简写识别码';

alter table sys_client_pre_apply modify COLUMN `agree` tinyint(1) DEFAULT 0;


insert into `royalpay_production`.`sys_configs` ( `config_key`, `config_value`) values ( 'royalpayindustry.json', '[{"children":[{"children":[],"label":"机票","mccCode":"10001"},{"children":[],"label":"旅游行业","mccCode":"10002"},{"children":[],"label":"私人定制旅游","mccCode":"10003"},{"children":[],"label":"租车","mccCode":"10004"},{"children":[],"label":"巴士","mccCode":"10005"}],"label":"旅游出行","mccCode":"1"},{"children":[{"children":[],"label":"饭店","mccCode":"20001"},{"children":[],"label":"奶茶店","mccCode":"20002"},{"children":[],"label":"烧烤","mccCode":"20003"},{"children":[],"label":"火锅","mccCode":"20004"},{"children":[],"label":"Coffee","mccCode":"20005"},{"children":[],"label":"酒吧","mccCode":"20006"}],"label":"餐饮","mccCode":"2"},{"children":[{"children":[],"label":"培训类","mccCode":"30001"},{"children":[],"label":"移民留学","mccCode":"30002"},{"children":[],"label":"私人幼儿园","mccCode":"30003"}],"label":"教育","mccCode":"3"},{"children":[{"children":[],"label":"换汇","mccCode":"40001"},{"children":[],"label":"房产","mccCode":"40002"}],"label":"商务咨询","mccCode":"4"},{"children":[{"children":[],"label":"公众号服务商","mccCode":"50001"},{"children":[],"label":"各种媒体类宣传","mccCode":"50002"}],"label":"传媒","mccCode":"5","value":"{\"category\":\"SERVICE\",\"code\":\"7542\",\"description\":\"Car Washes\",\"parentCode\":\"S10\"}"},{"children":[{"children":[],"label":"美容院","mccCode":"60001"},{"children":[],"label":"医疗美容","mccCode":"60002"}],"label":"医美","mccCode":"6"},{"children":[{"label":"超市","mccCode":"70001"},{"children":[],"label":"服装店","mccCode":"70002"},{"children":[],"label":"鞋店","mccCode":"70003"},{"children":[],"label":"珠宝店","mccCode":"70004"},{"children":[],"label":"箱包","mccCode":"70005"}],"label":"零售","mccCode":"7"},{"children":[{"children":[],"label":"桌游吧","mccCode":"80001"},{"children":[],"label":"演唱会","mccCode":"80002"},{"children":[],"label":"马术训练","mccCode":"80003"},{"children":[],"label":"瑜伽","mccCode":"80004"},{"children":[],"label":"健身","mccCode":"80005"},{"children":[],"label":"社团","mccCode":"80006"},{"children":[],"label":"网吧","mccCode":"80007"},{"children":[],"label":"KTV","mccCode":"80008"},{"children":[],"label":"电影","mccCode":"80009"}],"label":"休闲娱乐","mccCode":"8"},{"children":[{"children":[],"label":"摄影","mccCode":"90001"},{"children":[],"label":"massage","mccCode":"90002"},{"children":[],"label":"通讯运营商","mccCode":"90003"},{"children":[],"label":"车行","mccCode":"90004"},{"children:":[],"label":"软件服务","mccCode":"90005"}],"label":"其他服务类","mccCode":"9"},{"children":[{"children":[],"label":"Hotel","mccCode":"100001"},{"children":[],"label":"Motel","mccCode":"100002"}],"label":"酒店","mccCode":"10"},{"children":[{"children":[],"label":"代购","mccCode":"110001"},{"children":[],"label":"物流(大宗出口贸易)","mccCode":"110002"},{"children":[],"label":"红酒出口","mccCode":"110003"},{"children":[],"label":"综合电商","mccCode":"110004"}],"label":"出口贸易","mccCode":"11"},{"children":[{"children":[],"label":"建材","mccCode":"120001"},{"children":[],"label":"家居","mccCode":"120002"}],"label":"家居建材","mccCode":"12"}]');


ALTER TABLE `sys_client_config`
ADD COLUMN `gateway_alipay_online`  tinyint(1) NULL DEFAULT 1 COMMENT '支付宝线上网关使用线上渠道' AFTER `require_remark`;
ALTER TABLE `sys_clients`
ADD COLUMN `gateway_alipay_online`  tinyint(1) NULL DEFAULT 1 COMMENT '支付宝线上网关使用线上渠道' AFTER `require_remark`;

alter table pmt_refunds add column remark varchar(200);

alter table sys_client_pre_apply add column `salt` varchar(30) NOT NULL COMMENT '每次修改密码时随机更改';
alter table sys_client_pre_apply add column `password_hash` varchar(150) NOT NULL COMMENT '登录账户密码 base64(sha256(salt+password))';
alter table sys_client_pre_apply add column  `password_aes` varchar(50) NOT NULL COMMENT '登录账户密码 AES加密';

alter table sys_client_pre_apply add column apply_source varchar(10) default null COMMENT '申请渠道';


CREATE TABLE `sys_mail_unsub` (
  `id` bigint(20) NOT NULL,
  `address` varchar(50) NOT NULL,
  `client_id` int(11) NOT NULL,
  `client_moniker` varchar(20) NOT NULL,
  `create_time` timestamp NOT NULL DEFAULT now(),
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='邮箱取消订阅';



alter table sys_clients add column ali_sub_merchant_id varchar(20) DEFAULT NULL;
update sys_clients set ali_sub_merchant_id = client_moniker;

alter table sys_clients add column enable_hf TINYINT(1) default '0';
alter table sys_client_config add column enable_hf TINYINT(1) default '0';
alter table sys_clients add column enable_link TINYINT(1) default '0';
alter table sys_client_config add column enable_link TINYINT(1) default '0';
alter table sys_clients add column hf_pay_url VARCHAR(150) DEFAULT null COMMENT '汇付通支付短连接';
alter table sys_client_config add column hf_pay_url VARCHAR(150) DEFAULT null COMMENT '汇付通支付短连接';


ALTER TABLE sys_org ADD COLUMN min_hf_rate DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户最低hf费率';
ALTER TABLE sys_org ADD COLUMN hf_rate_value DECIMAL(3,2) DEFAULT NULL COMMENT '旗下商户hf费率';


ALTER TABLE `log_clearing_detail`
ADD COLUMN `settle_bank`  varchar(10) NULL DEFAULT NULL COMMENT '清算来源银行(RoyalPay)' AFTER `account_name`;
update log_clearing_detail set settle_bank='CBA';


ALTER TABLE `log_clearing`
ADD COLUMN `editable`  tinyint(1) NULL DEFAULT 1 COMMENT '是否可编辑' AFTER `balance`;


CREATE TABLE `pre_apply_handle_log` (
  `id` varchar(50) NOT NULL,
  `client_pre_apply_id` int(11) NOT NULL,
  `client_id` int(11) NOT NULL,
  `auditor` varchar(30) NOT NULL,
  `auditor_id` varchar(50) NOT NULL,
  `remark` varchar(100) DEFAULT NULL,
  `create_time` datetime NOT NULL,
  PRIMARY KEY (`id`),
  KEY `client_id` (`client_id`) USING BTREE,
  KEY `client_pre_apply_id` (`client_pre_apply_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `sys_client_pre_apply`
ADD COLUMN `status`  tinyint(2) NULL DEFAULT 0 COMMENT '0:未处理，1：处理中，2：处理完成';

alter table sys_clients add column hfindustry varchar(10) DEFAULT NULL COMMENT 'HF行业';

alter table financial_bd_prize_rate_config add column `kpi_range` smallint(6) NOT NULL;
alter table financial_bd_config add column `kpi_amount` decimal(15,2) DEFAULT NULL;
alter table financial_bd_prize_log add column `kpi_amount` decimal(15,2) DEFAULT NULL;

CREATE TABLE sys_permission_partner_modules (
  id int(11) NOT NULL AUTO_INCREMENT,
  module_name varchar(50) NOT NULL COMMENT '模块名称',
  js_module varchar(50) DEFAULT NULL COMMENT 'js module name',
  js_path varchar(255) DEFAULT NULL COMMENT 'js module path',
  remark varchar(50) DEFAULT NULL,
  PRIMARY KEY (id)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4;

CREATE TABLE sys_permission_partner_modules_clients (
  id bigint(20) NOT NULL,
  client_id int(11) NOT NULL COMMENT '客户编号',
  client_moniker varchar(20) NOT NULL COMMENT '客户简写识别码',
  module_id int(11) NOT NULL COMMENT '模块id',
  is_valid tinyint(1) DEFAULT '1' COMMENT '1:启用,0:不启用',
  PRIMARY KEY (id),
  UNIQUE KEY unique_client_id_module_id (client_id,module_id),
  KEY index_client_id (client_id),
  KEY index_client_moniker (client_moniker)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE sys_permission_partner_functions (
  func_id varchar(80) NOT NULL,
  module_id int(11) DEFAULT NULL COMMENT '模块id',
  role int(11) NOT NULL DEFAULT '0' COMMENT '有权限角色(mask)',
  class_name varchar(30) NOT NULL COMMENT '类名',
  method_name varchar(50) NOT NULL COMMENT '方法名',
  uri varchar(200) NOT NULL COMMENT '请求地址',
  req_methods varchar(50) NOT NULL,
  module varchar(30) DEFAULT NULL COMMENT '所属模块',
  name varchar(50) DEFAULT NULL COMMENT '别名(用于前端按钮指定权限)',
  remark varchar(50) DEFAULT NULL COMMENT '备注',
  is_valid tinyint(1) DEFAULT '1' COMMENT '是否有效',
  PRIMARY KEY (func_id),
  UNIQUE KEY uk_func_name (name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `act_charity` (
  `client_id` int(11) DEFAULT NULL,
  `client_moniker` varchar(20) NOT NULL COMMENT '客户简写识别码',
  `active_time` date DEFAULT NULL,
  PRIMARY KEY (`client_moniker`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `risk_attention_merchants` (
  `client_id` int(11) NOT NULL,
  `client_moniker` varchar(20) NOT NULL,
  `is_valid` tinyint(1) NOT NULL DEFAULT 1,
  `create_time` datetime NOT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`client_id`),
  KEY `client_moniker` (`client_moniker`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


ALTER TABLE `sys_clients`
ADD COLUMN `wechat_institution_merchant_id`  varchar(6) NULL AFTER `wechat_institution_merchant_id`;
ALTER TABLE `log_client_sub_merchant_id`
ADD COLUMN `wechat_institution_merchant_id`  varchar(6) NULL AFTER `client_id`;


INSERT INTO `sys_configs` VALUES ('payment.ali.individual_daily_limit', 100000,null);
INSERT INTO `sys_configs` VALUES ('payment.ali.individual_yearly_limit', 500000,null);
INSERT INTO `sys_configs` VALUES ('payment.ali.per_order_limit', 10000,null);

update sys_clients set contact_phone = concat('+61',contact_phone) where create_time >'2018-06-01' and source = 4

ALTER TABLE `log_clearing_detail`
ADD COLUMN `total_cashback`  decimal(16,3) NOT NULL DEFAULT 0 COMMENT '返现总额(2018-04-21开始计算)' AFTER `tax_amount`,
DEFAULT CHARACTER SET DEFAULT;

ALTER TABLE `log_clearing`
ADD COLUMN `total_charge`  decimal(16,3) NOT NULL DEFAULT 0 COMMENT '总手续费' AFTER `royalpay_charge`,
ADD COLUMN `charge_cashback`  decimal(16,3) NOT NULL DEFAULT 0 COMMENT '返现' AFTER `total_charge`;


ALTER TABLE `pmt_custom_reports`
ADD COLUMN `report_serial`  varchar(50) NOT NULL FIRST ,
ADD COLUMN `serial_no`  int NULL DEFAULT 0 AFTER `report_id`,
ADD COLUMN `custom_target`  varchar(30) NOT NULL AFTER `custom`,
DROP PRIMARY KEY,
DROP INDEX `client_id` ,
ADD INDEX `client_id` (`client_id`) USING HASH ,
DROP INDEX `order_id` ,
ADD INDEX `order_id` (`order_id`) USING HASH ,
DROP INDEX `channel` ,
ADD INDEX `channel` (`channel`) USING HASH ,
ADD INDEX `report_id` (`report_id`) USING HASH ;


update pmt_custom_reports set report_serial=uuid();

alter pmt_custom_reports add PRIMARY key (report_serial);
alter table sys_org add COLUMN  `state` varchar(20) DEFAULT NULL COMMENT '州 (使用标准码 NSW,QLD,WA,VIC,ACT,NT,TAS,SA)';