-- 系统配置表
-- INPUT_TYPE: 1.TEXT 2.SELECT. 3.CHECKBOX 4.YEAR_PICKER 5.DATE_TIME_PICKER 6.DATE_PICKER 7.TIME_PICKER 8.SWITCH
-- OPTIONS: STRING类型的关于上面的需要附加参数的选项
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CONFIG';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CONFIG
(
  CONFIG_NAME     VARCHAR2(32)                    NOT NULL PRIMARY KEY,
  TITLE           VARCHAR2(48)                    NOT NULL,
  UNIT            VARCHAR2(32),
  INPUT_TYPE      NUMBER(2) DEFAULT 1             NOT NULL,
  OPTIONS         VARCHAR2(4000),
  VALUE           VARCHAR2(4000) DEFAULT 1        NOT NULL,
  TYPE            VARCHAR2(32)                    NOT NULL,
  SORT            NUMBER(10) DEFAULT 1            NOT NULL,
  CREATED_AT      NUMBER(10)                      NOT NULL,
  UPDATED_AT      NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_CONFIG IS '系统配置表';
COMMENT ON COLUMN AR_CONFIG.CONFIG_NAME IS '配置参数名';
COMMENT ON COLUMN AR_CONFIG.TITLE IS '标题';
COMMENT ON COLUMN AR_CONFIG.UNIT IS '单位';
COMMENT ON COLUMN AR_CONFIG.INPUT_TYPE IS '表单类型';
COMMENT ON COLUMN AR_CONFIG.OPTIONS IS '参数配置的选项';
COMMENT ON COLUMN AR_CONFIG.VALUE IS '配置值';
COMMENT ON COLUMN AR_CONFIG.TYPE IS '类型';
COMMENT ON COLUMN AR_CONFIG.SORT IS '排序';
COMMENT ON COLUMN AR_CONFIG.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CONFIG.UPDATED_AT IS '更新时间';

INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('siteTitle', '网站标题', null, 1, null, '会员管理系统', 'base', 1, 1521085263, 1524013893);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('decPercent', '报单奖比例', '%', 1, null, '3', 'bonus', 1, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('transferOpen', '是否开启转账功能', null, 8, null, '1', 'transfer', 1, 1521085263, 1581816562);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsOpen', '是否开启短信通知', null, 8, null, '1', 'sms', 1, 1521085263, 1522396087);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('calcYear', '期数计算至年份', '年', 4, null, '2021', 'period', 1, 1521085263, 1580998939);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('siteClose', '是否关闭网站', null, 8, null, '0', 'base', 2, 1521085263, 1524013893);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('allowWallet', '转出转入配置', null, 10, null, '[{"out":"bonus","in":"cash","outMin":"0","outMax":"500","fee":"0","feeMin":"0","feeMax":"0","weekMax":"0","monthMax":"0","isSystem":true,"isBind":true,"isOpen":true},{"out":"bonus","in":"bonus","outMin":"0","outMax":"1000","fee":"0","feeMin":"0","feeMax":"0","weekMax":"2000","monthMax":"5000","isSystem":true,"isBind":true,"isOpen":true}]', 'transfer', 2, 1521085263, 1581816562);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsFee', '短信月费用', '元/月', 1, null, '10', 'sms', 2, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('closeWeekDate', '自动封期星期', null, 2, '[{"label":"星期一","value":"1"},{"label":"星期二","value":"2"},{"label":"星期三","value":"3"},{"label":"星期四","value":"4"},{"label":"星期五","value":"5"},{"label":"星期六","value":"6"},{"label":"星期日","value":"0"}]', '1', 'period', 2, 1521085263, 1580998939);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('recPercent', '推广奖比例', '%', 1, null, '15', 'bonus', 2, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('siteCloseInfo', '关闭提示信息', null, 1, null, '网站正在维护中...', 'base', 3, 1521085263, 1524013893);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('pointsLayer', '业绩奖偶数层数', '层', 1, null, '10', 'bonus', 3, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsWallet', '短信费用扣除钱包', null, 2, '[{"label":"奖金钱包","value":"1"},{"label":"现金钱包","value":"2"}]', '1,2', 'sms', 3, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('closeTime', '自动封期时间', null, 7, '{"start":"00:00","end":"23:59","step":"00:30"}', '00:00', 'period', 3, 1521085263, 1580998939);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsContent', '短信内容', null, 9, null, '尊敬的会员{%REAL_NAME%}！您的最迟复销充值日期是{%LAST_RECHARGE_DATE%}、您{%MONTH%}{%IS_PASS%}，请留意您的复销状态；如已交复销请忽略此短信。', 'sms', 4, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('pointsPercent', '业绩奖比例', '%', 1, null, '1', 'bonus', 4, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('shareRegPerson', '共享奖注册时间人数', '人', 1, null, '7', 'bonus', 5, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('sharePercent', '共享奖比例', '%', 1, null, '5', 'bonus', 6, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('parentOddPercent_0', '管理奖1/3/5代比例', '%', 1, null, '5', 'bonus', 7, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('parentOddPercent_1', '管理奖7/9/11代比例', '%', 1, null, '4', 'bonus', 8, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('parentOddPercent_2', '管理奖13/15/17代比例', '%', 1, null, '2', 'bonus', 9, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsEmpOpen', '是否开启首次达到聘级短信通知', null, 8, null, '1', 'sms', 10, 1521085263, 1522396087);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('parentOddPercent_3', '管理奖19/21/23代比例', '%', 1, null, '3', 'bonus', 10, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsEmp', '达到的聘级', null, 2, '[{"label":"高级经理","value":"1"},{"label":"合格高级经理","value":"2"},{"label":"一钻经理","value":"3"},{"label":"二钻经理","value":"4"},{"label":"三钻经理","value":"5"},{"label":"四钻经理","value":"6"},{"label":"五钻经理","value":"7"},{"label":"六钻经理","value":"8"},{"label":"七钻经理","value":"9"},{"label":"七星董事","value":"10"},{"label":"六星董事","value":"11"},{"label":"三星董事","value":"12"}]', '1,2,3,4,5,6,7,8,9,10,11,12', 'sms', 11, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('reConsumePointsPercent', '重复消费积分比例', '%', 1, null, '10', 'bonus', 11, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('smsEmpContent', '聘级短信内容', null, 9, null, '尊敬的会员{%REAL_NAME%}！恭喜您于{%EMP_LV_DATE%}升级到{%EMP_LV%}。', 'sms', 12, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('reConsumePointsMonthCap', '重复消费积分每月上限', '积分', 1, null, '1000', 'bonus', 12, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('showBonusPeriodNum', '前台可见往期奖金期数', '期', 1, null, '10', 'other', 13, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('manageTaxPercent', '管理费比例', '%', 1, null, '5', 'bonus', 13, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('showFlowPeriodNum', '前台可见交易记录期数', '期', 1, null, '10', 'other', 14, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('bonusTotalZeroLimit', '总收入限制(推荐0人)', '倍', 1, null, '1', 'bonus', 14, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('showTransferPeriodNum', '前台可见转账记录期数', '期', 1, null, '10', 'other', 15, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('bonusTotalOneLimit', '总收入限制(推荐1人)', '倍', 1, null, '2', 'bonus', 15, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('showWithdrawPeriodNum', '前台可见提现记录期数', '期', 1, null, '10', 'other', 16, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('bonusTotalTwoLimit', '总收入限制(推荐2人)', '倍', 1, null, '4', 'bonus', 16, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('sameEmpLevelPercent', '相同聘级荣衔奖比例', '%', 1, null, '10', 'bonus', 17, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openQY', '是否开启团队奖', null, 8, null, '1', 'bonus', 20, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openYC', '是否开启荣衔奖', null, 8, null, '1', 'bonus', 21, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openBD', '是否开启报单奖', null, 8, null, '1', 'bonus', 23, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('manualWithdrawMinAmount', '手动提现最低金额', '元', 1, null, '100', 'other', 23, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openTG', '是否开启推广奖', null, 8, null, '1', 'bonus', 24, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openYJ', '是否开启业绩奖', null, 8, null, '1', 'bonus', 25, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openGX', '是否开启共享奖', null, 8, null, '1', 'bonus', 26, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('withdrawFreezeDays', '提现预付款天数', '天', 1, null, '30', 'other', 26, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('openGL', '是否开启管理奖', null, 8, null, '1', 'bonus', 27, 1521085263, 1581836154);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('isCanWithdrawBack', '是否开启前台提现退回功能', null, 8, null, '1', 'other', 27, 1521085263, 1522396087);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('autoClosePeriod', '自动封期', null, 8, null, '1', 'other', 41, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('autoCalcPeriod', '自动结算', null, 8, null, '1', 'other', 42, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('isCanTransferProp', '是否开启单笔转账比例', null, 8, null, '1', 'other', 43, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('backupWeekDate', '备份星期', null, 2, '[{"label":"星期一","value":"1"},{"label":"星期二","value":"2"},{"label":"星期三","value":"3"},{"label":"星期四","value":"4"},{"label":"星期五","value":"5"},{"label":"星期六","value":"6"},{"label":"星期日","value":"0"}]', '6', 'other', 44, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('backupTime', '备份时间', null, 7, '{"start":"00:00","end":"23:59","step":"00:30"}', '03:30', 'other', 45, 1521085263, 1524116298);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('historyBonusLimit', '奖金余额备份近几周', '周', 1, null, '5', 'other', 46, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('payPasswordRule', '支付密码规则', null, 2, '[{"label":"无","value":"0"},{"label":"身份证后6位","value":"id_s_6"},{"label":"身份证前8位","value":"id_p_8"},{"label":"用户名","value":"user_name"}]', 'user_name', 'other', 47, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('passwordRule', '密码规则', null, 2, '[{"label":"无","value":"0"},{"label":"身份证后6位","value":"id_s_6"},{"label":"身份证前8位","value":"id_p_8"},{"label":"用户名","value":"user_name"}]', '0', 'other', 48, 1521085263, 1541830796);
INSERT INTO AKBONUS.AR_CONFIG (CONFIG_NAME, TITLE, UNIT, INPUT_TYPE, OPTIONS, VALUE, TYPE, SORT, CREATED_AT, UPDATED_AT) VALUES ('pvRatio', 'PV比例', null, 1, null, '0.7', 'other', 49, 1521085263, 1541830796);
COMMIT;

-- 管理员表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_ADMIN';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ADMIN
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  ADMIN_NAME    VARCHAR2(255)                   NOT NULL,
  REAL_NAME    VARCHAR2(128)                   NOT NULL,
  REMARK    VARCHAR2(255) ,
  ROLE_ID    VARCHAR2(32)         NOT NULL,
  IS_ENABLE NUMBER(1) DEFAULT 1 NOT NULL,
  AUTH_KEY    VARCHAR2(255) ,
  PASSWORD_HASH    VARCHAR2(255)                   NOT NULL,
  PASSWORD_RESET_TOKEN VARCHAR2(255),
  DONT_DEL    NUMBER(1) DEFAULT 0             NOT NULL,
  IS_DEL    NUMBER(1) DEFAULT 0             NOT NULL,
  LOGIN_NUMS NUMBER(10) DEFAULT 0            NOT NULL,
  FAIL_NUMS NUMBER(10) DEFAULT 0            NOT NULL,
  LAST_LOGIN_IP VARCHAR2(16) DEFAULT '0.0.0.0' NOT NULL ,
  LAST_LOGIN_AT  NUMBER(10) DEFAULT 0                     NOT NULL,
  BIND_IP VARCHAR2(4000) ,
  CREATE_ADMIN  VARCHAR2(32)                  NOT NULL,
  UPDATE_ADMIN   VARCHAR2(32),
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  DELETED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_ADMIN IS '管理员表';
COMMENT ON COLUMN AR_ADMIN.ADMIN_NAME IS '用户名';
COMMENT ON COLUMN AR_ADMIN.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_ADMIN.REMARK IS '备注';
COMMENT ON COLUMN AR_ADMIN.ROLE_ID IS '角色ID';
COMMENT ON COLUMN AR_ADMIN.IS_ENABLE IS '是否启用';
COMMENT ON COLUMN AR_ADMIN.AUTH_KEY IS '认证KEY';
COMMENT ON COLUMN AR_ADMIN.PASSWORD_HASH IS '密码';
COMMENT ON COLUMN AR_ADMIN.PASSWORD_RESET_TOKEN IS '重设密码TOKEN';
COMMENT ON COLUMN AR_ADMIN.DONT_DEL IS '不可删除';
COMMENT ON COLUMN AR_ADMIN.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_ADMIN.LOGIN_NUMS IS '登录次数';
COMMENT ON COLUMN AR_ADMIN.FAIL_NUMS IS '登录失败次数';
COMMENT ON COLUMN AR_ADMIN.LAST_LOGIN_IP IS '上次登录IP';
COMMENT ON COLUMN AR_ADMIN.LAST_LOGIN_AT IS '上次登录时间';
COMMENT ON COLUMN AR_ADMIN.BIND_IP IS '绑定IP';
COMMENT ON COLUMN AR_ADMIN.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_ADMIN.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_ADMIN.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_ADMIN.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_ADMIN.DELETED_AT IS '删除时间';

CREATE UNIQUE INDEX AR_ADMIN_AN_UNINDEX ON AR_ADMIN(ADMIN_NAME);

INSERT INTO AR_ADMIN (ID, ADMIN_NAME, REAL_NAME, REMARK, ROLE_ID, IS_ENABLE, AUTH_KEY, PASSWORD_HASH, DONT_DEL, LOGIN_NUMS, FAIL_NUMS, LAST_LOGIN_IP, LAST_LOGIN_AT, BIND_IP, CREATE_ADMIN, CREATED_AT) VALUES ('65F27BCE7FD278FFE055736AECE8644D', 'admin', 'admin', '', '666A7F102B8D6C66E055736AECE8644D', 1, 'asdsad', '$2y$13$ZTJsT7UpOiaebII1ex3vV.boCW9hTJseV3/pbuYJ2lQQltcKq/hcG', 1, 0, 0, '0.0.0.0', 0, '', '65F27BCE7FD278FFE055736AECE8644D', 1519978161);
COMMIT ;

-- 管理员角色表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_ADMIN_ROLE';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ADMIN_ROLE
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  ROLE_NAME    VARCHAR2(255)                   NOT NULL,
  REMARK    VARCHAR2(255) ,
  PERMISSION    CLOB DEFAULT NULL,
  COLUMN_PERMISSION    CLOB DEFAULT NULL,
  DONT_DEL     NUMBER(1)  DEFAULT 0           NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                  ,
  UPDATE_ADMIN   VARCHAR2(32),
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_ADMIN_ROLE IS '管理员角色表';
COMMENT ON COLUMN AR_ADMIN_ROLE.ROLE_NAME IS '角色名';
COMMENT ON COLUMN AR_ADMIN_ROLE.REMARK IS '描述';
COMMENT ON COLUMN AR_ADMIN_ROLE.PERMISSION IS '权限';
COMMENT ON COLUMN AR_ADMIN_ROLE.COLUMN_PERMISSION IS '列表字段权限';
COMMENT ON COLUMN AR_ADMIN_ROLE.DONT_DEL IS '不可删除';
COMMENT ON COLUMN AR_ADMIN_ROLE.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_ADMIN_ROLE.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_ADMIN_ROLE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_ADMIN_ROLE.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_A_R_R_NAME_UNINDEX ON AR_ADMIN_ROLE(ROLE_NAME);

INSERT INTO AR_ADMIN_ROLE (ID, ROLE_NAME, REMARK, DONT_DEL, CREATE_ADMIN, CREATED_AT) VALUES ('666A7F102B8D6C66E055736AECE8644D', '超级管理员', '全局管理', 1, '65F27BCE7FD278FFE055736AECE8644D', 1519978161);
COMMIT ;


-- 管理员TOKEN表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_ADMIN_TOKEN';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ADMIN_TOKEN
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  ADMIN_ID     VARCHAR2(32)                    NOT NULL,
  PC_ACCESS_TOKEN  VARCHAR2(255) ,
  APP_ACCESS_TOKEN     VARCHAR2(255) ,
  PC_REFRESH_TOKEN     VARCHAR2(255) ,
  APP_REFRESH_TOKEN  VARCHAR2(255) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  PAT_UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  AAT_UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  PRT_UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  ART_UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_ADMIN_TOKEN IS '管理员TOKEN表';
COMMENT ON COLUMN AR_ADMIN_TOKEN.ADMIN_ID IS '管理员ID';
COMMENT ON COLUMN AR_ADMIN_TOKEN.PC_ACCESS_TOKEN IS 'PC认证TOKEN';
COMMENT ON COLUMN AR_ADMIN_TOKEN.APP_ACCESS_TOKEN IS 'APP认证TOKEN';
COMMENT ON COLUMN AR_ADMIN_TOKEN.PC_REFRESH_TOKEN IS 'PC刷新TOKEN';
COMMENT ON COLUMN AR_ADMIN_TOKEN.APP_REFRESH_TOKEN IS 'APP刷新TOKEN';
COMMENT ON COLUMN AR_ADMIN_TOKEN.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_ADMIN_TOKEN.PAT_UPDATED_AT IS 'PCACCESSTOKEN更新时间';
COMMENT ON COLUMN AR_ADMIN_TOKEN.AAT_UPDATED_AT IS 'APPACCESSTOKEN更新时间';
COMMENT ON COLUMN AR_ADMIN_TOKEN.PRT_UPDATED_AT IS 'PCREFRESHTOKEN更新时间';
COMMENT ON COLUMN AR_ADMIN_TOKEN.ART_UPDATED_AT IS 'PCREFRESHTOKEN更新时间';

CREATE UNIQUE INDEX AR_A_T_P_ACCESS_TOKEN_UNINDEX ON AR_ADMIN_TOKEN(PC_ACCESS_TOKEN);
CREATE UNIQUE INDEX AR_A_T_A_ACCESS_TOKEN_UNINDEX ON AR_ADMIN_TOKEN(APP_ACCESS_TOKEN);
CREATE UNIQUE INDEX AR_A_T_P_REFRESH_TOKEN_UNINDEX ON AR_ADMIN_TOKEN(PC_REFRESH_TOKEN);
CREATE UNIQUE INDEX AR_A_T_A_REFRESH_TOKEN_UNINDEX ON AR_ADMIN_TOKEN(APP_REFRESH_TOKEN);

INSERT INTO AR_ADMIN_TOKEN (ID, ADMIN_ID, PC_ACCESS_TOKEN, APP_ACCESS_TOKEN, PC_REFRESH_TOKEN, APP_REFRESH_TOKEN, CREATED_AT, PAT_UPDATED_AT, AAT_UPDATED_AT, PRT_UPDATED_AT, ART_UPDATED_AT) VALUES ('6642C11AD4A66F07E055736AECE8644D', '65F27BCE7FD278FFE055736AECE8644D', '08ff6856c6ff0c8289a4958921221e05', null, '7875e4c5eff79308d4ce2af7ed5ecd0c', null, 1519807464, 1521508188, 0, 1521508188, 0);
COMMIT ;

-- 会员TOKEN表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_TOKEN';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_TOKEN
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  PC_ACCESS_TOKEN  VARCHAR2(255) ,
  APP_ACCESS_TOKEN VARCHAR2(255) ,
  PC_REFRESH_TOKEN VARCHAR2(255) ,
  APP_REFRESH_TOKEN VARCHAR2(255) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  PAT_UPDATED_AT  NUMBER(10) DEFAULT 0        NOT NULL,
  AAT_UPDATED_AT  NUMBER(10) DEFAULT 0        NOT NULL,
  PRT_UPDATED_AT  NUMBER(10) DEFAULT 0        NOT NULL,
  ART_UPDATED_AT  NUMBER(10) DEFAULT 0        NOT NULL
);
COMMENT ON TABLE AR_USER_TOKEN IS '会员TOKEN表';
COMMENT ON COLUMN AR_USER_TOKEN.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_TOKEN.PC_ACCESS_TOKEN IS 'PC端TOKEN';
COMMENT ON COLUMN AR_USER_TOKEN.APP_ACCESS_TOKEN IS 'APP端TOKEN';
COMMENT ON COLUMN AR_USER_TOKEN.PC_REFRESH_TOKEN IS 'PC刷新TOKEN';
COMMENT ON COLUMN AR_USER_TOKEN.APP_REFRESH_TOKEN IS 'APP刷新TOKEN';
COMMENT ON COLUMN AR_USER_TOKEN.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_TOKEN.PAT_UPDATED_AT IS 'PC端TOKEN更新时间';
COMMENT ON COLUMN AR_USER_TOKEN.AAT_UPDATED_AT IS 'APP端TOKEN更新时间';
COMMENT ON COLUMN AR_USER_TOKEN.PRT_UPDATED_AT IS 'PC刷新TOKEN更新时间';
COMMENT ON COLUMN AR_USER_TOKEN.ART_UPDATED_AT IS 'APP刷新TOKEN更新时间';

CREATE UNIQUE INDEX AR_U_T_P_ACCESS_TOKEN_UNINDEX ON AR_USER_TOKEN(PC_ACCESS_TOKEN);
CREATE UNIQUE INDEX AR_U_T_A_ACCESS_TOKEN_UNINDEX ON AR_USER_TOKEN(APP_ACCESS_TOKEN);
CREATE UNIQUE INDEX AR_U_T_P_REFRESH_TOKEN_UNINDEX ON AR_USER_TOKEN(PC_REFRESH_TOKEN);
CREATE UNIQUE INDEX AR_U_T_A_REFRESH_TOKEN_UNINDEX ON AR_USER_TOKEN(APP_REFRESH_TOKEN);


-- 复销池(未扣除的复销PV+未扣除的复销有效月 = 可用有效复销的结算月数)
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_RECONSUME_POOL';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RECONSUME_POOL
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  UNUSED_PV   NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  UNUSED_MONTH NUMBER(10) DEFAULT 0           NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_RECONSUME_POOL IS '复销池';
COMMENT ON COLUMN AR_RECONSUME_POOL.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RECONSUME_POOL.UNUSED_PV IS '未扣除PV';
COMMENT ON COLUMN AR_RECONSUME_POOL.UNUSED_MONTH IS '未扣除月数';
COMMENT ON COLUMN AR_RECONSUME_POOL.CREATED_AT IS '创建时间';

CREATE UNIQUE INDEX AR_R_P_USER_ID_UNINDEX ON AR_RECONSUME_POOL(USER_ID);

-- 复销池变动流水
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_RECONSUME_POOL_FLOW';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RECONSUME_POOL_FLOW
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  RECONSUME_POOL_SN     VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  RECONSUME_POOL_TYPE        NUMBER(1) DEFAULT 1             NOT NULL,
  DEAL_TYPE        NUMBER(1) DEFAULT 1             NOT NULL,
  DEDUCT_PV   NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  DEDUCT_MONTH NUMBER(10) DEFAULT 0           NOT NULL,
  UNUSED_PV   NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  UNUSED_MONTH NUMBER(10) DEFAULT 0           NOT NULL,
  IS_FX_DEDUCT NUMBER(1) DEFAULT 0            NOT NULL,
  REMARK      VARCHAR2(255) ,
  REMARK_IS_SHOW NUMBER(1) DEFAULT 1            NOT NULL,
  PERIOD_NUM  NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  CALC_MONTH  NUMBER(10)                      NOT NULL,
  P_CALC_MONTH DATE                           NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  ADMIN_NAME    VARCHAR2(32) DEFAULT ''
)
PARTITION BY RANGE(P_CALC_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_RECONSUME_POOL_FLOW IS '复销池变化流水';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.RECONSUME_POOL_SN IS '流水号';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.LAST_DEC_LV IS '流水产生时会员级别';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.LAST_EMP_LV IS '流水产生时会员聘级';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.LAST_STATUS IS '流水产生时会员状态';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.RECONSUME_POOL_TYPE IS '流水类型';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.DEAL_TYPE IS '交易类型';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.DEDUCT_PV IS '变动PV';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.DEDUCT_MONTH IS '变动PV';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.UNUSED_PV IS '当前剩余未扣除PV';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.UNUSED_MONTH IS '当前剩余未扣除PV';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.IS_FX_DEDUCT IS '是否复销扣除';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.REMARK IS '备注';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.REMARK_IS_SHOW IS '备注前台显示';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.CALC_MONTH IS '结算月';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.P_CALC_MONTH IS '分区表标识';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_RECONSUME_POOL_FLOW.ADMIN_NAME IS '操作人';

CREATE INDEX AR_R_P_F_USER_ID ON AR_RECONSUME_POOL_FLOW(USER_ID) LOCAL;
CREATE INDEX AR_R_P_F_TYPE ON AR_RECONSUME_POOL_FLOW(DEAL_TYPE) LOCAL;
CREATE INDEX AR_R_P_F_PERIOD_NUM ON AR_RECONSUME_POOL_FLOW(PERIOD_NUM) LOCAL;

-- 复销变动审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_RECONSUME_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RECONSUME_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  TYPE          NUMBER(1) DEFAULT 0             NOT NULL,
  CHANGE_PV     NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  CHANGE_MONTH  NUMBER(10) DEFAULT 0            NOT NULL,
  CALC_MONTH    NUMBER(10) DEFAULT 0            NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  REMARK_IS_SHOW NUMBER(1) DEFAULT 0            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_RECONSUME_AUDIT IS '复销变动审核表';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.TYPE IS '类型';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CHANGE_PV IS '变动PV';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CHANGE_MONTH IS '变动月数';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CALC_MONTH IS '扣月复销时的结算月';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CREATE_REMARK IS '申请备注';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.REMARK_IS_SHOW IS '申请备注是否显示';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_RECONSUME_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_R_A_USER_ID_INDEX ON AR_RECONSUME_AUDIT(USER_ID);
CREATE INDEX AR_R_A_TYPE_INDEX ON AR_RECONSUME_AUDIT(TYPE);
CREATE INDEX AR_R_A_AUDIT_STATUS_INDEX ON AR_RECONSUME_AUDIT(AUDIT_STATUS);
CREATE INDEX AR_R_A_REMARK_IS_SHOW ON AR_RECONSUME_AUDIT(REMARK_IS_SHOW);

-- 期业绩表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_PERF_PERIOD';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERF_PERIOD
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  PV_PCS      NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_PCS_ZC   NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_PCS_YH   NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_PCS_ZG   NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_PCS_LS   NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_PCS_FX   NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L       NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_ZC    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_YH    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_ZG    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_LS    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_1L_FX    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L       NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_ZC    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_YH    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_ZG    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_LS    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_2L_FX    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L       NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_ZC    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_YH    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_ZG    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_LS    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_3L_FX    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L       NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_ZC    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_YH    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_ZG    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_LS    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_4L_FX    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L       NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_ZC    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_YH    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_ZG    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_LS    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_5L_FX    NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PV_LS_TOUCH  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_1L  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_2L  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_3L  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_4L  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_5L  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  SURPLUS_LS  NUMBER(16, 3) DEFAULT 0        NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  CALC_MONTH  NUMBER(10)                      NOT NULL,
  P_CALC_MONTH DATE                           NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL
)
PARTITION BY RANGE(P_CALC_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_PERF_PERIOD IS '业绩记录';
COMMENT ON COLUMN AR_PERF_PERIOD.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_PERF_PERIOD.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_PERF_PERIOD.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_PERF_PERIOD.LAST_STATUS IS '结算时会有状态';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS IS '个人消费';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS_ZC IS '个人消费注册单';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS_YH IS '个人消费优惠单';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS_ZG IS '个人消费增购单';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS_LS IS '个人消费零售单';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PCS_FX IS '个人消费复销单';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_1L IS '一市场业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_1L_TOUCH IS '一市场对碰业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_2L IS '二市场业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_2L_TOUCH IS '二市场对碰业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_3L IS '三市场业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_3L_TOUCH IS '三市场对碰业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_4L IS '四市场业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_4L_TOUCH IS '四市场对碰业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_5L IS '五市场业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_5L_TOUCH IS '五市场对碰业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PV_LS_TOUCH IS '隐藏零售区业绩30%后的';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_1L IS '一市场结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_2L IS '二市场结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_3L IS '三市场结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_4L IS '四市场结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_5L IS '五市场结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.SURPLUS_LS  IS '零售隐藏区结余业绩';
COMMENT ON COLUMN AR_PERF_PERIOD.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_PERF_PERIOD.CALC_MONTH IS '结算月YYYYMM';
COMMENT ON COLUMN AR_PERF_PERIOD.P_CALC_MONTH IS '表分区日期索引';
COMMENT ON COLUMN AR_PERF_PERIOD.CREATED_AT IS '创建时间';

CREATE INDEX AR_PERF_P_USER_ID_INDEX ON AR_PERF_PERIOD(USER_ID) LOCAL;
CREATE INDEX AR_PERF_P_PERIOD_NUM_INDEX ON AR_PERF_PERIOD(PERIOD_NUM) LOCAL;
CREATE INDEX AR_PERF_P_CALC_MONTH_INDEX ON AR_PERF_PERIOD(CALC_MONTH) LOCAL;

-- 月度业绩表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_PERF_MONTH';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERF_MONTH
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID         VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  PV_PCS          NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_1L           NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_2L           NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_3L           NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_4L           NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_5L           NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_1L_TOTAL     NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_2L_TOTAL     NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_3L_TOTAL     NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_4L_TOTAL     NUMBER(16, 3) DEFAULT 0         NOT NULL,
  PV_5L_TOTAL     NUMBER(16, 3) DEFAULT 0         NOT NULL,
  CF_PERCENT      NUMBER(10) DEFAULT 0            NOT NULL,
  LX_PERCENT      NUMBER(10) DEFAULT 0            NOT NULL,
  FX_STATUS       NUMBER(1) DEFAULT 0             NOT NULL,
  CALC_MONTH      NUMBER(10)                      NOT NULL,
  P_CALC_MONTH    DATE                            NOT NULL,
  CREATED_AT      NUMBER(10)                      NOT NULL
)
PARTITION BY RANGE(P_CALC_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_PERF_MONTH IS '月业绩记录';
COMMENT ON COLUMN AR_PERF_MONTH.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_PERF_MONTH.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_PERF_MONTH.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_PERF_MONTH.LAST_STATUS IS '结算时会有状态';
COMMENT ON COLUMN AR_PERF_MONTH.PV_PCS IS '个人消费';
COMMENT ON COLUMN AR_PERF_MONTH.PV_1L IS '一市场业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_2L IS '二市场业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_3L IS '三市场业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_4L IS '四市场业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_5L IS '五市场业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_1L_TOTAL IS '一市场历史累计加该月业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_2L_TOTAL IS '二市场历史累计加该月业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_3L_TOTAL IS '三市场历史累计加该月业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_4L_TOTAL IS '四市场历史累计加该月业绩';
COMMENT ON COLUMN AR_PERF_MONTH.PV_5L_TOTAL IS '五市场历史累计加该月业绩';
COMMENT ON COLUMN AR_PERF_MONTH.CF_PERCENT  IS '车房养老奖分工系数';
COMMENT ON COLUMN AR_PERF_MONTH.LX_PERCENT  IS '领袖分红分工系数';
COMMENT ON COLUMN AR_PERF_MONTH.FX_STATUS  IS '本月复销状态作为下月发奖资格';
COMMENT ON COLUMN AR_PERF_MONTH.CALC_MONTH IS '结算月';
COMMENT ON COLUMN AR_PERF_MONTH.P_CALC_MONTH IS '表分区日期索引';
COMMENT ON COLUMN AR_PERF_MONTH.CREATED_AT IS '创建时间';

CREATE INDEX AR_P_M_USER_ID_INDEX ON AR_PERF_MONTH(USER_ID) LOCAL ;
CREATE INDEX AR_P_M_EMP_LEVEL_INDEX ON AR_PERF_MONTH(LAST_EMP_LV) LOCAL ;

-- 公司总业绩
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_PERF_COMPANY';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERF_COMPANY
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  PV          NUMBER(16,3) DEFAULT 0          NOT NULL,
  CALC_YEAR   NUMBER(10)                      NOT NULL,
  CALC_MONTH  NUMBER(10)                      NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_PERF_COMPANY IS '公司总业绩';
COMMENT ON COLUMN AR_PERF_COMPANY.ID IS 'ID';
COMMENT ON COLUMN AR_PERF_COMPANY.PV IS '月总业绩';
COMMENT ON COLUMN AR_PERF_COMPANY.CALC_YEAR IS '结算年';
COMMENT ON COLUMN AR_PERF_COMPANY.CALC_MONTH IS '结算月';
COMMENT ON COLUMN AR_PERF_COMPANY.CREATED_AT IS '创建时间';

CREATE INDEX AR_PERF_C_CALC_YEAR ON AR_PERF_COMPANY(CALC_YEAR);
CREATE INDEX AR_PERF_C_CALC_MONTH ON AR_PERF_COMPANY(CALC_MONTH);

-- 报单级别
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_DECLARATION_LEVEL';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DECLARATION_LEVEL
(
	ID         VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
	LEVEL_NAME VARCHAR2(48)                    NOT NULL,
	PERF       NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	QY_PERCENT NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	QY_TOUCH_CAP NUMBER(16, 2) DEFAULT 0.00    NOT NULL,
	QY_BIG_CAP NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	FX_MIN_DEEP NUMBER(10) DEFAULT 1           NOT NULL,
	FX_MAX_DEEP NUMBER(10) DEFAULT 1           NOT NULL,
	FX_PERCENT NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	IS_ADJUST_GIFT NUMBER(1) DEFAULT 0         NOT NULL,
	IS_DEC     NUMBER(1) DEFAULT 0             NOT NULL,
	SORT       NUMBER(10) DEFAULT 0            NOT NULL,
	CREATE_ADMIN VARCHAR2(32)                  NOT NULL,
	UPDATE_ADMIN VARCHAR2(32),
	UPDATE_PERIOD NUMBER(10,0) DEFAULT 0       NOT NULL,
	ORDER_PERMISSION VARCHAR2(4000) DEFAULT '',
	CREATED_AT NUMBER(10)                      NOT NULL,
	UPDATED_AT NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_DECLARATION_LEVEL IS '报单级别';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.LEVEL_NAME IS '级别名称';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.PERF IS '累计业绩';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.QY_PERCENT IS '区域津贴百分比';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.QY_TOUCH_CAP IS '对碰封顶';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.QY_BIG_CAP IS '大区封顶';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.FX_MIN_DEEP IS '复销奖拿奖最小层数';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.FX_MAX_DEEP IS '复销奖拿奖最大层数';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.FX_PERCENT IS '复销奖百分比';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.IS_ADJUST_GIFT IS '是否可调整礼包';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.IS_DEC IS '是否可以报单';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.SORT IS '级别排序';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_DECLARATION_LEVEL.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_DEC_L_L_NAME_UNINDEX ON AR_DECLARATION_LEVEL(LEVEL_NAME);

--AR_DECLARATION_LEVEL 表字段修改
ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_ONE NUMBER(10) DEFAULT 1 NOT NULL;
COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_ONE IS '共享奖推荐1人拿的代数';
ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_TWO NUMBER(10) DEFAULT 1 NOT NULL;
COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_TWO IS '共享奖推荐2人拿的代数';
ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_THREE NUMBER(10) DEFAULT 1 NOT NULL;
COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_THREE IS '共享奖推荐3人拿的代数';
ALTER TABLE AR_DECLARATION_LEVEL ADD INCOME_CAP NUMBER(16,2) DEFAULT 0.00 NOT NULL;
COMMENT ON COLUMN AR_DECLARATION_LEVEL.INCOME_CAP IS '共享奖推荐3人拿的代数';

-- INSERT INTO AR_DECLARATION_LEVEL("ID", "LEVEL_NAME", "PERF", "QY_PERCENT", "QY_TOUCH_CAP", "QY_BIG_CAP", "FX_MIN_DEEP", "FX_MAX_DEEP", "FX_PERCENT", "IS_ADJUST_GIFT", "IS_DEC", "SORT", "CREATE_ADMIN", "UPDATE_ADMIN", "UPDATE_PERIOD", "ORDER_PERMISSION", "CREATED_AT", "UPDATED_AT") VALUES ('67AB99FDC4B6501CE055736AECE8644D', '普通会员', '600', '8', '4000', '100000', '1', '12', '3', '0', '1', '1', 'admin', 'wangqi', '154', '', '1521357308', '1571879753');
-- INSERT INTO AR_DECLARATION_LEVEL("ID", "LEVEL_NAME", "PERF", "QY_PERCENT", "QY_TOUCH_CAP", "QY_BIG_CAP", "FX_MIN_DEEP", "FX_MAX_DEEP", "FX_PERCENT", "IS_ADJUST_GIFT", "IS_DEC", "SORT", "CREATE_ADMIN", "UPDATE_ADMIN", "UPDATE_PERIOD", "ORDER_PERMISSION", "CREATED_AT", "UPDATED_AT") VALUES ('67ABCB8C1F7D5519E055736AECE8644D', '银卡会员', '3000', '10', '15000', '280000', '1', '13', '3', '1', '1', '2', 'admin', 'adminty', '158', '', '1521358140', '1572317628');
-- INSERT INTO AR_DECLARATION_LEVEL("ID", "LEVEL_NAME", "PERF", "QY_PERCENT", "QY_TOUCH_CAP", "QY_BIG_CAP", "FX_MIN_DEEP", "FX_MAX_DEEP", "FX_PERCENT", "IS_ADJUST_GIFT", "IS_DEC", "SORT", "CREATE_ADMIN", "UPDATE_ADMIN", "UPDATE_PERIOD", "ORDER_PERMISSION", "CREATED_AT", "UPDATED_AT") VALUES ('67ABCCE20A9F5553E055736AECE8644D', '金卡会员', '6000', '12', '30000', '550000', '1', '14', '3', '1', '1', '3', 'admin', NULL, '140', '', '1521358162', '1563504126');
-- INSERT INTO AR_DECLARATION_LEVEL("ID", "LEVEL_NAME", "PERF", "QY_PERCENT", "QY_TOUCH_CAP", "QY_BIG_CAP", "FX_MIN_DEEP", "FX_MAX_DEEP", "FX_PERCENT", "IS_ADJUST_GIFT", "IS_DEC", "SORT", "CREATE_ADMIN", "UPDATE_ADMIN", "UPDATE_PERIOD", "ORDER_PERMISSION", "CREATED_AT", "UPDATED_AT") VALUES ('67ABCE0ECE705575E055736AECE8644D', 'VIP会员', '12000', '16', '80000', '1050000', '1', '17', '3', '1', '1', '4', 'admin', 'wangqi', '158', '', '1521358182', '1572257546');
INSERT INTO AKBONUS.AR_DECLARATION_LEVEL (ID, LEVEL_NAME, PERF, QY_PERCENT, QY_TOUCH_CAP, QY_BIG_CAP, FX_MIN_DEEP, FX_MAX_DEEP, FX_PERCENT, IS_ADJUST_GIFT, IS_DEC, SORT, CREATE_ADMIN, UPDATE_ADMIN, UPDATE_PERIOD, ORDER_PERMISSION, CREATED_AT, UPDATED_AT, GL_ODD_DEEP_ONE, GL_ODD_DEEP_TWO, GL_ODD_DEEP_THREE, INCOME_CAP) VALUES ('67ABCB8C1F7D5519E055736AECE8644D', '银钻会员', 980.00, 2.00, 15000.00, 280000.00, 1, 13, 3.00, 1, 1, 2, 'admin', 'adminx', 158, null, 1521358140, 1581996445, 1, 2, 6, 10000.00);
INSERT INTO AKBONUS.AR_DECLARATION_LEVEL (ID, LEVEL_NAME, PERF, QY_PERCENT, QY_TOUCH_CAP, QY_BIG_CAP, FX_MIN_DEEP, FX_MAX_DEEP, FX_PERCENT, IS_ADJUST_GIFT, IS_DEC, SORT, CREATE_ADMIN, UPDATE_ADMIN, UPDATE_PERIOD, ORDER_PERMISSION, CREATED_AT, UPDATED_AT, GL_ODD_DEEP_ONE, GL_ODD_DEEP_TWO, GL_ODD_DEEP_THREE, INCOME_CAP) VALUES ('67ABCCE20A9F5553E055736AECE8644D', '金钻会员', 2980.00, 2.00, 30000.00, 550000.00, 1, 14, 3.00, 1, 1, 3, 'admin', 'adminx', 140, null, 1521358162, 1581996462, 2, 4, 9, 100000.00);
INSERT INTO AKBONUS.AR_DECLARATION_LEVEL (ID, LEVEL_NAME, PERF, QY_PERCENT, QY_TOUCH_CAP, QY_BIG_CAP, FX_MIN_DEEP, FX_MAX_DEEP, FX_PERCENT, IS_ADJUST_GIFT, IS_DEC, SORT, CREATE_ADMIN, UPDATE_ADMIN, UPDATE_PERIOD, ORDER_PERMISSION, CREATED_AT, UPDATED_AT, GL_ODD_DEEP_ONE, GL_ODD_DEEP_TWO, GL_ODD_DEEP_THREE, INCOME_CAP) VALUES ('67ABCE0ECE705575E055736AECE8644D', 'VIP会员', 9800.00, 2.00, 80000.00, 1050000.00, 1, 17, 3.00, 1, 1, 4, 'admin', 'adminx', 158, null, 1521358182, 1581996473, 3, 6, 12, 200000.00);
COMMIT;

-- 聘级
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_EMPLOY_LEVEL';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EMPLOY_LEVEL
(
	ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
	LEVEL_NAME  VARCHAR2(48)                    NOT NULL,
	LOCATION_NUM NUMBER(10) DEFAULT 0           NOT NULL,
	LOCATION_PERF NUMBER(16, 2) DEFAULT 0.00    NOT NULL,
	NEW_PERF    NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	MIN_EMPLOY_LEVEL VARCHAR2(32) ,
	YC_PERCENT_ARR  VARCHAR2(4000),
	CF_BASE_NUM NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	CF_PERCENT  NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	LX_BASE_NUM NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	LX_PERCENT  NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
	SORT        NUMBER(10)  DEFAULT 0           NOT NULL,
	CREATED_AT  NUMBER(10)                      NOT NULL,
	UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
	CREATE_ADMIN VARCHAR2(32)                   NOT NULL,
	UPDATE_ADMIN VARCHAR2(32),
	ICON_TYPE  	NUMBER(1) DEFAULT 0             NOT NULL,
	ICON_NUM  	NUMBER(2) DEFAULT 0             NOT NULL
);
COMMENT ON TABLE AR_EMPLOY_LEVEL IS '聘级';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.LEVEL_NAME IS '级别名称';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.LOCATION_NUM IS '区数量';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.LOCATION_PERF IS '单区业绩';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.NEW_PERF IS '新增业绩';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.MIN_EMPLOY_LEVEL IS '几个区域内分别有几个最低什么聘级的会员';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.YC_PERCENT_ARR IS '育成津贴比例集合';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.CF_BASE_NUM IS '车房奖基数';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.CF_PERCENT IS '车房奖系数';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.LX_BASE_NUM IS '领袖奖奖基数';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.LX_PERCENT IS '领袖奖系数';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.SORT IS '排序';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.ICON_TYPE IS '图表类型';
COMMENT ON COLUMN AR_EMPLOY_LEVEL.ICON_NUM IS '图标个数';

CREATE UNIQUE INDEX AR_E_L_LEVEL_NAME_UNINDEX ON AR_EMPLOY_LEVEL(LEVEL_NAME);

ALTER TABLE AR_EMPLOY_LEVEL ADD RX_PERCENT NUMBER(16,2) DEFAULT 0.00 NOT NULL;
COMMENT ON COLUMN AR_EMPLOY_LEVEL.RX_PERCENT IS '荣衔奖比例';
ALTER TABLE AR_EMPLOY_LEVEL ADD OTHER_DEPART_PERF NUMBER(16,2) DEFAULT 0.00 NOT NULL;
COMMENT ON COLUMN AR_EMPLOY_LEVEL.OTHER_DEPART_PERF IS '去除最大部门，其它部门的累计推荐业绩';
ALTER TABLE AR_EMPLOY_LEVEL ADD MIN_EMPLOY_NUM NUMBER(10) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_EMPLOY_LEVEL.MIN_EMPLOY_NUM IS '最小聘级的数量';

-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE1C6C21F81B32E055736AECE8644D', '无聘级', '0', '0', '0', NULL, '[0,0,0,0,0,0,0,0,0,0]', '0', '0', '0', '0', '0', '1521436806', '1547104919', 'admin', NULL, '0', '0');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE5FE7857C216AE055736AECE8644D', '高级经理', '2', '70000', '0', NULL, '[0,0,0,0,0,0,0,0,0,0]', '0', '0', '0', '0', '1', '1521437938', '1548221354', 'admin', NULL, '1', '1');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE6A4D03C52288E055736AECE8644D', '合格高级经理', '2', '70000', '14000', NULL, '[0,0,0,0,0,0,0,0,0,0]', '0', '0', '0', '0', '2', '1521438113', '1547103900', 'admin', NULL, '1', '2');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE6EA2070D22EBE055736AECE8644D', '一钻经理', '1', '70000', '14000', '67BE6A4D03C52288E055736AECE8644D', '["10",0,0,0,0,0,0,0,0,0]', '0', '0', '0', '0', '3', '1521438185', '1547104065', 'admin', NULL, '2', '1');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE742A336F2370E055736AECE8644D', '二钻经理', '2', '0', '0', '67BE6A4D03C52288E055736AECE8644D', '["10","10",0,0,0,0,0,0,0,0]', '0', '0', '0', '0', '4', '1521438278', '1547104073', 'admin', NULL, '2', '2');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE805032C22492E055736AECE8644D', '三钻经理', '3', '0', '0', '67BE6A4D03C52288E055736AECE8644D', '["10","10","10",0,0,0,0,0,0,0]', '0', '0', '0', '0', '5', '1521438482', '1547104081', 'admin', NULL, '2', '3');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE82019BE524CAE055736AECE8644D', '四钻经理', '3', '0', '0', '67BE6EA2070D22EBE055736AECE8644D', '["10","10","10","5",0,0,0,0,0,0]', '0', '0', '0', '0', '6', '1521438510', '1547104088', 'admin', NULL, '2', '4');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE84991AF22509E055736AECE8644D', '五钻经理', '3', '0', '0', '67BE742A336F2370E055736AECE8644D', '["10","10","10","5","5",0,0,0,0,0]', '1', '1', '1', '1', '7', '1521438554', '1547104095', 'admin', NULL, '2', '5');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE866A22C6252FE055736AECE8644D', '六钻经理', '3', '0', '0', '67BE84991AF22509E055736AECE8644D', '["10","10","10","5","5","5",0,0,0,0]', '2', '3', '2', '3', '8', '1521438584', '1547104102', 'admin', NULL, '2', '6');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE88C8F55F2582E055736AECE8644D', '七钻经理', '3', '0', '0', '67BE866A22C6252FE055736AECE8644D', '["10","10","10","5","5","5","5",0,0,0]', '3', '6', '3', '6', '9', '1521438624', '1547104110', 'admin', NULL, '2', '7');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE8A92393225B1E055736AECE8644D', '七星董事', '3', '0', '0', '67BE88C8F55F2582E055736AECE8644D', '["10","10","10","5","5","5","5","5",0,0]', '4', '10', '4', '10', '10', '1521438654', '1547111868', 'admin', NULL, '3', '1');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE8BF76AD925E5E055736AECE8644D', '六星董事', '3', '0', '0', '67BE8A92393225B1E055736AECE8644D', '["10","10","10","5","5","5","5","5","5",0]', '5', '15', '5', '15', '11', '1521438677', '1547104142', 'admin', NULL, '3', '2');
-- INSERT INTO "AR_EMPLOY_LEVEL"("ID", "LEVEL_NAME", "LOCATION_NUM", "LOCATION_PERF", "NEW_PERF", "MIN_EMPLOY_LEVEL", "YC_PERCENT_ARR", "CF_BASE_NUM", "CF_PERCENT", "LX_BASE_NUM", "LX_PERCENT", "SORT", "CREATED_AT", "UPDATED_AT", "CREATE_ADMIN", "UPDATE_ADMIN", "ICON_TYPE", "ICON_NUM") VALUES ('67BE8E20BE1A260FE055736AECE8644D', '三星董事', '3', '0', '0', '67BE8BF76AD925E5E055736AECE8644D', '["10","10","10","5","5","5","5","5","5","5"]', '6', '21', '6', '21', '12', '1521438714', '1547104149', 'admin', NULL, '3', '3');
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE1C6C21F81B32E055736AECE8644D', '无聘级', 0, 0.00, 0.00, null, '[0,0,0,0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 0, 1521436806, 1547104919, 'admin', null, 0, 0, 0.00, 0.00, 0);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE5FE7857C216AE055736AECE8644D', '主任', 0, 70000.00, 0.00, null, '[0,0,0,0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 1, 1521437938, 1548221354, 'admin', null, 1, 1, 2.00, 500000.00, 0);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE6A4D03C52288E055736AECE8644D', '经理', 2, 70000.00, 14000.00, '67BE5FE7857C216AE055736AECE8644D', '[0,0,0,0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 2, 1521438113, 1581997760, 'admin', 'adminx', 2, 1, 3.00, 0.00, 1);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE6EA2070D22EBE055736AECE8644D', '高级经理', 2, 70000.00, 14000.00, '67BE6A4D03C52288E055736AECE8644D', '["10",0,0,0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 3, 1521438185, 1581997773, 'admin', 'adminx', 2, 2, 4.00, 0.00, 1);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE742A336F2370E055736AECE8644D', '总监', 3, 0.00, 0.00, '67BE6EA2070D22EBE055736AECE8644D', '["10","10",0,0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 4, 1521438278, 1581997787, 'admin', 'adminx', 3, 1, 4.50, 0.00, 1);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE805032C22492E055736AECE8644D', '高级总监', 3, 0.00, 0.00, '67BE742A336F2370E055736AECE8644D', '["10","10","10",0,0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 5, 1521438482, 1581997806, 'admin', 'adminx', 3, 2, 5.00, 0.00, 1);
INSERT INTO AKBONUS.AR_EMPLOY_LEVEL (ID, LEVEL_NAME, LOCATION_NUM, LOCATION_PERF, NEW_PERF, MIN_EMPLOY_LEVEL, YC_PERCENT_ARR, CF_BASE_NUM, CF_PERCENT, LX_BASE_NUM, LX_PERCENT, SORT, CREATED_AT, UPDATED_AT, CREATE_ADMIN, UPDATE_ADMIN, ICON_TYPE, ICON_NUM, RX_PERCENT, OTHER_DEPART_PERF, MIN_EMPLOY_NUM) VALUES ('67BE82019BE524CAE055736AECE8644D', '首席总监', 3, 0.00, 0.00, '67BE742A336F2370E055736AECE8644D', '["10","10","10","5",0,0,0,0,0,0]', 0.00, 0.00, 0.00, 0.00, 6, 1521438510, 1581997817, 'admin', 'adminx', 3, 3, 0.00, 0.00, 2);

COMMIT;

-- 报单中心级别表
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_DEC_ROLE';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DEC_ROLE
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    ROLE_NAME VARCHAR2(255) NOT NULL,
    ORDER_PERMISSION VARCHAR2(4000) NOT NULL,
    STORE_SUBSIDY NUMBER(16,2) NOT NULL,
    GOODS_SUBSIDY NUMBER(16,2) NOT NULL,
    CREATED_AT NUMBER(10) NOT NULL,
    UPDATED_AT NUMBER(10) NOT NULL,
    UPDATER VARCHAR2(16),
    ADM_NAME VARCHAR2(16) NOT NULL,
    GOODS_TO_USER_PROP NUMBER(16,2) NOT NULL,
    D_STORE_PERF_PROP NUMBER(16,2) NOT NULL,
    FLOW_SUBSIDY_PROP NUMBER(10,2),
    NEED_SET_AREA NUMBER(1) NOT NULL,
    UPDATE_PERIOD NUMBER(10) NOT NULL,
    CREATE_ORDER_FORM NUMBER(1) NOT NULL
);

CREATE UNIQUE INDEX AR_D_R_ROLE_NAME_UNINDEX ON AR_DEC_ROLE(ROLE_NAME);

INSERT INTO AR_DEC_ROLE (ID, ROLE_NAME, ORDER_PERMISSION, STORE_SUBSIDY, GOODS_SUBSIDY, CREATED_AT, UPDATED_AT, UPDATER, ADM_NAME, GOODS_TO_USER_PROP, D_STORE_PERF_PROP, FLOW_SUBSIDY_PROP, NEED_SET_AREA, UPDATE_PERIOD, CREATE_ORDER_FORM) VALUES ('8976C62F40064D8AB357BE07C8A3CA8F', '店铺', '["ZC","ZG","LS","FX","DH"]', 4.00, 0.00, 1534748970, 1571380687, 'ADMINZ', 'ADMIN', 2.00, 0.00, 2.00, 1, 153, 1);
INSERT INTO AR_DEC_ROLE (ID, ROLE_NAME, ORDER_PERMISSION, STORE_SUBSIDY, GOODS_SUBSIDY, CREATED_AT, UPDATED_AT, UPDATER, ADM_NAME, GOODS_TO_USER_PROP, D_STORE_PERF_PROP, FLOW_SUBSIDY_PROP, NEED_SET_AREA, UPDATE_PERIOD, CREATE_ORDER_FORM) VALUES ('466CB7E1F32349C196B88ECBDE51C059', '形象店', '["ZC","ZG","FX","LS","DH"]', 4.00, 3.00, 1534749202, 1571380500, 'ADMINZ', 'ADMIN', 2.00, 0.00, 2.00, 1, 153, 1);
INSERT INTO AR_DEC_ROLE (ID, ROLE_NAME, ORDER_PERMISSION, STORE_SUBSIDY, GOODS_SUBSIDY, CREATED_AT, UPDATED_AT, UPDATER, ADM_NAME, GOODS_TO_USER_PROP, D_STORE_PERF_PROP, FLOW_SUBSIDY_PROP, NEED_SET_AREA, UPDATE_PERIOD, CREATE_ORDER_FORM) VALUES ('16B96B8D910E44EA86C89CC80F6BC76C', '报单中心', '["ZC","ZG","LS","FX","DH"]', 0.00, 0.00, 1534749214, 1571380490, 'ADMINZ', 'ADMIN', 0.00, 0.00, 0.00, 1, 153, 0);
INSERT INTO AR_DEC_ROLE (ID, ROLE_NAME, ORDER_PERMISSION, STORE_SUBSIDY, GOODS_SUBSIDY, CREATED_AT, UPDATED_AT, UPDATER, ADM_NAME, GOODS_TO_USER_PROP, D_STORE_PERF_PROP, FLOW_SUBSIDY_PROP, NEED_SET_AREA, UPDATE_PERIOD, CREATE_ORDER_FORM) VALUES ('85B65542FCC341FAAFFAD0FA625CF9B8', '服务点', '["ZC","ZG","LS","FX","DH"]', 2.00, 0.00, 1534749225, 1571380719, 'ADMINZ', 'ADMIN', 2.00, 0.00, 1.00, 1, 153, 1);
INSERT INTO AR_DEC_ROLE (ID, ROLE_NAME, ORDER_PERMISSION, STORE_SUBSIDY, GOODS_SUBSIDY, CREATED_AT, UPDATED_AT, UPDATER, ADM_NAME, GOODS_TO_USER_PROP, D_STORE_PERF_PROP, FLOW_SUBSIDY_PROP, NEED_SET_AREA, UPDATE_PERIOD, CREATE_ORDER_FORM) VALUES ('810916A06B304162902408A6B9E5D177', '区级店', '["ZC","ZG","LS","FX","DH"]', 4.00, 0.00, 1534749236, 1571380696, 'ADMINZ', 'ADMIN', 2.00, 1.00, 2.00, 1, 153, 1);

COMMIT;

-- 银行表
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_OPEN_BANK';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_OPEN_BANK
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    BANK_NAME VARCHAR2(64) NOT NULL,
    BANK_CODE VARCHAR2(32) NOT NULL,
    LIST_ORDER NUMBER(5) DEFAULT 0 NOT NULL,
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    ADM_NAME VARCHAR2(16) NOT NULL,
    MIN_CHARGE NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    MAX_CHARGE NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    CHARGE_PROP NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    UPDATER VARCHAR2(16) DEFAULT '',
    STATUS NUMBER(1) DEFAULT 1 NOT NULL
);
COMMENT ON TABLE AR_OPEN_BANK IS '开户行';
COMMENT ON COLUMN AR_OPEN_BANK.BANK_NAME IS '银行名称';
COMMENT ON COLUMN AR_OPEN_BANK.BANK_CODE IS '银行代码';
COMMENT ON COLUMN AR_OPEN_BANK.LIST_ORDER IS '排序';
COMMENT ON COLUMN AR_OPEN_BANK.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_OPEN_BANK.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_OPEN_BANK.ADM_NAME IS '操作人';
COMMENT ON COLUMN AR_OPEN_BANK.MIN_CHARGE IS '最低手续费';
COMMENT ON COLUMN AR_OPEN_BANK.MAX_CHARGE IS '最高手续费';
COMMENT ON COLUMN AR_OPEN_BANK.CHARGE_PROP IS '手续费比例';
COMMENT ON COLUMN AR_OPEN_BANK.UPDATER IS '修改人';
COMMENT ON COLUMN AR_OPEN_BANK.STATUS IS '状态';
CREATE UNIQUE INDEX AR_OPEN_BANK_CODE ON AR_OPEN_BANK (BANK_CODE);

INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('960B4D9367C776B7E053693418ACFCC1', '中国银行', '4566999', 0, 1572345878, 1573182295, 'ADMIN', 0.00, 0.00, 0.00, 'LIMIN', 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('960B6BDE22667B67E053693418ACF2B7', '招商银行', '789666', 0, 1572346386, 0, 'ADMIN', 0.00, 0.00, 0.00, NULL, 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('960B4CAB7C07769CE053693418ACF6F7', '农业银行', '123456', 0, 1572345863, 0, 'ADMIN', 0.00, 0.00, 0.00, NULL, 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('960B6924E1527B02E053693418AC2B0A', '民生银行', '456789', 0, 1572346341, 0, 'ADMIN', 0.00, 0.00, 0.00, NULL, 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('95A71AF5E4D55466E053693418ACED88', '123', '11111111', 0, 1571915532, 1572345780, 'CN0006', 0.00, 0.00, 0.00, 'ADMIN', 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('960B7BDF35E67F01E053693418AC3102', '上海银行', '88585585', 0, 1572346655, 0, 'ADMIN', 0.00, 0.00, 0.00, NULL, 1);
INSERT INTO AR_OPEN_BANK (ID, BANK_NAME, BANK_CODE, LIST_ORDER, CREATED_AT, UPDATED_AT, ADM_NAME, MIN_CHARGE, MAX_CHARGE, CHARGE_PROP, UPDATER, STATUS) VALUES ('9632D2ECCB120E33E053693418AC891C', '建设银行', '11111112', 0, 1572515619, 0, 'ADMINZ', 0.00, 0.00, 0.00, NULL, 1);

COMMIT;

-- 会员表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL CONSTRAINT AR_USER_ID_PK PRIMARY KEY,
    USER_NAME VARCHAR2(16) NOT NULL,
    PASSWORD_HASH VARCHAR2(255) NOT NULL,
    PAY_PASSWORD VARCHAR2(255) NOT NULL,
    NATION NUMBER(2) DEFAULT 0 NOT NULL,
    REAL_NAME VARCHAR2(128) NOT NULL,
    ID_CARD VARCHAR2(18) NOT NULL,
    ID_TYPE NUMBER(1) DEFAULT 0 NOT NULL,
    MOBILE VARCHAR2(11) DEFAULT '',
    ADDRESS VARCHAR2(2000) DEFAULT '',
    ID_IMAGE VARCHAR2(255) DEFAULT '',
    OPEN_BANK VARCHAR2(32) DEFAULT '',
    BANK_ADDRESS VARCHAR2(255) DEFAULT '',
    BANK_NO VARCHAR2(32) DEFAULT '',
    BANK_PROVINCE NUMBER(6) DEFAULT 0,
    BANK_CITY NUMBER(6) DEFAULT 0,
    BANK_COUNTY NUMBER(6) DEFAULT 0,
    SPOUSE_NAME VARCHAR2(16) DEFAULT '',
    SPOUSE_IDCARD VARCHAR2(18) DEFAULT '',
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    STATUS NUMBER(1) DEFAULT 1 NOT NULL,
    DEC_CLOSED NUMBER(1) DEFAULT 0 NOT NULL,
    DEC_CLOSED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_LV VARCHAR2(32) DEFAULT '',
    EMP_LV VARCHAR2(32) DEFAULT '',
    PROVINCE NUMBER(6) DEFAULT 0 NOT NULL,
    CITY NUMBER(6) DEFAULT 0 NOT NULL,
    COUNTY NUMBER(6) DEFAULT 0 NOT NULL,
    TEL VARCHAR2(16) DEFAULT '',
    LOGIN_TIMES NUMBER(10) DEFAULT 0 NOT NULL,
    LOGIN_IP VARCHAR2(15) DEFAULT '',
    LOGIN_AT NUMBER(10) DEFAULT 0 NOT NULL,
    PULL_MESSAGE_AT NUMBER(10) DEFAULT 0 NOT NULL,
    SUB_COM_ID VARCHAR2(32) DEFAULT '',
    AVATAR VARCHAR2(255) NOT NULL,
    DELETED NUMBER(1) DEFAULT 0 NOT NULL,
    DELETED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    ALLOW_TRANSFER NUMBER(1) DEFAULT 1 NOT NULL,
    TRANSFER_PROP NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    PARTITION_DATE DATE DEFAULT SYSDATE NOT NULL,
    IS_DEC NUMBER(1) DEFAULT 0 NOT NULL,
    DEC_ID VARCHAR2(32) DEFAULT 1 NOT NULL,
    BIRTHDAY DATE DEFAULT '',
    DEC_ROLE_ID VARCHAR2(32) DEFAULT '',
    PERIOD_AT NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_PROVINCE NUMBER(6) DEFAULT 0 NOT NULL,
    DEC_CITY NUMBER(6) DEFAULT 0 NOT NULL,
    DEC_COUNTY NUMBER(6) DEFAULT 0 NOT NULL,
    IS_UNION NUMBER(1) DEFAULT 0 NOT NULL,
    STATUS_AT NUMBER(10) DEFAULT 0 NOT NULL,
    VERIFIED NUMBER(1) DEFAULT 0 NOT NULL,
    VERIFIED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    ALLOW_LOGIN NUMBER(1) DEFAULT 1 NOT NULL,
    NOT_OPERATING NUMBER(1) DEFAULT 0 NOT NULL,
    REG_FROM NUMBER(1) DEFAULT 1 NOT NULL,
    ID_CARD_PREFIX VARCHAR2(32) DEFAULT '',
    ALLOW_BONUS_LOGIN NUMBER(1) DEFAULT 1 NOT NULL,
    SEX VARCHAR2(32) DEFAULT '',
    DEC_ACCOUNT_OLD VARCHAR2(64) DEFAULT '',
    BANK_UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    IS_DIRECT_SELLER NUMBER(1) DEFAULT 0 NOT NULL,
    DEC_LV_UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_LV_UPDATED_PERIOD NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_ADDRESS VARCHAR2(2000) DEFAULT '',
    DEC_PHONE VARCHAR2(32) DEFAULT '',
    GUARANTOR VARCHAR2(32) DEFAULT '',
    GUARANTOR_NAME VARCHAR2(64) DEFAULT '',
    PART_FUNC_CLOSED NUMBER(1) DEFAULT 0 NOT NULL,
    LAST_DEC_LV_UPDATED_PERIOD NUMBER(10) DEFAULT 0 NOT NULL,
    USER_CREATOR VARCHAR2(32) DEFAULT '',
    USER_UPDATER VARCHAR2(32) DEFAULT '',
    LAST_DEC_LV_UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    PART_FUNC_CLOSED_REMARK VARCHAR2(4000) DEFAULT '',
    DEC_CREATED_PERIOD NUMBER(10) DEFAULT 0 NOT NULL,
    PASSWORD_CHANGED NUMBER(1) DEFAULT 0 NOT NULL,
    SUB_COM_LEADER NUMBER(1) DEFAULT 0 NOT NULL,
    LOGIN_FAIL_TIMES NUMBER(10) DEFAULT 0 NOT NULL,
    ZG_UPGRADE_PV NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    APP_CLIENT_ID VARCHAR2(128) DEFAULT '',
    READ_AGREEMENT NUMBER(1) DEFAULT 1 NOT NULL,
    LAST_DEC_LV VARCHAR2(32) DEFAULT '',
    BONUS_APP_CLIENT_ID VARCHAR2(128) DEFAULT '',
    IS_FIRST_OPEN NUMBER(1) DEFAULT 1
);
COMMENT ON TABLE AR_USER IS '用户';
COMMENT ON COLUMN AR_USER.USER_NAME IS '帐号';
COMMENT ON COLUMN AR_USER.PASSWORD_HASH IS '登录密码';
COMMENT ON COLUMN AR_USER.PAY_PASSWORD IS '支付密码';
COMMENT ON COLUMN AR_USER.NATION IS '民族';
COMMENT ON COLUMN AR_USER.REAL_NAME IS '姓名';
COMMENT ON COLUMN AR_USER.ID_CARD IS '身份证号';
COMMENT ON COLUMN AR_USER.ID_TYPE IS '证件类型';
COMMENT ON COLUMN AR_USER.MOBILE IS '手机号';
COMMENT ON COLUMN AR_USER.ADDRESS IS '身份证地址';
COMMENT ON COLUMN AR_USER.ID_IMAGE IS '证件图片';
COMMENT ON COLUMN AR_USER.OPEN_BANK IS '开户行';
COMMENT ON COLUMN AR_USER.BANK_ADDRESS IS '银行地址';
COMMENT ON COLUMN AR_USER.BANK_NO IS '银行卡号';
COMMENT ON COLUMN AR_USER.BANK_PROVINCE IS '银行省份';
COMMENT ON COLUMN AR_USER.BANK_CITY IS '银行城市';
COMMENT ON COLUMN AR_USER.BANK_COUNTY IS '银行县区';
COMMENT ON COLUMN AR_USER.SPOUSE_NAME IS '配偶姓名';
COMMENT ON COLUMN AR_USER.SPOUSE_IDCARD IS '配偶证件号';
COMMENT ON COLUMN AR_USER.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_USER.STATUS IS '状态';
COMMENT ON COLUMN AR_USER.DEC_CLOSED IS '是否关闭报单功能';
COMMENT ON COLUMN AR_USER.DEC_CLOSED_AT IS '关闭时间';
COMMENT ON COLUMN AR_USER.DEC_LV IS '报单级别';
COMMENT ON COLUMN AR_USER.EMP_LV IS '聘级';
COMMENT ON COLUMN AR_USER.PROVINCE IS '省份';
COMMENT ON COLUMN AR_USER.CITY IS '城市';
COMMENT ON COLUMN AR_USER.COUNTY IS '县区';
COMMENT ON COLUMN AR_USER.TEL IS '座机';
COMMENT ON COLUMN AR_USER.LOGIN_TIMES IS '登录次数';
COMMENT ON COLUMN AR_USER.LOGIN_IP IS '登录IP';
COMMENT ON COLUMN AR_USER.LOGIN_AT IS '登录时间';
COMMENT ON COLUMN AR_USER.PULL_MESSAGE_AT IS '拉取消息的时间';
COMMENT ON COLUMN AR_USER.SUB_COM_ID IS '子公司ID';
COMMENT ON COLUMN AR_USER.AVATAR IS '头像';
COMMENT ON COLUMN AR_USER.DELETED IS '是否删除';
COMMENT ON COLUMN AR_USER.DELETED_AT IS '删除时间';
COMMENT ON COLUMN AR_USER.ALLOW_TRANSFER IS '开启转帐功能';
COMMENT ON COLUMN AR_USER.TRANSFER_PROP IS '转帐比例';
COMMENT ON COLUMN AR_USER.PARTITION_DATE IS '分区时间';
COMMENT ON COLUMN AR_USER.IS_DEC IS '是否为报单中心';
COMMENT ON COLUMN AR_USER.DEC_ID IS '报单中心ID';
COMMENT ON COLUMN AR_USER.BIRTHDAY IS '生日';
COMMENT ON COLUMN AR_USER.DEC_ROLE_ID IS '报单中心级别';
COMMENT ON COLUMN AR_USER.PERIOD_AT IS '期数';
COMMENT ON COLUMN AR_USER.DEC_PROVINCE IS '报单中心所属的省份';
COMMENT ON COLUMN AR_USER.DEC_CITY IS '报单中心所属的城市';
COMMENT ON COLUMN AR_USER.DEC_COUNTY IS '报单中心所属的县区';
COMMENT ON COLUMN AR_USER.IS_UNION IS '是否为点位合作';
COMMENT ON COLUMN AR_USER.STATUS_AT IS '状态更改时间';
COMMENT ON COLUMN AR_USER.VERIFIED IS '是否认证';
COMMENT ON COLUMN AR_USER.VERIFIED_AT IS '认证时间';
COMMENT ON COLUMN AR_USER.ALLOW_LOGIN IS '允许登录';
COMMENT ON COLUMN AR_USER.NOT_OPERATING IS '不运作';
COMMENT ON COLUMN AR_USER.REG_FROM IS '注册类型';
COMMENT ON COLUMN AR_USER.ID_CARD_PREFIX IS '身份证前缀';
COMMENT ON COLUMN AR_USER.ALLOW_BONUS_LOGIN IS '允许结算登录';
COMMENT ON COLUMN AR_USER.SEX IS '性别';
COMMENT ON COLUMN AR_USER.DEC_ACCOUNT_OLD IS '老系统中的报单中心编号';
COMMENT ON COLUMN AR_USER.BANK_UPDATED_AT IS '银行信息更新时间';
COMMENT ON COLUMN AR_USER.IS_DIRECT_SELLER IS '是否为直销员';
COMMENT ON COLUMN AR_USER.DEC_LV_UPDATED_AT IS '报单级别更新时间';
COMMENT ON COLUMN AR_USER.DEC_LV_UPDATED_PERIOD IS '报单级别更新期数';
COMMENT ON COLUMN AR_USER.DEC_ADDRESS IS '报单中心详细地址';
COMMENT ON COLUMN AR_USER.DEC_PHONE IS '报单中心电话';
COMMENT ON COLUMN AR_USER.GUARANTOR IS '担保人编号';
COMMENT ON COLUMN AR_USER.GUARANTOR_NAME IS '担保人姓名';
COMMENT ON COLUMN AR_USER.PART_FUNC_CLOSED IS '部分功能开启';
COMMENT ON COLUMN AR_USER.LAST_DEC_LV_UPDATED_PERIOD IS '上次报单级别更新期数';
COMMENT ON COLUMN AR_USER.USER_CREATOR IS '创建人';
COMMENT ON COLUMN AR_USER.USER_UPDATER IS '修改人';
COMMENT ON COLUMN AR_USER.LAST_DEC_LV_UPDATED_AT IS '上次报单级别更新时间';
COMMENT ON COLUMN AR_USER.DEC_CREATED_AT IS '成为报单中心时间';
COMMENT ON COLUMN AR_USER.PART_FUNC_CLOSED_REMARK IS '部分功能关闭原因';
COMMENT ON COLUMN AR_USER.DEC_CREATED_PERIOD IS '成为报单中心期数';
COMMENT ON COLUMN AR_USER.PASSWORD_CHANGED IS '是否修改过密码';
COMMENT ON COLUMN AR_USER.SUB_COM_LEADER IS '是否为分公司领导';
COMMENT ON COLUMN AR_USER.LOGIN_FAIL_TIMES IS '登录失败次数';
COMMENT ON COLUMN AR_USER.ZG_UPGRADE_PV IS '增购升级PV';
COMMENT ON COLUMN AR_USER.APP_CLIENT_ID IS 'APP设备ID';
COMMENT ON COLUMN AR_USER.READ_AGREEMENT IS '已读协议';
COMMENT ON COLUMN AR_USER.LAST_DEC_LV IS '上次的报单级别';
COMMENT ON COLUMN AR_USER.BONUS_APP_CLIENT_ID IS '结算APP设备ID';
COMMENT ON COLUMN AR_USER.IS_FIRST_OPEN IS '首次开通';
CREATE UNIQUE INDEX AR_AR_USER_NAME_UIN ON AR_USER (USER_NAME);

INSERT INTO AR_USER (ID, USER_NAME, PASSWORD_HASH, PAY_PASSWORD, NATION, REAL_NAME, ID_CARD, ID_TYPE, MOBILE, ADDRESS, ID_IMAGE, OPEN_BANK, BANK_ADDRESS, BANK_NO, BANK_PROVINCE, BANK_CITY, BANK_COUNTY, SPOUSE_NAME, SPOUSE_IDCARD, CREATED_AT, UPDATED_AT, STATUS, DEC_CLOSED, DEC_CLOSED_AT, DEC_LV, EMP_LV, PROVINCE, CITY, COUNTY, TEL, LOGIN_TIMES, LOGIN_IP, LOGIN_AT, PULL_MESSAGE_AT, SUB_COM_ID, AVATAR, DELETED, DELETED_AT, ALLOW_TRANSFER, TRANSFER_PROP, PARTITION_DATE, IS_DEC, DEC_ID, BIRTHDAY, DEC_ROLE_ID, PERIOD_AT, DEC_PROVINCE, DEC_CITY, DEC_COUNTY, IS_UNION, STATUS_AT, VERIFIED, VERIFIED_AT, ALLOW_LOGIN, NOT_OPERATING, REG_FROM, ID_CARD_PREFIX, ALLOW_BONUS_LOGIN, SEX, DEC_ACCOUNT_OLD, BANK_UPDATED_AT, IS_DIRECT_SELLER, DEC_LV_UPDATED_AT, DEC_LV_UPDATED_PERIOD, DEC_ADDRESS, DEC_PHONE, GUARANTOR, GUARANTOR_NAME, PART_FUNC_CLOSED, LAST_DEC_LV_UPDATED_PERIOD, USER_CREATOR, USER_UPDATER, LAST_DEC_LV_UPDATED_AT, DEC_CREATED_AT, PART_FUNC_CLOSED_REMARK, DEC_CREATED_PERIOD, PASSWORD_CHANGED, SUB_COM_LEADER, LOGIN_FAIL_TIMES, ZG_UPGRADE_PV, APP_CLIENT_ID, READ_AGREEMENT, LAST_DEC_LV, BONUS_APP_CLIENT_ID, IS_FIRST_OPEN) VALUES ('670B84FD7C216D4EE055736AECE8644D', 'tester001', '$2y$10$26RZqjbcKbKmeLn5JZtqYON2CBCiGT76TX2cxyjT10eNjZ7CZBfTW', '$2y$10$P1m//xxOA1JP4aJ.7ZfqVe8de8Of1XJDnGBn3OfPVB.vUGcJX4OxS', 1, '新周静', '32038119770810152X', 0, '13333333333', '秦皇岛市东山街1000001号', 'http://upload.ar.wqcms.com/files/2018/0606/e0013022694b11e8b1af10ddb1d0e3fd', '0010000', '鸽子窝110号', '6222222222222220131', 130000, 130300, 130304, '瞬瞬', '130324198808081235', 1528770496, 1575450033, 1, 0, 0, '67ABCE0ECE705575E055736AECE8644D', '67BE1C6C21F81B32E055736AECE8644D', 110000, 110100, 110101, '13826545212', 2659, '106.118.113.61', 1578879390, 0, '953BF18AE3694BC4E053693418ACAC98', 'http://upload.ar.wqcms.com/cdn/avatar/1.png', 0, 0, 1, 1.01, TO_DATE('2018-06-12 10:28:19', 'YYYY-MM-DD HH24:MI:SS'), 1, '670B84FD7C216D4EE055736AECE8644D', TO_DATE('1977-08-10 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), '810916A06B304162902408A6B9E5D177', 117, 130000, 130200, 130203, 0, 1565921409, 1, 1571797394, 1, 0, 0, null, 1, '女', null, 0, 0, 1573003331, 158, '123', '15098156582', null, null, 0, 0, 'adminty', 'adminty', 0, 1572337842, '报单中心货款/会员货款余额15132.00,600010.00高于参数"100.00"关闭', 158, 3, 0, 5, 12000.00, null, 1, null, null, 1);

COMMIT;

-- 结算系统用到的会员其他资料
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_INFO';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_INFO
(
  USER_ID     VARCHAR2(32)                    NOT NULL PRIMARY KEY,
  USER_NAME   VARCHAR2(16)                    NOT NULL,
  ZC_PV       NUMBER(16,3) DEFAULT 0          NOT NULL,
  CON_UID     VARCHAR2(32)                    NOT NULL,
  REC_UID     VARCHAR2(32)                    NOT NULL,
  CON_NUM     NUMBER(10) DEFAULT 0            NOT NULL,
  REC_NUM     NUMBER(10) DEFAULT 0            NOT NULL,
  NETWORK_DEEP    NUMBER(10) DEFAULT 0        NOT NULL,
  RELATION_DEEP   NUMBER(10) DEFAULT 0        NOT NULL,
  SYSTEM_ID   VARCHAR2(32) ,
  IS_GROUP_LEADER  NUMBER(1) DEFAULT 0        NOT NULL,
  IS_SYSTEM_LEADER  NUMBER(1) DEFAULT 0       NOT NULL,
  IS_TEAM     NUMBER(1) DEFAULT 0             NOT NULL,
  IS_BIND     NUMBER(1) DEFAULT 0             NOT NULL,
  IS_TEAM_MAIN NUMBER(1) DEFAULT 0            NOT NULL,
  IS_BIND_MAIN NUMBER(1) DEFAULT 0            NOT NULL,
  IS_AUTO_WITHDRAW NUMBER(1) DEFAULT 0        NOT NULL,
  CLOSE_LOGIN NUMBER(1) DEFAULT 0             NOT NULL,
  REG_TYPE    VARCHAR2(32) DEFAULT '56D9181C0F5D428FA2DBD4CAB263BF2F' NOT NULL,
  SHOULD_REG_TYPE VARCHAR2(32) DEFAULT '56D9181C0F5D428FA2DBD4CAB263BF2F',
  REG_NAME    VARCHAR2(255) ,
  CREDIT_CODE VARCHAR2(255) ,
  PREMISES    VARCHAR2(255) ,
  LEGAL_PERSON VARCHAR2(255) ,
  REG_EXPIRES NUMBER(10) ,
  STORE_TYPE  NUMBER(1) DEFAULT 0             NOT NULL,
  INVOICE_BALANCE  NUMBER(16,2) DEFAULT 0.00  NOT NULL,
  HIGHEST_EMP_LV VARCHAR2(32) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  CLOSE_LOGIN_AT  NUMBER(10) DEFAULT 0        NOT NULL,
  PULLED_AT   NUMBER(10) DEFAULT 0            NOT NULL,
  DELETED   NUMBER(1) DEFAULT 0               NOT NULL,
  DELETED_AT   NUMBER(10) DEFAULT 0           NOT NULL,
  GROUP_LEADER_AT   NUMBER(10) DEFAULT 0      NOT NULL,
  ALLOW_TRANSFER NUMBER(1) DEFAULT 1          NOT NULL,
  ALLOW_RECONSUME_SMS NUMBER(1) DEFAULT 0          NOT NULL,
  ALLOW_RECONSUME_SMS_TO  NUMBER(10) DEFAULT 0        NOT NULL,
  HIGHEST_EMP_LV_PERIOD NUMBER(10) DEFAULT 1   NOT NULL,
  TRANSFER_PROP NUMBER(10,2) DEFAULT 100.00     NOT NULL,
  LOGIN_NUMS NUMBER(10) DEFAULT 0            NOT NULL,
  FAIL_NUMS NUMBER(10) DEFAULT 0            NOT NULL,
  LAST_LOGIN_IP VARCHAR2(16) DEFAULT '0.0.0.0' NOT NULL ,
  LAST_LOGIN_AT  NUMBER(10) DEFAULT 0                     NOT NULL,
  SHOW_EMP_LV     VARCHAR2(32) DEFAULT NULL
);
COMMENT ON TABLE AR_USER_INFO IS '会员资料表';
COMMENT ON COLUMN AR_USER_INFO.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_INFO.USER_NAME IS '会员名';
COMMENT ON COLUMN AR_USER_INFO.ZC_PV IS '注册单PV';
COMMENT ON COLUMN AR_USER_INFO.CON_UID IS '接点人ID';
COMMENT ON COLUMN AR_USER_INFO.REC_UID IS '推荐人ID';
COMMENT ON COLUMN AR_USER_INFO.CON_NUM IS '下级节点数量';
COMMENT ON COLUMN AR_USER_INFO.REC_NUM IS '开拓会员数量';
COMMENT ON COLUMN AR_USER_INFO.NETWORK_DEEP IS '安置网络深度';
COMMENT ON COLUMN AR_USER_INFO.RELATION_DEEP IS '开拓网络深度';
COMMENT ON COLUMN AR_USER_INFO.SYSTEM_ID IS '体系ID';
COMMENT ON COLUMN AR_USER_INFO.IS_GROUP_LEADER IS '是否团队领导人';
COMMENT ON COLUMN AR_USER_INFO.IS_SYSTEM_LEADER IS '是否体系领导人';
COMMENT ON COLUMN AR_USER_INFO.IS_TEAM IS '是否点位合作';
COMMENT ON COLUMN AR_USER_INFO.IS_BIND IS '是否点位绑定';
COMMENT ON COLUMN AR_USER_INFO.IS_TEAM_MAIN IS '是否点位合作主点';
COMMENT ON COLUMN AR_USER_INFO.IS_BIND_MAIN IS '是否点位绑定主点';
COMMENT ON COLUMN AR_USER_INFO.IS_AUTO_WITHDRAW IS '是否开启自动提现';
COMMENT ON COLUMN AR_USER_INFO.CLOSE_LOGIN IS '关闭结算系统登录';
COMMENT ON COLUMN AR_USER_INFO.REG_TYPE IS '注册类型';
COMMENT ON COLUMN AR_USER_INFO.SHOULD_REG_TYPE IS '应注册类型';
COMMENT ON COLUMN AR_USER_INFO.REG_NAME IS '注册名称';
COMMENT ON COLUMN AR_USER_INFO.CREDIT_CODE IS '信用代码';
COMMENT ON COLUMN AR_USER_INFO.PREMISES IS '经营场所';
COMMENT ON COLUMN AR_USER_INFO.LEGAL_PERSON IS '法人';
COMMENT ON COLUMN AR_USER_INFO.REG_EXPIRES IS '注册有效期';
COMMENT ON COLUMN AR_USER_INFO.STORE_TYPE IS '店铺类型';
COMMENT ON COLUMN AR_USER_INFO.INVOICE_BALANCE IS '发票余额';
COMMENT ON COLUMN AR_USER_INFO.HIGHEST_EMP_LV IS '历史最高聘级';
COMMENT ON COLUMN AR_USER_INFO.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_INFO.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_USER_INFO.CLOSE_LOGIN_AT IS '禁止登录时间';
COMMENT ON COLUMN AR_USER_INFO.PULLED_AT IS '站内信拉取时间';
COMMENT ON COLUMN AR_USER_INFO.DELETED IS '是否删除';
COMMENT ON COLUMN AR_USER_INFO.DELETED_AT IS '删除时间';
COMMENT ON COLUMN AR_USER_INFO.GROUP_LEADER_AT IS '成为团队领导人的时间';
COMMENT ON COLUMN AR_USER_INFO.ALLOW_TRANSFER is '开启转账功能';
COMMENT ON COLUMN AR_USER_INFO.ALLOW_RECONSUME_SMS is '开启复销短信通知';
COMMENT ON COLUMN AR_USER_INFO.ALLOW_RECONSUME_SMS_TO is '开启复销短信通知有效期';
COMMENT ON COLUMN AR_USER_INFO.HIGHEST_EMP_LV_PERIOD is '首次达到最高聘级期数';
COMMENT ON COLUMN AR_USER_INFO.TRANSFER_PROP is '单笔转账比例';
COMMENT ON COLUMN AR_USER_INFO.LOGIN_NUMS IS '登录次数';
COMMENT ON COLUMN AR_USER_INFO.FAIL_NUMS IS '登录失败次数';
COMMENT ON COLUMN AR_USER_INFO.LAST_LOGIN_IP IS '上次登录IP';
COMMENT ON COLUMN AR_USER_INFO.LAST_LOGIN_AT IS '上次登录时间';
COMMENT ON COLUMN AR_USER_INFO.SHOW_EMP_LV IS '展示聘级';


CREATE INDEX AR_U_I_USER_NAME_DEL ON AR_USER_INFO(USER_NAME, DELETED);
CREATE INDEX AR_U_I_NETWORK_DEEP_INDEX ON AR_USER_INFO(NETWORK_DEEP);
CREATE INDEX AR_U_I_RELATION_DEEP_INDEX ON AR_USER_INFO(RELATION_DEEP);
CREATE INDEX AR_U_I_IS_REG_TYPE ON AR_USER_INFO(REG_TYPE);

INSERT INTO AR_USER_INFO (USER_ID, USER_NAME, ZC_PV, CON_UID, REC_UID, CON_NUM, REC_NUM, NETWORK_DEEP, RELATION_DEEP, SYSTEM_ID, IS_AUTO_WITHDRAW, STORE_TYPE, CREATED_AT, UPDATED_AT) VALUES ('670B84FD7C216D4EE055736AECE8644D', 'tester001', 600.000, '0', '0', 11, 11, 0, 0, null, 1, 0, 1520667339, 0);
COMMIT ;

-- 点位合作
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_TEAMWORK';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_TEAMWORK
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  MAIN_UID    VARCHAR2(32)                    NOT NULL,
  DIVIDE_PERCENT NUMBER(16,2) DEFAULT 0.00    NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  IS_DEL      NUMBER(10) DEFAULT 0            NOT NULL,
  CREATE_ADMIN VARCHAR2(32)                   NOT NULL,
  UPDATE_ADMIN VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000) ,
  UPDATE_REMARK VARCHAR2(4000) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  UPDATED_PERIOD NUMBER(10) ,
  DELETED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_TEAMWORK IS '点位合作';
COMMENT ON COLUMN AR_USER_TEAMWORK.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_TEAMWORK.MAIN_UID IS '主会员ID';
COMMENT ON COLUMN AR_USER_TEAMWORK.DIVIDE_PERCENT IS '分成比例';
COMMENT ON COLUMN AR_USER_TEAMWORK.PERIOD_NUM IS '加入时期数';
COMMENT ON COLUMN AR_USER_TEAMWORK.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_USER_TEAMWORK.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_USER_TEAMWORK.UPDATE_ADMIN IS '修改人';
COMMENT ON COLUMN AR_USER_TEAMWORK.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_USER_TEAMWORK.UPDATE_REMARK IS '修改备注';
COMMENT ON COLUMN AR_USER_TEAMWORK.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_TEAMWORK.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_USER_TEAMWORK.UPDATED_PERIOD IS '修改期数';
COMMENT ON COLUMN AR_USER_TEAMWORK.DELETED_AT IS '已删除';

CREATE INDEX AR_U_TWORK_USER_ID ON AR_USER_TEAMWORK(USER_ID);
CREATE INDEX AR_U_TWORK_MAIN_UID ON AR_USER_TEAMWORK(MAIN_UID);

-- 点位绑定
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_BIND';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_BIND
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  MAIN_UID    VARCHAR2(32)                    NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  IS_DEL      NUMBER(10) DEFAULT 0            NOT NULL,
  CREATE_ADMIN VARCHAR2(32),
  UPDATE_ADMIN VARCHAR2(32),
  CREATE_USER VARCHAR2(32),
  UPDATE_USER VARCHAR2(32),
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  DELETED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_BIND IS '点位合作';
COMMENT ON COLUMN AR_USER_BIND.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_BIND.MAIN_UID IS '主会员ID';
COMMENT ON COLUMN AR_USER_BIND.PERIOD_NUM IS '加入时期数';
COMMENT ON COLUMN AR_USER_BIND.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_USER_BIND.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_BIND.DELETED_AT IS '已删除';

CREATE INDEX AR_U_BIND_USER_ID ON AR_USER_BIND(USER_ID);
CREATE INDEX AR_U_BIND_MAIN_UID ON AR_USER_BIND(MAIN_UID);

-- 会员奖金表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_BONUS';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_BONUS
(
  USER_ID     VARCHAR2(32)                    NOT NULL PRIMARY KEY,
  BONUS       NUMBER(16,2) DEFAULT 0          NOT NULL,
  BONUS_FREEZE NUMBER(16,2) DEFAULT 0         NOT NULL,
  CF          NUMBER(16,2) DEFAULT 0          NOT NULL,
  LX          NUMBER(16,2) DEFAULT 0          NOT NULL,
  QY_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  YC_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  FX_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  LS_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  FW_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  BT_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  BT_PROD_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  BT_TOOL_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  CF_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  LX_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  DEDUCT_ZR_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  FL_TOTAL    NUMBER(16,2) DEFAULT 0          NOT NULL,
  VER         NUMBER(10) DEFAULT 0            NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL
);

COMMENT ON TABLE AR_USER_BONUS IS '会员奖金表';
COMMENT ON COLUMN AR_USER_BONUS.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_BONUS.BONUS IS '奖金总额';
COMMENT ON COLUMN AR_USER_BONUS.BONUS_FREEZE IS '奖金冻结部分';
COMMENT ON COLUMN AR_USER_BONUS.CF IS '车房养老奖';
COMMENT ON COLUMN AR_USER_BONUS.LX IS '领袖分红奖';
COMMENT ON COLUMN AR_USER_BONUS.QY_TOTAL IS '区域津贴累计';
COMMENT ON COLUMN AR_USER_BONUS.YC_TOTAL IS '育成津贴累计';
COMMENT ON COLUMN AR_USER_BONUS.FX_TOTAL IS '复销奖累计';
COMMENT ON COLUMN AR_USER_BONUS.LS_TOTAL IS '零售奖累计';
COMMENT ON COLUMN AR_USER_BONUS.FW_TOTAL IS '区级店业绩提成累计';
COMMENT ON COLUMN AR_USER_BONUS.BT_TOTAL IS '店补累计';
COMMENT ON COLUMN AR_USER_BONUS.BT_PROD_TOTAL IS '产品补贴累计';
COMMENT ON COLUMN AR_USER_BONUS.BT_TOOL_TOTAL IS '工具流补贴累计';
COMMENT ON COLUMN AR_USER_BONUS.CF_TOTAL IS '车房养老奖累计';
COMMENT ON COLUMN AR_USER_BONUS.LX_TOTAL IS '领袖分红累计';
COMMENT ON COLUMN AR_USER_BONUS.DEDUCT_ZR_TOTAL IS '责任业绩扣除累计';
COMMENT ON COLUMN AR_USER_BONUS.FL_TOTAL IS '形象店货补累计';
COMMENT ON COLUMN AR_USER_BONUS.VER IS '乐观锁标识';
COMMENT ON COLUMN AR_USER_BONUS.CREATED_AT IS '创建时间';

-- 会员关停和停发表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_CLOSE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_CLOSE
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  TYPE        NUMBER(1) DEFAULT 1             NOT NULL,
  IS_MANUAL   NUMBER(1) DEFAULT 0             NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  IS_CLOSE    NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK      VARCHAR2(255)                   NOT NULL,
  AUDIT_STATUS NUMBER(1) DEFAULT 0            NOT NULL,
  ADMIN_ID    VARCHAR2(32) ,
  AUDIT_ADMIN_ID VARCHAR2(32) ,
  AUDITED_AT  NUMBER(10) ,
  CREATED_AT  NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_USER_CLOSE IS '会员关停和停发表';
COMMENT ON COLUMN AR_USER_CLOSE.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_CLOSE.TYPE IS '类型';
COMMENT ON COLUMN AR_USER_CLOSE.IS_MANUAL IS '是否手动操作';
COMMENT ON COLUMN AR_USER_CLOSE.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_USER_CLOSE.IS_CLOSE IS '停|开';
COMMENT ON COLUMN AR_USER_CLOSE.REMARK IS '备注';
COMMENT ON COLUMN AR_USER_CLOSE.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_USER_CLOSE.ADMIN_ID IS '操作管理员';
COMMENT ON COLUMN AR_USER_CLOSE.AUDIT_ADMIN_ID IS '审核管理员';
COMMENT ON COLUMN AR_USER_CLOSE.AUDITED_AT IS '审核时间';
COMMENT ON COLUMN AR_USER_CLOSE.CREATED_AT IS '创建时间';

CREATE INDEX AR_USER_CLOSE_UID_INDEX ON AR_USER_CLOSE(USER_ID);
CREATE INDEX AR_USER_CLOSE_TYPE_INDEX ON AR_USER_CLOSE(TYPE);
CREATE INDEX AR_USER_CLOSE_PN_INDEX ON AR_USER_CLOSE(PERIOD_NUM);
CREATE INDEX AR_USER_CLOSE_IC_INDEX ON AR_USER_CLOSE(IS_CLOSE);
CREATE INDEX AR_USER_CLOSE_AS_INDEX ON AR_USER_CLOSE(AUDIT_STATUS);

-- 会员安置关系表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_NETWORK';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_NETWORK
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID         VARCHAR2(32)                    NOT NULL,
  PARENT_UID  VARCHAR2(32)                    NOT NULL,
  LOCATION    NUMBER(1)                       NOT NULL,
  TOP_UID     VARCHAR2(32)                    NOT NULL,
  TOP_DEEP    NUMBER(10)                      NOT NULL,
  PERIOD_NUM      NUMBER(10)                      NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_NETWORK IS '安置关系表';
COMMENT ON COLUMN AR_USER_NETWORK.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_NETWORK.PARENT_UID IS '相对上级会员ID';
COMMENT ON COLUMN AR_USER_NETWORK.LOCATION IS '相对上级会员区位';
COMMENT ON COLUMN AR_USER_NETWORK.TOP_UID IS '顶端会员ID';
COMMENT ON COLUMN AR_USER_NETWORK.TOP_DEEP IS '距离顶端会员深度';
COMMENT ON COLUMN AR_USER_NETWORK.PERIOD_NUM IS '加入时的期数';
COMMENT ON COLUMN AR_USER_NETWORK.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_NETWORK.UPDATED_AT IS '更新时间';

CREATE INDEX AR_U_NETWORK_USER_ID ON AR_USER_NETWORK(USER_ID);
CREATE INDEX AR_U_NETWORK_PARENT_UID ON AR_USER_NETWORK(PARENT_UID);
CREATE INDEX AR_U_NETWORK_LOCATION ON AR_USER_NETWORK(LOCATION);
CREATE INDEX AR_U_NETWORK_TOP_DEEP ON AR_USER_NETWORK(TOP_DEEP);
CREATE INDEX AR_U_NETWORK_PERIOD_NUM ON AR_USER_NETWORK(PERIOD_NUM);

INSERT INTO AR_USER_NETWORK (ID, USER_ID, PARENT_UID, LOCATION, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('8F793577F2A44947A5918852976AE290', '670B84FD7C216D4EE055736AECE8644D', '0', 0, '670B84FD7C216D4EE055736AECE8644D', 0, 100, 1522378282, 0);
COMMIT ;

-- 会员开拓关系
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_RELATION';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_RELATION
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID         VARCHAR2(32)                    NOT NULL,
  PARENT_UID  VARCHAR2(32)                    NOT NULL,
  TOP_UID     VARCHAR2(32)                    NOT NULL,
  TOP_DEEP    NUMBER(10)                      NOT NULL,
  PERIOD_NUM      NUMBER(10)                      NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_RELATION IS '开拓关系表';
COMMENT ON COLUMN AR_USER_RELATION.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_RELATION.PARENT_UID IS '相对上级会员ID';
COMMENT ON COLUMN AR_USER_RELATION.TOP_UID IS '顶端会员ID';
COMMENT ON COLUMN AR_USER_RELATION.TOP_DEEP IS '距离顶端会员深度';
COMMENT ON COLUMN AR_USER_RELATION.PERIOD_NUM IS '加入时的期数';
COMMENT ON COLUMN AR_USER_RELATION.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_RELATION.UPDATED_AT IS '更新时间';

CREATE INDEX AR_U_RELAT_USER_ID ON AR_USER_RELATION(USER_ID);
CREATE INDEX AR_U_RELAT_PARENT_UID ON AR_USER_RELATION(PARENT_UID);
CREATE INDEX AR_U_RELAT_TOP_DEEP ON AR_USER_RELATION(TOP_DEEP);
CREATE INDEX AR_U_RELAT_PERIOD_NUM ON AR_USER_RELATION(PERIOD_NUM);

INSERT INTO AR_USER_RELATION (ID, USER_ID, PARENT_UID, TOP_UID, TOP_DEEP, PERIOD_NUM, CREATED_AT, UPDATED_AT) VALUES ('EF010C38C7144BD0844593A1FF8AC7AD', '670B84FD7C216D4EE055736AECE8644D', '0', '670B84FD7C216D4EE055736AECE8644D', 0, 100, 1522378282, 0);
COMMIT ;

-- 会员体系
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_SYSTEM';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_SYSTEM
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  SYSTEM_NAME VARCHAR2(32)                    NOT NULL,
  LEADER_UID  VARCHAR2(32)                    NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  UPDATE_PERIOD_NUM  NUMBER(10) ,
  CREATE_ADMIN VARCHAR2(32)                   NOT NULL,
  UPDATE_ADMIN VARCHAR2(32) ,
  CREATE_REMARK  VARCHAR2(4000) ,
  UPDATE_REMARK  VARCHAR2(4000) ,
  IS_DEL      NUMBER(1) DEFAULT 0             NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  DELETED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_SYSTEM IS '会员体系';
COMMENT ON COLUMN AR_USER_SYSTEM.SYSTEM_NAME IS '体系名称';
COMMENT ON COLUMN AR_USER_SYSTEM.LEADER_UID IS '领导人ID';
COMMENT ON COLUMN AR_USER_SYSTEM.PERIOD_NUM IS '加入时的期数';
COMMENT ON COLUMN AR_USER_SYSTEM.UPDATE_PERIOD_NUM IS '修改期数';
COMMENT ON COLUMN AR_USER_SYSTEM.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_USER_SYSTEM.UPDATE_ADMIN IS '修改人';
COMMENT ON COLUMN AR_USER_SYSTEM.CREATE_REMARK IS '备注';
COMMENT ON COLUMN AR_USER_SYSTEM.UPDATE_REMARK IS '备注';
COMMENT ON COLUMN AR_USER_SYSTEM.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_USER_SYSTEM.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_SYSTEM.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_USER_SYSTEM.DELETED_AT IS '删除时间';

CREATE UNIQUE INDEX AR_USER_SYS_SYSTEM_NAME_UINDEX ON AR_USER_SYSTEM(SYSTEM_NAME);
CREATE UNIQUE INDEX AR_USER_SYS_LEADER_UID_UINDEX ON AR_USER_SYSTEM(LEADER_UID);


-- 会员移网记录
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_MOVE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_MOVE
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID     VARCHAR2(32)                    NOT NULL,
  FROM_UID    VARCHAR2(32)                    NOT NULL,
  TO_UID      VARCHAR2(32)                    NOT NULL,
  LOCATION    NUMBER(1) DEFAULT 0             NOT NULL,
  TYPE        VARCHAR2(48)                    NOT NULL,
  IS_MOVING   NUMBER(1) DEFAULT 0             NOT NULL,
  MOVE_PERCENT  NUMBER(3) DEFAULT 0           NOT NULL,
  AUDIT_STATUS NUMBER(1) DEFAULT 0            NOT NULL,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  UPDATE_PERIOD_NUM  NUMBER(10),
  AUDIT_PERIOD_NUM  NUMBER(10),
  MOVE_ADMIN_ID VARCHAR2(32)                  NOT NULL,
  AUDIT_ADMIN_ID VARCHAR2(32) ,
  NET_TABLE_NAME VARCHAR2(32) ,
  CREATE_REMARK  VARCHAR2(4000) ,
  AUDIT_REMARK  VARCHAR2(4000) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  STARTED_AT  NUMBER(10) DEFAULT 0            NOT NULL,
  ENDED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  AUDITED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_MOVE IS '会员移网记录';
COMMENT ON COLUMN AR_USER_MOVE.USER_ID IS '移动的会员ID';
COMMENT ON COLUMN AR_USER_MOVE.FROM_UID IS '移动前接点UID';
COMMENT ON COLUMN AR_USER_MOVE.TO_UID IS '移动后接点UID';
COMMENT ON COLUMN AR_USER_MOVE.LOCATION IS '移动到位置';
COMMENT ON COLUMN AR_USER_MOVE.TYPE IS '移网类型';
COMMENT ON COLUMN AR_USER_MOVE.IS_MOVING IS '是否正在移动';
COMMENT ON COLUMN AR_USER_MOVE.MOVE_PERCENT IS '移动百分比';
COMMENT ON COLUMN AR_USER_MOVE.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_USER_MOVE.PERIOD_NUM IS '移动时的期数';
COMMENT ON COLUMN AR_USER_MOVE.UPDATE_PERIOD_NUM IS '修改期数';
COMMENT ON COLUMN AR_USER_MOVE.AUDIT_PERIOD_NUM IS '修改期数';
COMMENT ON COLUMN AR_USER_MOVE.MOVE_ADMIN_ID IS '移网管理员';
COMMENT ON COLUMN AR_USER_MOVE.AUDIT_ADMIN_ID IS '审核管理员';
COMMENT ON COLUMN AR_USER_MOVE.NET_TABLE_NAME IS '移点备份表名';
COMMENT ON COLUMN AR_USER_MOVE.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_USER_MOVE.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_USER_MOVE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_MOVE.STARTED_AT IS '移网开始时间';
COMMENT ON COLUMN AR_USER_MOVE.ENDED_AT IS '移网结束时间';
COMMENT ON COLUMN AR_USER_MOVE.AUDITED_AT IS '审核时间';

-- 会员累计业绩
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_PERF';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_PERF
(
  USER_ID       VARCHAR2(32)                    NOT NULL PRIMARY KEY,
  PV_PCS_ZC     NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_PCS_YH     NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_PCS_ZG     NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_PCS_LS     NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_PCS_FX     NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_1L         NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_2L         NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_3L         NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_4L         NUMBER(16,2) DEFAULT 0          NOT NULL,
  PV_5L         NUMBER(16,2) DEFAULT 0          NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_USER_PERF IS '会员累计业绩表';
COMMENT ON COLUMN AR_USER_PERF.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_PERF.PV_PCS_ZC IS '个人注册单累计';
COMMENT ON COLUMN AR_USER_PERF.PV_PCS_YH IS '个人优惠单累计';
COMMENT ON COLUMN AR_USER_PERF.PV_PCS_ZG IS '个人增购单累计';
COMMENT ON COLUMN AR_USER_PERF.PV_PCS_LS IS '个人零售单累计';
COMMENT ON COLUMN AR_USER_PERF.PV_PCS_FX IS '个人复销单累计';
COMMENT ON COLUMN AR_USER_PERF.PV_1L IS '一市场累计业绩';
COMMENT ON COLUMN AR_USER_PERF.PV_2L IS '二市场累计业绩';
COMMENT ON COLUMN AR_USER_PERF.PV_3L IS '三市场累计业绩';
COMMENT ON COLUMN AR_USER_PERF.PV_4L IS '四市场累计业绩';
COMMENT ON COLUMN AR_USER_PERF.PV_5L IS '五市场累计业绩';
COMMENT ON COLUMN AR_USER_PERF.CREATED_AT IS '创建时间';

-- 会员累计业绩更新期数
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_PERF_UPDATE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_PERF_UPDATE
(
    ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)              NOT NULL,
    PERIOD_NUM    NUMBER(10) DEFAULT 0      NOT NULL,
    P_CALC_MONTH  DATE                      NOT NULL,
    CREATED_AT    NUMBER(10)                NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_USER_PERF_UPDATE IS '会员累计业绩更新期数';
COMMENT ON COLUMN AR_USER_PERF_UPDATE.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_PERF_UPDATE.PERIOD_NUM IS '更新时的期数';
COMMENT ON COLUMN AR_USER_PERF_UPDATE.P_CALC_MONTH IS '更新时的结算月';
COMMENT ON COLUMN AR_USER_PERF_UPDATE.CREATED_AT IS '创建时间';
CREATE INDEX AR_USER_PERF_UPDATE_UID ON AR_USER_PERF_UPDATE(USER_ID);

-- 报单级别变动
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_DEC_LEVEL_LOG';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DEC_LEVEL_LOG
(
  ID         VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID    VARCHAR2(32)                    NOT NULL,
  FROM_ID    VARCHAR2(32)                    NOT NULL,
  TO_ID      VARCHAR2(32)                    NOT NULL,
  PERIOD_NUM NUMBER(10)                      NOT NULL,
  CALC_MONTH NUMBER(10)                      NOT NULL,
  REMARK     VARCHAR2(4000)                  NOT NULL,
  ADMIN_ID   VARCHAR2(32)  DEFAULT ''        NOT NULL,
  STATUS     NUMBER(1) DEFAULT 0             NOT NULL,
  CREATED_AT NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_DEC_LEVEL_LOG IS '报单级别变动记录';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.FROM_ID IS '变动前的级别';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.TO_ID IS '变动后的级别';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.PERIOD_NUM IS '变动的期数';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.CALC_MONTH IS '变动的结算月';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.REMARK IS '备注';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.ADMIN_ID IS '管理员ID';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.STATUS IS '状态';
COMMENT ON COLUMN AR_DEC_LEVEL_LOG.CREATED_AT IS '创建时间';

CREATE INDEX AR_DEC_LEVEL_LOG_USER_ID ON AR_DEC_LEVEL_LOG(USER_ID);
CREATE INDEX AR_DEC_LEVEL_LOG_PERIOD_NUM ON AR_DEC_LEVEL_LOG(PERIOD_NUM);
CREATE INDEX AR_DEC_LEVEL_LOG_STATUS ON AR_DEC_LEVEL_LOG(STATUS);


-- 聘级变动记录表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_EMPLOY_LEVEL_LOG';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EMPLOY_LEVEL_LOG
(
  ID         VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID    VARCHAR2(32)                    NOT NULL,
  FROM_ID    VARCHAR2(32)                    NOT NULL,
  TO_ID      VARCHAR2(32)                    NOT NULL,
  PERIOD_NUM NUMBER(10)                      NOT NULL,
  CALC_MONTH NUMBER(10)                      NOT NULL,
  P_CALC_MONTH DATE                          NOT NULL,
  REMARK     VARCHAR2(4000) ,
  CREATED_AT NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_EMPLOY_LEVEL_LOG IS '聘级变动记录表';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.FROM_ID IS '变动前的级别';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.TO_ID IS '变动后的级别';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.PERIOD_NUM IS '变动时的期数';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.CALC_MONTH IS '变动时的结算月';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.P_CALC_MONTH IS '表分区标识';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.REMARK IS '备注';
COMMENT ON COLUMN AR_EMPLOY_LEVEL_LOG.CREATED_AT IS '创建时间';

-- 注册类型
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_REG_TYPE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_REG_TYPE
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TYPE_NAME   VARCHAR2(48)                    NOT NULL,
  IS_PACT     NUMBER(1)  DEFAULT 1            NOT NULL,
  MONTH_LIMIT_AMOUNT   NUMBER(16,2)  DEFAULT 0           NOT NULL,
  YEAR_LIMIT_AMOUNT   NUMBER(16,2)  DEFAULT 0           NOT NULL,
  SORT        NUMBER(10)  DEFAULT 0           NOT NULL,
  CREATE_ADMIN VARCHAR2(32) ,
  UPDATE_ADMIN VARCHAR2(32) ,
  REMARK      VARCHAR2(255) ,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  UPDATED_AT  NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_REG_TYPE IS '聘级';
COMMENT ON COLUMN AR_REG_TYPE.TYPE_NAME IS '类型名称';
COMMENT ON COLUMN AR_REG_TYPE.IS_PACT IS '是否启用协议';
COMMENT ON COLUMN AR_REG_TYPE.MONTH_LIMIT_AMOUNT IS '达到月提现金额升级应注册类型';
COMMENT ON COLUMN AR_REG_TYPE.YEAR_LIMIT_AMOUNT IS '达到年提现金额升级应注册类型';
COMMENT ON COLUMN AR_REG_TYPE.SORT IS '排序';
COMMENT ON COLUMN AR_REG_TYPE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_REG_TYPE.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_R_T_TYPE_NAME_UNINDEX ON AR_REG_TYPE(TYPE_NAME);

INSERT INTO AR_REG_TYPE (ID, TYPE_NAME, SORT, CREATED_AT, UPDATED_AT) VALUES ('56D9181C0F5D428FA2DBD4CAB263BF2F', '个人', 1, 1521438677, 0);
INSERT INTO AR_REG_TYPE (ID, TYPE_NAME, SORT, CREATED_AT, UPDATED_AT) VALUES ('28359A005A3E44C6816A4A7E994B7789', '个体工商户', 2, 1521438677, 0);
INSERT INTO AR_REG_TYPE (ID, TYPE_NAME, SORT, CREATED_AT, UPDATED_AT) VALUES ('758BF69C25C3422AA7743936BC77EE64', '公司', 3, 1521438677, 0);
COMMIT;

-- 期数
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_PERIOD';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERIOD
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(2)                       NOT NULL,
  CALC_YEAR     NUMBER(4)                       NOT NULL,
  START_TIME    NUMBER(10)                      NOT NULL,
  END_TIME      NUMBER(10)                      NOT NULL,
  IS_MONTH      NUMBER(1) DEFAULT 0             NOT NULL,
  IS_YEAR       NUMBER(1) DEFAULT 0             NOT NULL,
  IS_CLOSED     NUMBER(1) DEFAULT 0             NOT NULL,
  IS_PERFED     NUMBER(1) DEFAULT 0             NOT NULL,
  IS_CALCULATED NUMBER(1) DEFAULT 0             NOT NULL,
  IS_SENT       NUMBER(1) DEFAULT 0             NOT NULL,
  IS_PERFING    NUMBER(1) DEFAULT 0             NOT NULL,
  IS_CALCING    NUMBER(1) DEFAULT 0             NOT NULL,
  IS_SENDING    NUMBER(1) DEFAULT 0             NOT NULL,
  PERF_PERCENT  NUMBER(3) DEFAULT 0             NOT NULL,
  CALC_PERCENT  NUMBER(3) DEFAULT 0             NOT NULL,
  SENT_PERCENT  NUMBER(3) DEFAULT 0             NOT NULL,
  PERF_ADMIN_ID VARCHAR2(32) ,
  CLOSE_ADMIN_ID VARCHAR2(32) ,
  CALC_ADMIN_ID VARCHAR2(32) ,
  SENT_ADMIN_ID VARCHAR2(32) ,
  CLOSED_AT     NUMBER(10) ,
  PERF_STARTED_AT NUMBER(10) DEFAULT 0          NOT NULL,
  PERFED_AT     NUMBER(10) DEFAULT 0            NOT NULL,
  CALCULATE_STARTED_AT NUMBER(10) DEFAULT 0     NOT NULL,
  CALCULATED_AT NUMBER(10) DEFAULT 0            NOT NULL,
  SEND_STARTED_AT NUMBER(10) DEFAULT 0          NOT NULL,
  SENT_AT       NUMBER(10) DEFAULT 0            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_PERIOD IS '期数';
COMMENT ON COLUMN AR_PERIOD.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_PERIOD.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_PERIOD.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_PERIOD.START_TIME IS '期数开始时间戳';
COMMENT ON COLUMN AR_PERIOD.END_TIME IS '期数结束时间戳';
COMMENT ON COLUMN AR_PERIOD.IS_MONTH IS '是否结算月节点';
COMMENT ON COLUMN AR_PERIOD.IS_YEAR IS '是否结算年节点';
COMMENT ON COLUMN AR_PERIOD.IS_CLOSED IS '是否已封期';
COMMENT ON COLUMN AR_PERIOD.IS_PERFED IS '是否已生成业绩单';
COMMENT ON COLUMN AR_PERIOD.IS_CALCULATED IS '是否已结算';
COMMENT ON COLUMN AR_PERIOD.IS_SENT IS '是否已发放';
COMMENT ON COLUMN AR_PERIOD.IS_PERFING IS '是否正在生成业绩单';
COMMENT ON COLUMN AR_PERIOD.IS_CALCING IS '是否正在计算状态';
COMMENT ON COLUMN AR_PERIOD.IS_SENDING IS '是否正在挂网状态';
COMMENT ON COLUMN AR_PERIOD.PERF_PERCENT IS '生成业绩单进度';
COMMENT ON COLUMN AR_PERIOD.CALC_PERCENT IS '结算进度';
COMMENT ON COLUMN AR_PERIOD.SENT_PERCENT IS '发放进度';
COMMENT ON COLUMN AR_PERIOD.PERF_ADMIN_ID IS '生成业绩单管理员';
COMMENT ON COLUMN AR_PERIOD.CLOSE_ADMIN_ID IS '手动封期管理员ID';
COMMENT ON COLUMN AR_PERIOD.CALC_ADMIN_ID IS '结算管理员ID';
COMMENT ON COLUMN AR_PERIOD.SENT_ADMIN_ID IS '发放管理员ID';
COMMENT ON COLUMN AR_PERIOD.CLOSED_AT IS '发放管理员ID';
COMMENT ON COLUMN AR_PERIOD.PERF_STARTED_AT IS '生成业绩单开始时间';
COMMENT ON COLUMN AR_PERIOD.PERFED_AT IS '生成业绩单结束时间';
COMMENT ON COLUMN AR_PERIOD.CALCULATE_STARTED_AT IS '结算开始时间';
COMMENT ON COLUMN AR_PERIOD.CALCULATED_AT IS '结算完成时间';
COMMENT ON COLUMN AR_PERIOD.SEND_STARTED_AT IS '发放开始时间';
COMMENT ON COLUMN AR_PERIOD.SENT_AT IS '发放完成时间';
COMMENT ON COLUMN AR_PERIOD.CREATED_AT IS '创建时间';

CREATE UNIQUE INDEX AR_PERIOD_PERIOD_NUM_UINDEX ON AR_PERIOD(PERIOD_NUM);
CREATE INDEX AR_PERIOD_ISCLOSED_INDEX ON AR_PERIOD(IS_CLOSED);
CREATE INDEX AR_PERIOD_ISPERFED_INDEX ON AR_PERIOD(IS_PERFED);
CREATE INDEX AR_PERIOD_ISCALC_INDEX ON AR_PERIOD(IS_CALCULATED);
CREATE INDEX AR_PERIOD_ISSENT_INDEX ON AR_PERIOD(IS_SENT);
CREATE INDEX AR_PERIOD_IS_PERFING_INDEX ON AR_PERIOD(IS_PERFING);
CREATE INDEX AR_PERIOD_IS_CALCING_INDEX ON AR_PERIOD(IS_CALCING);
CREATE INDEX AR_PERIOD_IS_SENDING_INDEX ON AR_PERIOD(IS_SENDING);

-- 会员提供的税票
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_BILL';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_BILL
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID           VARCHAR2(32)                    NOT NULL,
  BILL_NO       VARCHAR2(255)                   NOT NULL,
  BILL_AMOUNT   NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  USED_AMOUNT   NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  EXPIRY_DATE   NUMBER(10)                      NOT NULL,
  INPUT_ADMIN_ID VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_BILL IS '会员提供的税票';
COMMENT ON COLUMN AR_BILL.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_BILL.BILL_NO IS '发票号';
COMMENT ON COLUMN AR_BILL.BILL_AMOUNT IS '发票金额';
COMMENT ON COLUMN AR_BILL.USED_AMOUNT IS '已用金额';
COMMENT ON COLUMN AR_BILL.EXPIRY_DATE IS '有效期';
COMMENT ON COLUMN AR_BILL.INPUT_ADMIN_ID IS '录入管理员ID';
COMMENT ON COLUMN AR_BILL.CREATED_AT IS '创建时间';

-- 提现申请
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_WITHDRAW';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_WITHDRAW
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  SN              VARCHAR2(32),
  USER_ID         VARCHAR2(32)                    NOT NULL,
  ID_CARD         VARCHAR2(20) ,
  WITHDRAW_PERIOD_NUM NUMBER(10),
  WITHDRAW_YEAR   NUMBER(4),
  WITHDRAW_MONTH  NUMBER(2),
  PAY_TYPE        NUMBER(1)  DEFAULT 1            NOT NULL,
  IS_AUTO_WITHDRAW NUMBER(1) DEFAULT 0            NOT NULL,
  AMOUNT          NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  INVOICE_ID      VARCHAR2(32),
  REAL_NAME       VARCHAR2(255),
  OPEN_BANK       VARCHAR2(32),
  BANK_ADDRESS    VARCHAR2(255),
  BANK_NO         VARCHAR2(32),
  BANK_PROVINCE   NUMBER(6),
  BANK_CITY       NUMBER(6),
  BANK_COUNTY     NUMBER(6),
  P_MONTH         DATE                            NOT NULL,
  AUDIT_STATUS    NUMBER(1) DEFAULT 0             NOT NULL,
  REMARK          VARCHAR2(4000),
  UPDATE_ADMIN    VARCHAR2(32),
  UPDATE_REMARK   VARCHAR2(4000),
  AUDIT_ADMIN     VARCHAR2(32),
  CREATED_AT      NUMBER(10)                      NOT NULL,
  UPDATED_AT      NUMBER(10) DEFAULT 0            NOT NULL,
  AUDITED_AT      NUMBER(10) DEFAULT 0            NOT NULL,
  PLAN_PAID_AT    NUMBER(10)                      NOT NULL,
  PAID_AT         NUMBER(10) DEFAULT 0            NOT NULL,
  PAID_FAIL_REMARK VARCHAR2(4000),
  PAID_FAIL_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  BACK_REMARK VARCHAR2(4000),
  BACK_FAIL_AT    NUMBER(10) DEFAULT 0            NOT NULL
)
PARTITION BY RANGE(P_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_WITHDRAW IS '提现申请';
COMMENT ON COLUMN AR_WITHDRAW.SN IS '单号';
COMMENT ON COLUMN AR_WITHDRAW.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_WITHDRAW.ID_CARD IS '身份证号';
COMMENT ON COLUMN AR_WITHDRAW.WITHDRAW_PERIOD_NUM IS '提现期数';
COMMENT ON COLUMN AR_WITHDRAW.WITHDRAW_YEAR IS '提现年份';
COMMENT ON COLUMN AR_WITHDRAW.WITHDRAW_MONTH IS '提现月份';
COMMENT ON COLUMN AR_WITHDRAW.PAY_TYPE IS '付款类型';
COMMENT ON COLUMN AR_WITHDRAW.IS_AUTO_WITHDRAW IS '是否自动提现';
COMMENT ON COLUMN AR_WITHDRAW.AMOUNT IS '提现金额';
COMMENT ON COLUMN AR_WITHDRAW.INVOICE_ID IS '发票ID';
COMMENT ON COLUMN AR_WITHDRAW.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_WITHDRAW.OPEN_BANK IS '开户行';
COMMENT ON COLUMN AR_WITHDRAW.BANK_ADDRESS IS '银行地址';
COMMENT ON COLUMN AR_WITHDRAW.BANK_NO IS '银行账号';
COMMENT ON COLUMN AR_WITHDRAW.BANK_PROVINCE IS '银行省份';
COMMENT ON COLUMN AR_WITHDRAW.BANK_CITY IS '银行城市';
COMMENT ON COLUMN AR_WITHDRAW.BANK_COUNTY IS '银行地区';
COMMENT ON COLUMN AR_WITHDRAW.P_MONTH IS '表分区标识';
COMMENT ON COLUMN AR_WITHDRAW.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_WITHDRAW.REMARK IS '备注';
COMMENT ON COLUMN AR_WITHDRAW.UPDATE_ADMIN IS '修改管理员';
COMMENT ON COLUMN AR_WITHDRAW.UPDATE_REMARK IS '修改备注';
COMMENT ON COLUMN AR_WITHDRAW.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_WITHDRAW.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_WITHDRAW.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_WITHDRAW.AUDITED_AT IS '审核时间';
COMMENT ON COLUMN AR_WITHDRAW.PLAN_PAID_AT IS '预计付款时间';
COMMENT ON COLUMN AR_WITHDRAW.PAID_AT IS '付款时间';
COMMENT ON COLUMN AR_WITHDRAW.PAID_FAIL_REMARK IS '付款失败备注';
COMMENT ON COLUMN AR_WITHDRAW.PAID_FAIL_AT IS '付款失败时间';
COMMENT ON COLUMN AR_WITHDRAW.BACK_REMARK IS '提现退回备注';
COMMENT ON COLUMN AR_WITHDRAW.BACK_FAIL_AT IS '提现退回时间';

CREATE UNIQUE INDEX AR_WITHDRAW_SN_UINDEX ON AR_WITHDRAW(SN);

-- 转账记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_TRANSFER';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_TRANSFER
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TRANSFER_SN      VARCHAR2(32)                    NOT NULL,
  OUT_UID      VARCHAR2(32)                    NOT NULL,
  LAST_OUT_USER_NAME      VARCHAR2(16)                    NOT NULL,
  LAST_OUT_REAL_NAME      VARCHAR2(128)                    NOT NULL,
  LAST_OUT_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_OUT_DEC_ROLE_ID   VARCHAR2(32)               DEFAULT '',
  OUT_WALLET   VARCHAR2(128) DEFAULT 'bonus'   NOT NULL,
  LAST_OUT_SYSTEM_ID       VARCHAR2(32)                    NOT NULL,
  IN_UID      VARCHAR2(32)                    NOT NULL,
  LAST_IN_USER_NAME      VARCHAR2(16)                    NOT NULL,
  LAST_IN_REAL_NAME      VARCHAR2(128)                    NOT NULL,
  LAST_IN_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  IN_WALLET   VARCHAR2(128) DEFAULT 'bonus'   NOT NULL,
  LAST_IN_SYSTEM_ID       VARCHAR2(32)                    NOT NULL,
  ORI_AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  FEE        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  REMARK        VARCHAR2(4000) ,
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_TRANSFER IS '转账记录';
COMMENT ON COLUMN AR_TRANSFER.TRANSFER_SN IS '转账记录流水号';
COMMENT ON COLUMN AR_TRANSFER.OUT_UID IS '转出会员ID';
COMMENT ON COLUMN AR_TRANSFER.LAST_OUT_USER_NAME IS '转账时转出会员编号';
COMMENT ON COLUMN AR_TRANSFER.LAST_OUT_REAL_NAME IS '转账时转出会员姓名';
COMMENT ON COLUMN AR_TRANSFER.LAST_OUT_DEC_LV IS '转账时转出会员级别';
COMMENT ON COLUMN AR_TRANSFER.LAST_OUT_DEC_ROLE_ID IS '转账时转出会员报单中心级别';
COMMENT ON COLUMN AR_TRANSFER.OUT_WALLET IS '转出账户';
COMMENT ON COLUMN AR_TRANSFER.LAST_OUT_SYSTEM_ID IS '转账时转出会员体系';
COMMENT ON COLUMN AR_TRANSFER.IN_UID IS '转入会员ID';
COMMENT ON COLUMN AR_TRANSFER.LAST_IN_USER_NAME IS '转账时转入会员编号';
COMMENT ON COLUMN AR_TRANSFER.LAST_IN_REAL_NAME IS '转账时转入会员姓名';
COMMENT ON COLUMN AR_TRANSFER.LAST_IN_DEC_LV IS '转账时转入会员级别';
COMMENT ON COLUMN AR_TRANSFER.IN_WALLET IS '转入账户';
COMMENT ON COLUMN AR_TRANSFER.LAST_IN_SYSTEM_ID IS '转账时转入会员体系';
COMMENT ON COLUMN AR_TRANSFER.ORI_AMOUNT IS '转账金额';
COMMENT ON COLUMN AR_TRANSFER.FEE IS '手续费';
COMMENT ON COLUMN AR_TRANSFER.AMOUNT IS '实际转入金额';
COMMENT ON COLUMN AR_TRANSFER.REMARK IS '备注';
COMMENT ON COLUMN AR_TRANSFER.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_TRANSFER.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_TRANSFER.CREATED_AT IS '创建时间';

-- 钱包变更审核记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_BALANCE_AUDIT';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_BALANCE_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_DEC_ROLE_ID   VARCHAR2(32)                    DEFAULT '',
  TYPE          VARCHAR2(48)                    NOT NULL,
  DEAL_TYPE     VARCHAR2(32)                    NOT NULL,
  AMOUNT        NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  UPDATE_ADMIN_ID VARCHAR2(32),
  AUDIT_ADMIN_ID VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK VARCHAR2(4000),
  REMARK_IS_SHOW NUMBER(1) DEFAULT 0            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_BALANCE_AUDIT IS '钱包变更审核记录';
COMMENT ON COLUMN AR_BALANCE_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_BALANCE_AUDIT.LAST_DEC_LV IS '申请时会员级别';
COMMENT ON COLUMN AR_BALANCE_AUDIT.LAST_EMP_LV IS '申请时会员聘级';
COMMENT ON COLUMN AR_BALANCE_AUDIT.LAST_DEC_ROLE_ID IS '申请时报单中心级别';
COMMENT ON COLUMN AR_BALANCE_AUDIT.TYPE IS '余额类型';
COMMENT ON COLUMN AR_BALANCE_AUDIT.DEAL_TYPE IS '交易类型';
COMMENT ON COLUMN AR_BALANCE_AUDIT.AMOUNT IS '金额';
COMMENT ON COLUMN AR_BALANCE_AUDIT.AUDIT_STATUS IS '状态';
COMMENT ON COLUMN AR_BALANCE_AUDIT.UPDATE_ADMIN_ID IS '变更管理员';
COMMENT ON COLUMN AR_BALANCE_AUDIT.AUDIT_ADMIN_ID IS '审核管理员';
COMMENT ON COLUMN AR_BALANCE_AUDIT.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_BALANCE_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_BALANCE_AUDIT.REMARK_IS_SHOW IS '前台是否展示';
COMMENT ON COLUMN AR_BALANCE_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_BALANCE_AUDIT.AUDITED_AT IS ' 审核时间';

CREATE INDEX AR_BALANCE_AUDIT_TYPE_INDEX ON AR_BALANCE_AUDIT(TYPE);
CREATE INDEX AR_BALANCE_AUDIT_STATUS_INDEX ON AR_BALANCE_AUDIT(AUDIT_STATUS);

-- 总奖金流水
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_BONUS';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_BONUS
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  CALC_ID       VARCHAR2(32),
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  TOTAL         NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  IS_INCR       NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  REMARK_IS_SHOW NUMBER(1) DEFAULT 1            NOT NULL,
  DEAL_TYPE_ID VARCHAR2(32),
  DEAL_TYPE_IS_PRESET    NUMBER(1) DEFAULT 1            NOT NULL,
  ADMIN_NAME    VARCHAR2(32),
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  P_MONTH       DATE                            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  DELETED       NUMBER(1) DEFAULT 0             NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  TRANSFER_SN   VARCHAR2(32) DEFAULT '',
  SORT    NUMBER(10) DEFAULT 0            NOT NULL,
  AUTO_SORT NUMBER generated as identity
)
PARTITION BY RANGE(P_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_FLOW_BONUS IS '总奖金流水';
COMMENT ON COLUMN AR_FLOW_BONUS.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_FLOW_BONUS.LAST_DEC_LV IS '记录时会员级别';
COMMENT ON COLUMN AR_FLOW_BONUS.LAST_EMP_LV IS '记录时会员聘级';
COMMENT ON COLUMN AR_FLOW_BONUS.LAST_STATUS IS '记录时状态';
COMMENT ON COLUMN AR_FLOW_BONUS.CALC_ID IS '奖金结算表ID';
COMMENT ON COLUMN AR_FLOW_BONUS.AMOUNT IS '金额';
COMMENT ON COLUMN AR_FLOW_BONUS.TOTAL IS '当前总金额';
COMMENT ON COLUMN AR_FLOW_BONUS.IS_INCR IS '是否增加';
COMMENT ON COLUMN AR_FLOW_BONUS.REMARK IS '备注';
COMMENT ON COLUMN AR_FLOW_BONUS.REMARK_IS_SHOW IS '备注是否显示';
COMMENT ON COLUMN AR_FLOW_BONUS.DEAL_TYPE_ID IS '交易类型ID';
COMMENT ON COLUMN AR_FLOW_BONUS.DEAL_TYPE_IS_PRESET IS '交易类型是否预置';
COMMENT ON COLUMN AR_FLOW_BONUS.ADMIN_NAME IS '操作人名称';
COMMENT ON COLUMN AR_FLOW_BONUS.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_FLOW_BONUS.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_FLOW_BONUS.P_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_FLOW_BONUS.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_FLOW_BONUS.DELETED IS '是否删除';
COMMENT ON COLUMN AR_FLOW_BONUS.DELETED_AT IS '删除时间';
COMMENT ON COLUMN AR_FLOW_BONUS.TRANSFER_SN IS '转账流水号';
COMMENT ON COLUMN AR_FLOW_BONUS.SORT IS '排序';
COMMENT ON COLUMN AR_FLOW_BONUS.AUTO_SORT IS '自增排序';

-- 车房奖流水
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_CF';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_CF
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  TOTAL         NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  IS_INCR       NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  REMARK_IS_SHOW NUMBER(1) DEFAULT 1            NOT NULL,
  DEAL_TYPE_ID VARCHAR2(32),
  DEAL_TYPE_IS_PRESET    NUMBER(1) DEFAULT 1            NOT NULL,
  ADMIN_NAME    VARCHAR2(32),
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  P_MONTH       DATE                            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  DELETED       NUMBER(1) DEFAULT 0             NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL
)
  PARTITION BY RANGE(P_MONTH)
  INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_FLOW_CF IS '车房养老奖流水';
COMMENT ON COLUMN AR_FLOW_CF.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_FLOW_CF.LAST_DEC_LV IS '记录时会员级别';
COMMENT ON COLUMN AR_FLOW_CF.LAST_EMP_LV IS '记录时会员聘级';
COMMENT ON COLUMN AR_FLOW_CF.LAST_STATUS IS '记录时状态';
COMMENT ON COLUMN AR_FLOW_CF.AMOUNT IS '金额';
COMMENT ON COLUMN AR_FLOW_CF.TOTAL IS '当前总金额';
COMMENT ON COLUMN AR_FLOW_CF.IS_INCR IS '是否增加';
COMMENT ON COLUMN AR_FLOW_CF.REMARK IS '备注';
COMMENT ON COLUMN AR_FLOW_CF.REMARK_IS_SHOW IS '备注是否显示';
COMMENT ON COLUMN AR_FLOW_CF.DEAL_TYPE_ID IS '交易类型ID';
COMMENT ON COLUMN AR_FLOW_CF.DEAL_TYPE_IS_PRESET IS '交易类型是否预置';
COMMENT ON COLUMN AR_FLOW_CF.ADMIN_NAME IS '操作人名称';
COMMENT ON COLUMN AR_FLOW_CF.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_FLOW_CF.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_FLOW_CF.P_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_FLOW_CF.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_FLOW_CF.DELETED IS '是否删除';
COMMENT ON COLUMN AR_FLOW_CF.DELETED_AT IS '删除时间';

CREATE INDEX AR_FLOW_CF_USER_ID_INDEX ON AR_FLOW_CF(USER_ID);

-- 领袖分红奖流水
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_LX';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_LX
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  TOTAL         NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  IS_INCR       NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  REMARK_IS_SHOW NUMBER(1) DEFAULT 1            NOT NULL,
  DEAL_TYPE_ID VARCHAR2(32),
  DEAL_TYPE_IS_PRESET    NUMBER(1) DEFAULT 1            NOT NULL,
  ADMIN_NAME    VARCHAR2(32),
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  P_MONTH       DATE                            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  DELETED       NUMBER(1) DEFAULT 0             NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL
)
  PARTITION BY RANGE(P_MONTH)
  INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_FLOW_LX IS '领袖分红奖流水';
COMMENT ON COLUMN AR_FLOW_LX.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_FLOW_LX.LAST_DEC_LV IS '记录时会员级别';
COMMENT ON COLUMN AR_FLOW_LX.LAST_EMP_LV IS '记录时会员聘级';
COMMENT ON COLUMN AR_FLOW_LX.LAST_STATUS IS '记录时状态';
COMMENT ON COLUMN AR_FLOW_LX.AMOUNT IS '金额';
COMMENT ON COLUMN AR_FLOW_LX.TOTAL IS '当前总金额';
COMMENT ON COLUMN AR_FLOW_LX.IS_INCR IS '是否增加';
COMMENT ON COLUMN AR_FLOW_LX.REMARK IS '备注';
COMMENT ON COLUMN AR_FLOW_LX.REMARK_IS_SHOW IS '备注是否显示';
COMMENT ON COLUMN AR_FLOW_LX.DEAL_TYPE_ID IS '交易类型ID';
COMMENT ON COLUMN AR_FLOW_LX.DEAL_TYPE_IS_PRESET IS '交易类型是否预置';
COMMENT ON COLUMN AR_FLOW_LX.ADMIN_NAME IS '操作人名称';
COMMENT ON COLUMN AR_FLOW_LX.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_FLOW_LX.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_FLOW_LX.P_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_FLOW_LX.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_FLOW_LX.DELETED IS '是否删除';
COMMENT ON COLUMN AR_FLOW_LX.DELETED_AT IS '删除时间';

CREATE INDEX AR_FLOW_LX_USER_ID_INDEX ON AR_FLOW_LX(USER_ID);

-- 历史奖金余额
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_HISTORY_BONUS';
EXCEPTION
    WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_HISTORY_BONUS
(
    ID        VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID VARCHAR2(32) NOT NULL,
    USER_NAME VARCHAR2(32) NOT NULL,
    REAL_NAME VARCHAR2(32) NOT NULL,
    DEC_LV VARCHAR2(32) NOT NULL,
    EMP_LV VARCHAR2(32) NOT NULL,
    IS_DEC NUMBER(1) DEFAULT 0 NOT NULL,
    DEC_ROLE_ID VARCHAR2(32) DEFAULT '',
    SYSTEM_NAME VARCHAR2(32) DEFAULT '',
    BONUS NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    CF NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    LX NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    WITHDRAW NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    WITHDRAW_TAX NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    WITHDRAW_DEDUCT NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    WITHDRAW_REAL NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    WITHDRAW_FAIL NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    USER_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
    USER_STATUS_AT NUMBER(10) DEFAULT 0 NOT NULL,
    HIGHEST_EMP_LV VARCHAR2(32) DEFAULT '',
    PERIOD_AT VARCHAR2(32) DEFAULT '',
    DEC_DEC_ROLE_ID VARCHAR2(32) DEFAULT '',
    DEC_USER_NAME VARCHAR2(32) DEFAULT '',
    DEC_REAL_NAME VARCHAR2(32) DEFAULT '',
    MOBILE VARCHAR2(11) DEFAULT '',
    TEL VARCHAR2(11) DEFAULT '',
    PROVINCE NUMBER(10) DEFAULT 0 NOT NULL,
    CITY NUMBER(10) DEFAULT 0 NOT NULL,
    COUNTY NUMBER(10) DEFAULT 0 NOT NULL,
    SUB_COM_ID VARCHAR2(32) DEFAULT '',
    IS_DIRECT_SELLER NUMBER(1) DEFAULT 0 NOT NULL,
    BACKUP_AT NUMBER (10) DEFAULT 0 NOT NULL,
    PARTITION_DATE        DATE           DEFAULT SYSDATE NOT NULL
)
    PARTITION BY RANGE (PARTITION_DATE)
    INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
(
    PARTITION AR_HISTORY_BONUS_P1 VALUES LESS THAN (TO_DATE('2019-07-01', 'YYYY-MM-DD'))
);
CREATE INDEX AR_HISTORY_BONUS_UID ON AR_HISTORY_BONUS (USER_ID) LOCAL;
COMMENT ON TABLE AR_HISTORY_BONUS IS '历史奖金余额';
COMMENT ON COLUMN AR_HISTORY_BONUS.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_HISTORY_BONUS.USER_NAME IS '会员编号';
COMMENT ON COLUMN AR_HISTORY_BONUS.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_HISTORY_BONUS.DEC_LV IS '会员级别';
COMMENT ON COLUMN AR_HISTORY_BONUS.EMP_LV IS '聘级';
COMMENT ON COLUMN AR_HISTORY_BONUS.IS_DEC IS '是否报单中心';
COMMENT ON COLUMN AR_HISTORY_BONUS.DEC_ROLE_ID IS '报单中心级别';
COMMENT ON COLUMN AR_HISTORY_BONUS.SYSTEM_NAME IS '体系名称';
COMMENT ON COLUMN AR_HISTORY_BONUS.BONUS IS '奖金';
COMMENT ON COLUMN AR_HISTORY_BONUS.CF IS '车房养老余额';
COMMENT ON COLUMN AR_HISTORY_BONUS.LX IS '领袖分红余额';
COMMENT ON COLUMN AR_HISTORY_BONUS.WITHDRAW IS '提现金额';
COMMENT ON COLUMN AR_HISTORY_BONUS.WITHDRAW_TAX IS '个税';
COMMENT ON COLUMN AR_HISTORY_BONUS.WITHDRAW_DEDUCT IS '扣款';
COMMENT ON COLUMN AR_HISTORY_BONUS.WITHDRAW_REAL IS '实付金额';
COMMENT ON COLUMN AR_HISTORY_BONUS.WITHDRAW_FAIL IS '实付失败金额';
COMMENT ON COLUMN AR_HISTORY_BONUS.USER_STATUS IS '会员状态';
COMMENT ON COLUMN AR_HISTORY_BONUS.USER_STATUS_AT IS '会员状态变更时间';
COMMENT ON COLUMN AR_HISTORY_BONUS.HIGHEST_EMP_LV IS '历史最高聘级';
COMMENT ON COLUMN AR_HISTORY_BONUS.PERIOD_AT IS '加入期数';
COMMENT ON COLUMN AR_HISTORY_BONUS.DEC_DEC_ROLE_ID IS '所属报单中心级别';
COMMENT ON COLUMN AR_HISTORY_BONUS.DEC_USER_NAME IS '所属报单中心编号';
COMMENT ON COLUMN AR_HISTORY_BONUS.DEC_REAL_NAME IS '所属报单中心姓名';
COMMENT ON COLUMN AR_HISTORY_BONUS.MOBILE IS '手机号';
COMMENT ON COLUMN AR_HISTORY_BONUS.TEL IS '备用手机号码';
COMMENT ON COLUMN AR_HISTORY_BONUS.PROVINCE IS '省份';
COMMENT ON COLUMN AR_HISTORY_BONUS.CITY IS '城市';
COMMENT ON COLUMN AR_HISTORY_BONUS.COUNTY IS '地区';
COMMENT ON COLUMN AR_HISTORY_BONUS.SUB_COM_ID IS '所属分公司';
COMMENT ON COLUMN AR_HISTORY_BONUS.IS_DIRECT_SELLER IS '是否直销员';
COMMENT ON COLUMN AR_HISTORY_BONUS.BACKUP_AT IS '备份时间';
COMMENT ON COLUMN AR_HISTORY_BONUS.PARTITION_DATE IS '分区日期';


-- 全部奖金结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_USER_NAME        VARCHAR2(16)                    NOT NULL,
    LAST_REAL_NAME        VARCHAR2(128)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    LAST_MOBILE           VARCHAR2(11) DEFAULT '',
    LAST_PERIOD_AT NUMBER(10) DEFAULT 0 NOT NULL,
    LAST_CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    LAST_SUB_COM_ID       VARCHAR2(32) DEFAULT '',
    LAST_PROVINCE    NUMBER(6) DEFAULT 0,
    LAST_CITY        NUMBER(6) DEFAULT 0,
    LAST_COUNTY      NUMBER(6) DEFAULT 0,
    LAST_SYSTEM_ID       VARCHAR2(32)                    NOT NULL,
    LAST_IS_DIRECT_SELLER NUMBER(1) DEFAULT 0 NOT NULL,
    LAST_REC_USER_NAME        VARCHAR2(16) DEFAULT '',
    LAST_REC_REAL_NAME        VARCHAR2(128) DEFAULT '',
    LAST_CON_USER_NAME        VARCHAR2(16) DEFAULT '',
    LAST_CON_REAL_NAME        VARCHAR2(128) DEFAULT '',
    LAST_LOCATION    NUMBER(1)                       NOT NULL,
    BONUS_QY      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_YC      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_FX      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_LS      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_FW      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_BT      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_BT_PROD      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_BT_TOOL      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    DEDUCT_ZR     NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_FL      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_CF      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    BONUS_LX      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    SHOULD_QY     NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    SHOULD_DEDUCT_ZR     NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PV_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_PCS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_LS_TOUCH        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_LS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_LS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_TOUCH        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    BONUS_TOTAL        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    BONUS_INCOME        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    CALCULATED_AT NUMBER(10)                      NOT NULL,
    IS_SENT       NUMBER(1) DEFAULT 0             NOT NULL,
    SENT_AT       NUMBER(10) DEFAULT 0            NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    CREATED_AT    NUMBER(10)                      NOT NULL,
    BONUS_QY_MONTH        NUMBER(16,3) DEFAULT 0.000       NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS IS '总奖金结算记录';
COMMENT ON COLUMN AR_CALC_BONUS.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_USER_NAME IS '结算时会员编号';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_REAL_NAME IS '结算时会员姓名';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_MOBILE IS '结算时手机号码';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_PERIOD_AT IS '结算时加入期数';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_CREATED_AT IS '结算时加入时间';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_SUB_COM_ID IS '结算时所属分公司';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_PROVINCE IS '结算时所属省份';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_CITY IS '结算时所属城市';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_COUNTY IS '结算时所属地区';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_SYSTEM_ID IS '结算时体系';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_IS_DIRECT_SELLER IS '结算时是否直销员';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_REC_USER_NAME IS '结算时开拓者编号';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_REC_REAL_NAME IS '结算时开拓者姓名';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_CON_USER_NAME IS '结算时上级编号';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_CON_REAL_NAME IS '结算时上级姓名';
COMMENT ON COLUMN AR_CALC_BONUS.LAST_LOCATION IS '结算时市场';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_QY IS '区域津贴';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_YC IS '育成津贴';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_FX IS '复销奖';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_LS IS '零售奖';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_FW IS '区级店业绩提成';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_BT IS '店补';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_BT_PROD IS '产品补贴';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_BT_TOOL IS '工具流补贴';
COMMENT ON COLUMN AR_CALC_BONUS.DEDUCT_ZR IS '责任业绩扣除';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_FL IS '形象店货补';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_CF IS '车房养老奖';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_LX IS '领袖分红';
COMMENT ON COLUMN AR_CALC_BONUS.SHOULD_QY IS '应发区域津贴';
COMMENT ON COLUMN AR_CALC_BONUS.SHOULD_DEDUCT_ZR IS '应扣责任业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_1L IS '一市场新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.QY_1L IS '一市场区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_1L IS '一市场结余业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_2L IS '二市场新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.QY_2L IS '二市场区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_2L IS '二市场结余业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_3L IS '三市场新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.QY_3L IS '三市场区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_3L IS '三市场结余业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_4L IS '四市场新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.QY_4L IS '四市场区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_4L IS '四市场结余业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_5L IS '五市场新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.QY_5L IS '五市场区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_5L IS '五市场结余业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_PCS IS '当期零售';
COMMENT ON COLUMN AR_CALC_BONUS.PV_LS_TOUCH IS '虚拟零售区新增业绩';
COMMENT ON COLUMN AR_CALC_BONUS.SURPLUS_LS IS '虚拟零售区结余';
COMMENT ON COLUMN AR_CALC_BONUS.QY_LS IS '虚拟零售区区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS.PV_TOUCH IS '新增业绩累计';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_TOTAL IS '总奖金';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_INCOME IS '总收入';
COMMENT ON COLUMN AR_CALC_BONUS.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS.CALCULATED_AT IS '结算时间';
COMMENT ON COLUMN AR_CALC_BONUS.IS_SENT IS '是否挂网';
COMMENT ON COLUMN AR_CALC_BONUS.SENT_AT IS '挂网时间';
COMMENT ON COLUMN AR_CALC_BONUS.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_QY_MONTH IS '月区域津贴累计';

CREATE INDEX AR_CALC_BONUS_IS_SENT ON AR_CALC_BONUS(IS_SENT) LOCAL;

-- 报单中心店补补贴记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_BT';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_BT
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    FROM_USER_ID  VARCHAR2(32)                    NOT NULL,
    LAST_FROM_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    LAST_DEC_ROLE_ID      VARCHAR2(32)                 DEFAULT '',
    BT_TYPE VARCHAR2(8)     NOT NULL,
    FROM_ORDER_SN   VARCHAR2(32)                    DEFAULT '',
    ORDER_TIME    NUMBER(10)   DEFAULT 0            NOT NULL,
    ORDER_PERIOD    NUMBER(10) DEFAULT 0            NOT NULL,
    DELIVERY_AT    NUMBER(10)   DEFAULT 0            NOT NULL,
    DELIVERY_PERIOD    NUMBER(10) DEFAULT 0          NOT NULL,
    PAY_AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PAY_PV        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    TRANSFER_SN   VARCHAR2(32)                    DEFAULT '',
    TRANSFER_AMOUNT   NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    TRANSFER_AT   NUMBER(10)   DEFAULT 0            NOT NULL,
    TRANSFER_PERIOD   NUMBER(10)   DEFAULT 0            NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_BT IS '报单中心店补补贴记录';
COMMENT ON COLUMN AR_CALC_BONUS_BT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_STATUS IS '结算时会员状态';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_DEC_ROLE_ID IS '结算时会员报单级别';
COMMENT ON COLUMN AR_CALC_BONUS_BT.FROM_USER_ID IS '来源会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_FROM_DEC_LV IS '结算时来源会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_FROM_EMP_LV IS '结算时来源会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LAST_FROM_STATUS IS '结算时来源会员状态';
COMMENT ON COLUMN AR_CALC_BONUS_BT.BT_TYPE IS '补贴类型';
COMMENT ON COLUMN AR_CALC_BONUS_BT.FROM_ORDER_SN IS '来源订单编号';
COMMENT ON COLUMN AR_CALC_BONUS_BT.ORDER_TIME IS '订货时间';
COMMENT ON COLUMN AR_CALC_BONUS_BT.ORDER_PERIOD IS '订货期数';
COMMENT ON COLUMN AR_CALC_BONUS_BT.DELIVERY_AT IS '发货时间';
COMMENT ON COLUMN AR_CALC_BONUS_BT.DELIVERY_PERIOD IS '发货期数';
COMMENT ON COLUMN AR_CALC_BONUS_BT.PAY_AMOUNT IS '订货金额';
COMMENT ON COLUMN AR_CALC_BONUS_BT.PAY_PV IS '订货积分';
COMMENT ON COLUMN AR_CALC_BONUS_BT.TRANSFER_SN IS '转账记录流水号';
COMMENT ON COLUMN AR_CALC_BONUS_BT.TRANSFER_AMOUNT IS '转账金额';
COMMENT ON COLUMN AR_CALC_BONUS_BT.TRANSFER_AT IS '转账时间';
COMMENT ON COLUMN AR_CALC_BONUS_BT.TRANSFER_PERIOD IS '转账期数';
COMMENT ON COLUMN AR_CALC_BONUS_BT.AMOUNT IS '店补金额';
COMMENT ON COLUMN AR_CALC_BONUS_BT.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_BT.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_BT.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_BT.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_BT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_BT.LOGS IS '日志';

-- 车房养老结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_CF';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_CF
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_CF IS '车房养老结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_CF.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_CF.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_CF.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_CF.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_CF.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_CF.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_CF.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_CF.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_CF.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_CF.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_CF.LOGS IS '日志';

-- 货补记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_FL';
EXCEPTION
    WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_FL
(
    ID           VARCHAR2(32)  DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID      VARCHAR2(32)                     NOT NULL,
    LAST_DEC_ROLE_ID      VARCHAR2(32)                     NOT NULL,
    DEC_SN     VARCHAR2(32)                     NOT NULL,
    TO_USER_ID VARCHAR2(32)                     NOT NULL,
    DEC_AT       NUMBER(10) DEFAULT 0      NOT NULL,
    DEC_PERIOD       NUMBER(10) DEFAULT 0      NOT NULL,
    DEC_AMOUNT       NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    DEC_PV       NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    AMOUNT       NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    PERIOD_NUM   NUMBER(10)                       NOT NULL,
    CALC_YEAR    NUMBER(10)                       NOT NULL,
    CALC_MONTH   NUMBER(10)                       NOT NULL,
    P_CALC_MONTH DATE                             NOT NULL,
    ORDER_PV     NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT   NUMBER(10)                       NOT NULL
)
    PARTITION BY RANGE (P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01', 'YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_FL IS '货补记录';
COMMENT ON COLUMN AR_CALC_BONUS_FL.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FL.LAST_DEC_ROLE_ID IS '结算时报单级别';
COMMENT ON COLUMN AR_CALC_BONUS_FL.DEC_SN IS '报单编号';
COMMENT ON COLUMN AR_CALC_BONUS_FL.TO_USER_ID IS '被报单会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FL.DEC_AT IS '报单时间';
COMMENT ON COLUMN AR_CALC_BONUS_FL.DEC_PERIOD IS '报单期数';
COMMENT ON COLUMN AR_CALC_BONUS_FL.DEC_AMOUNT IS '报单金额';
COMMENT ON COLUMN AR_CALC_BONUS_FL.DEC_PV IS '报单PV';
COMMENT ON COLUMN AR_CALC_BONUS_FL.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_FL.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_FL.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_FL.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_FL.ORDER_PV IS '区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS_FL.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_FL.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_FL.LOGS IS '日志';

-- 区级店业绩提成结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_FW';
EXCEPTION
    WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_FW
(
    ID           VARCHAR2(32)  DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID      VARCHAR2(32)                     NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    LAST_DEC_ROLE_ID   VARCHAR2(32)                    DEFAULT '',
    FROM_USER_ID VARCHAR2(32)                     NOT NULL,
    LAST_FROM_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    LAST_FROM_DEC_ROLE_ID   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_PROVINCE    NUMBER(6) DEFAULT 0,
    LAST_FROM_CITY        NUMBER(6) DEFAULT 0,
    LAST_FROM_COUNTY      NUMBER(6) DEFAULT 0,
    FROM_ORDER_SN   VARCHAR2(32)                    DEFAULT '',
    ORDER_TIME    NUMBER(10)   DEFAULT 0            NOT NULL,
    ORDER_PERIOD    NUMBER(10) DEFAULT 0            NOT NULL,
    DELIVERY_AT    NUMBER(10)   DEFAULT 0            NOT NULL,
    DELIVERY_PERIOD    NUMBER(10) DEFAULT 0          NOT NULL,
    PAY_AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PAY_PV        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    ORDER_PV     NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    AMOUNT       NUMBER(16, 3) DEFAULT 0.000      NOT NULL,
    PERIOD_NUM   NUMBER(10)                       NOT NULL,
    CALC_YEAR    NUMBER(10)                       NOT NULL,
    CALC_MONTH   NUMBER(10)                       NOT NULL,
    P_CALC_MONTH DATE                             NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT   NUMBER(10)                       NOT NULL
)
    PARTITION BY RANGE (P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01', 'YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_FW IS '区级店业绩提成结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_FW.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_DEC_ROLE_ID IS '结算时会员报单中心级别';
COMMENT ON COLUMN AR_CALC_BONUS_FW.FROM_USER_ID IS '来源会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_DEC_LV IS '结算时来源会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_EMP_LV IS '结算时来源会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_STATUS IS '结算时来源状态';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_DEC_ROLE_ID IS '结算时来源会员报单中心级别';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_PROVINCE IS '结算时来源省市';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_CITY IS '结算时来源城市';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LAST_FROM_COUNTY IS '结算时来源地区';
COMMENT ON COLUMN AR_CALC_BONUS_FW.FROM_ORDER_SN IS '来源订单编号';
COMMENT ON COLUMN AR_CALC_BONUS_FW.ORDER_TIME IS '订货时间';
COMMENT ON COLUMN AR_CALC_BONUS_FW.ORDER_PERIOD IS '订货期数';
COMMENT ON COLUMN AR_CALC_BONUS_FW.DELIVERY_AT IS '发货时间';
COMMENT ON COLUMN AR_CALC_BONUS_FW.DELIVERY_PERIOD IS '发货期数';
COMMENT ON COLUMN AR_CALC_BONUS_FW.PAY_AMOUNT IS '订货金额';
COMMENT ON COLUMN AR_CALC_BONUS_FW.PAY_PV IS '订货积分';
COMMENT ON COLUMN AR_CALC_BONUS_FW.ORDER_PV IS '提供区域业绩';
COMMENT ON COLUMN AR_CALC_BONUS_FW.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_FW.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_FW.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_FW.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_FW.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_FW.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_FW.LOGS IS '日志';

-- 复销奖结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_FX';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_FX
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    FROM_USER_ID  VARCHAR2(32)                    NOT NULL,
    LAST_FROM_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    DEEP          NUMBER(10)                      NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_FX IS '复销奖结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_FX.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_FX.FROM_USER_ID IS '来源会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_FROM_DEC_LV IS '结算时来源会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_FROM_EMP_LV IS '结算时来源会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LAST_FROM_STATUS IS '结算时来源状态';
COMMENT ON COLUMN AR_CALC_BONUS_FX.DEEP IS '深度';
COMMENT ON COLUMN AR_CALC_BONUS_FX.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_FX.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_FX.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_FX.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_FX.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_FX.LOGS IS '日志';

-- 零售结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_LS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_LS
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_LS IS '零售结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_LS.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_LS.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_LS.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_LS.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_LS.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_LS.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_LS.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_LS.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_LS.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_LS.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_LS.LOGS IS '日志';

-- 领袖分红结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_LX';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_LX
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_LX IS '领袖分红结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_LX.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_LX.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_LX.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_LX.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_LX.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_LX.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_LX.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_LX.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_LX.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_LX.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_LX.LOGS IS '日志';

-- 区域津贴结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_QY';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_QY
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_QY IS '区域津贴结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_QY.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_QY.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_QY.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_QY.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_QY.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_QY.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_QY.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_CALC_BONUS_QY.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_QY.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_QY.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_QY.LOGS IS '日志';

-- 育成津贴结算记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_YC';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_YC
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    FROM_USER_ID  VARCHAR2(32)                    NOT NULL,
    LAST_FROM_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_FROM_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    DEEP          NUMBER(10)                      NOT NULL,
    AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_CALC_BONUS_YC IS '育成津贴结算记录';
COMMENT ON COLUMN AR_CALC_BONUS_YC.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_CALC_BONUS_YC.FROM_USER_ID IS '来源会员ID';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_FROM_DEC_LV IS '结算时来源会员级别';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_FROM_EMP_LV IS '结算时来源会员聘级';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LAST_FROM_STATUS IS '结算时来源状态';
COMMENT ON COLUMN AR_CALC_BONUS_YC.DEEP IS '深度';
COMMENT ON COLUMN AR_CALC_BONUS_YC.AMOUNT IS '奖金金额';
COMMENT ON COLUMN AR_CALC_BONUS_YC.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_CALC_BONUS_YC.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_CALC_BONUS_YC.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_CALC_BONUS_YC.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CALC_BONUS_YC.LOGS IS '日志';



-- 责任业绩扣除记录
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_DEDUCT_ZR';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_DEDUCT_ZR
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    ZR  NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    LOGS   VARCHAR2(2000)   DEFAULT '',
    SURPLUS_BONUS        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    P_CALC_MONTH  DATE                            NOT NULL,
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_FLOW_DEDUCT_ZR IS '责任业绩扣除记录';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.LAST_DEC_LV IS '记录时会员级别';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.LAST_EMP_LV IS '记录时会员聘级';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.LAST_STATUS IS '记录时状态';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.ZR IS '责任业绩';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.SURPLUS_BONUS IS '剩余奖金';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_FLOW_DEDUCT_ZR.LOGS IS '日志';

-- 短信模板
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_SMS_TEMPLATE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_SMS_TEMPLATE
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TITLE         VARCHAR2(32)                    NOT NULL,
  DESCRIPTION   VARCHAR2(255)                   NOT NULL,
  FIELD         VARCHAR2(255)                   NOT NULL,
  DEC_LEVEL     VARCHAR2(32),
  EMP_LEVEL     VARCHAR2(32),
  CONTENT       VARCHAR2(255)                   NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_SMS_TEMPLATE IS '短信模板';
COMMENT ON COLUMN AR_SMS_TEMPLATE.TITLE IS '标题';
COMMENT ON COLUMN AR_SMS_TEMPLATE.DESCRIPTION IS '描述';
COMMENT ON COLUMN AR_SMS_TEMPLATE.FIELD IS '标题英文字段';
COMMENT ON COLUMN AR_SMS_TEMPLATE.DEC_LEVEL IS '报单级别';
COMMENT ON COLUMN AR_SMS_TEMPLATE.EMP_LEVEL IS '聘级';
COMMENT ON COLUMN AR_SMS_TEMPLATE.CONTENT IS '模板内容';
COMMENT ON COLUMN AR_SMS_TEMPLATE.CREATED_AT IS '创建时间';

INSERT INTO AR_SMS_TEMPLATE (ID, TITLE, DESCRIPTION, FIELD, DEC_LEVEL, EMP_LEVEL, CONTENT, CREATED_AT) VALUES ('A8563B1832CB4B1B95145974B60574C5', '注册成功', '首购报单完成后给新注册的会员发送注册成功短信', 'REG_SUCCESS','67AB99FDC4B6501CE055736AECE8644D', null, '尊敬的{REAL_NAME}，您已注册成功，用户名：{USER_NAME}，报单金额{AMOUNT}', 1526002387);
INSERT INTO AR_SMS_TEMPLATE (ID, TITLE, DESCRIPTION, FIELD, DEC_LEVEL, EMP_LEVEL, CONTENT, CREATED_AT) VALUES ('651074FEE2804DE695CDB00EDED342B0', '注册成功', '首购报单完成后给新注册的会员发送注册成功短信', 'REG_SUCCESS', '67ABCB8C1F7D5519E055736AECE8644D', null, '尊敬的{REAL_NAME}，您已注册成功，用户名：{USER_NAME}，报单金额{AMOUNT}', 1526002387);
INSERT INTO AR_SMS_TEMPLATE (ID, TITLE, DESCRIPTION, FIELD, DEC_LEVEL, EMP_LEVEL, CONTENT, CREATED_AT) VALUES ('F8A46347B7014701B61B77034A7AE3BA', '注册成功', '首购报单完成后给新注册的会员发送注册成功短信', 'REG_SUCCESS', '67ABCCE20A9F5553E055736AECE8644D', null, '尊敬的{REAL_NAME}，您已注册成功，用户名：{USER_NAME}，报单金额{AMOUNT}', 1526002387);
INSERT INTO AR_SMS_TEMPLATE (ID, TITLE, DESCRIPTION, FIELD, DEC_LEVEL, EMP_LEVEL, CONTENT, CREATED_AT) VALUES ('FEA004EDB52347D99869B2E8B61C7C3D', '注册成功', '首购报单完成后给新注册的会员发送注册成功短信', 'REG_SUCCESS', '67ABCE0ECE705575E055736AECE8644D', null, '尊敬的{REAL_NAME}，您已注册成功，用户名：{USER_NAME}，报单金额{AMOUNT}', 1526002387);
COMMIT;

-- 提现金额等级设置
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_WITHDRAW_LEVEL';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_WITHDRAW_LEVEL
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TYPE          VARCHAR2(32)                    NOT NULL,
  MIN_AMOUNT    NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  MAX_AMOUNT    NUMBER(16,2),
  TAX_PERCENT   NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_WITHDRAW_LEVEL IS '提现金额等级';
COMMENT ON COLUMN AR_WITHDRAW_LEVEL.TYPE IS '注册类型';
COMMENT ON COLUMN AR_WITHDRAW_LEVEL.MIN_AMOUNT IS '最小金额';
COMMENT ON COLUMN AR_WITHDRAW_LEVEL.MAX_AMOUNT IS '最大金额';
COMMENT ON COLUMN AR_WITHDRAW_LEVEL.TAX_PERCENT IS '税金比率';
COMMENT ON COLUMN AR_WITHDRAW_LEVEL.CREATED_AT IS '创建时间';

INSERT INTO AR_WITHDRAW_LEVEL (ID, TYPE, MIN_AMOUNT, MAX_AMOUNT, TAX_PERCENT, CREATED_AT) VALUES ('BE062D2EDA204B16B31DF8B06189AD07', '56D9181C0F5D428FA2DBD4CAB263BF2F', 0.00, 2000.00, 5.00, 1523435526);
INSERT INTO AR_WITHDRAW_LEVEL (ID, TYPE, MIN_AMOUNT, MAX_AMOUNT, TAX_PERCENT, CREATED_AT) VALUES ('7671AA8CA8DE4BF39C00BB5558416EAB', '56D9181C0F5D428FA2DBD4CAB263BF2F', 2001.00, 5000.00, 2.00, 1523435514);
INSERT INTO AR_WITHDRAW_LEVEL (ID, TYPE, MIN_AMOUNT, MAX_AMOUNT, TAX_PERCENT, CREATED_AT) VALUES ('89CFFF1D53464165B173ED9B48AEC0C3', '56D9181C0F5D428FA2DBD4CAB263BF2F', 5001.00, null, 1.00, 1523437783);
COMMIT;

-- 上传文件列表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_UPLOADS';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_UPLOADS
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  FILE_NAME     VARCHAR2(255)                   NOT NULL,
  CATEGORY      VARCHAR2(255)                   NOT NULL,
  REMARK        VARCHAR2(255),
  URL           VARCHAR2(1000)                  NOT NULL,
  FILE_SIZE     VARCHAR2(255),
  MD5           VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_UPLOADS IS '上传文件表';
COMMENT ON COLUMN AR_UPLOADS.FILE_NAME IS '文件名称';
COMMENT ON COLUMN AR_UPLOADS.CATEGORY IS '分类';
COMMENT ON COLUMN AR_UPLOADS.REMARK IS '备注';
COMMENT ON COLUMN AR_UPLOADS.URL IS '文件路径';
COMMENT ON COLUMN AR_UPLOADS.FILE_SIZE IS '文件大小';
COMMENT ON COLUMN AR_UPLOADS.MD5 IS 'MD5值';
COMMENT ON COLUMN AR_UPLOADS.CREATED_AT IS '创建时间';

CREATE INDEX AR_UPLOADS_CATEGORY ON AR_UPLOADS(CATEGORY);

-- 导出文件管理表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXPORT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXPORT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  EXPORT_NAME   VARCHAR2(255)                   NOT NULL,
  MODULE_NAME   VARCHAR2(255)                   NOT NULL,
  REMARK        VARCHAR2(255),
  IS_EXPORTING  NUMBER(1) DEFAULT 0             NOT NULL,
  ADMIN_ID      VARCHAR2(32),
  EXPORT_PERCENT NUMBER(16,2) DEFAULT 0.00      NOT NULL,
  STARTED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  ENDED_AT      NUMBER(10) DEFAULT 0            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  FILE_NAME     VARCHAR2(255) DEFAULT '',
  REMOTE_URL    VARCHAR2(2000) DEFAULT  '',
  FILE_SIZE     NUMBER(16) DEFAULT 0 NOT NULL,
  UPDATER      VARCHAR2(16),
  UPDATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_EXPORT IS '导出表';
COMMENT ON COLUMN AR_EXPORT.EXPORT_NAME IS '导出名称';
COMMENT ON COLUMN AR_EXPORT.MODULE_NAME IS '模块名称';
COMMENT ON COLUMN AR_EXPORT.REMARK IS '备注';
COMMENT ON COLUMN AR_EXPORT.IS_EXPORTING IS '正在导出';
COMMENT ON COLUMN AR_EXPORT.ADMIN_ID IS '管理员ID';
COMMENT ON COLUMN AR_EXPORT.EXPORT_PERCENT IS '导出进度';
COMMENT ON COLUMN AR_EXPORT.STARTED_AT IS '导出开始时间';
COMMENT ON COLUMN AR_EXPORT.ENDED_AT IS '导出完成时间';
COMMENT ON COLUMN AR_EXPORT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_EXPORT.UPDATER IS '更新人';
COMMENT ON COLUMN AR_EXPORT.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_EXPORT.FILE_SIZE IS '文件大小';
COMMENT ON COLUMN AR_EXPORT.REMOTE_URL IS '远程url';
COMMENT ON COLUMN AR_EXPORT.FILE_NAME IS '文件名称';

CREATE UNIQUE INDEX AR_EXPORT_E_N_UI ON AR_EXPORT(EXPORT_NAME);
CREATE INDEX AR_EXPORT_M_N_I ON AR_EXPORT(MODULE_NAME);

-- 导出对应的文件表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXPORT_FILE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXPORT_FILE
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  FILE_NAME     VARCHAR2(255)                   NOT NULL,
  EXPORT_ID     VARCHAR2(32)                    NOT NULL,
  URL           VARCHAR2(1000) ,
  FILE_SIZE     VARCHAR2(255),
  MD5           VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_EXPORT_FILE IS '导出文件表';
COMMENT ON COLUMN AR_EXPORT_FILE.FILE_NAME IS '文件名称';
COMMENT ON COLUMN AR_EXPORT_FILE.EXPORT_ID IS '对应导出的ID';
COMMENT ON COLUMN AR_EXPORT_FILE.URL IS '文件路径';
COMMENT ON COLUMN AR_EXPORT_FILE.FILE_SIZE IS '文件大小';
COMMENT ON COLUMN AR_EXPORT_FILE.MD5 IS 'MD5值';
COMMENT ON COLUMN AR_EXPORT_FILE.CREATED_AT IS '创建时间';

CREATE UNIQUE INDEX AR_EXPORT_FILE_F_N_UI ON AR_EXPORT_FILE(FILE_NAME);

-- OCR识别接口表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_OCR_API';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_OCR_API
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  API_NAME      VARCHAR2(48)                   NOT NULL,
  DESCRIPTION   VARCHAR2(255)                   NOT NULL,
  CONFIG        VARCHAR2(4000),
  STATUS        NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  UPDATE_ADMIN   VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  UPDATED_AT    NUMBER(10) DEFAULT 0
);
COMMENT ON TABLE AR_OCR_API IS 'OCR识别接口表';
COMMENT ON COLUMN AR_OCR_API.API_NAME IS '文件名称';
COMMENT ON COLUMN AR_OCR_API.DESCRIPTION IS '分类';
COMMENT ON COLUMN AR_OCR_API.CONFIG IS '备注';
COMMENT ON COLUMN AR_OCR_API.STATUS IS '文件路径';
COMMENT ON COLUMN AR_OCR_API.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_OCR_API.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_OCR_API.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_OCR_API.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_OCR_API_API_NAME_UINDEX ON AR_OCR_API(API_NAME);

INSERT INTO AR_OCR_API (ID, API_NAME, DESCRIPTION, CONFIG, STATUS, CREATE_ADMIN, CREATED_AT) VALUES ('5955B56B0C0E465E8F0E65FBF86E5D44', 'baidu', '百度OCR识别', null, 1, '65F27BCE7FD278FFE055736AECE8644D', 1526960820);
COMMIT ;

-- SMS短信接口表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_SMS_API';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_SMS_API
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    API_NAME      VARCHAR2(48)                   NOT NULL,
    DESCRIPTION   VARCHAR2(255)                   NOT NULL,
    CONFIG        VARCHAR2(4000),
    STATUS        NUMBER(1) DEFAULT 0             NOT NULL,
    CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
    UPDATE_ADMIN   VARCHAR2(32),
    CREATED_AT    NUMBER(10)                      NOT NULL,
    UPDATED_AT    NUMBER(10) DEFAULT 0
);
COMMENT ON TABLE AR_SMS_API IS 'SMS短信接口表';
COMMENT ON COLUMN AR_SMS_API.API_NAME IS '接口名称';
COMMENT ON COLUMN AR_SMS_API.DESCRIPTION IS '描述';
COMMENT ON COLUMN AR_SMS_API.CONFIG IS '设置内容';
COMMENT ON COLUMN AR_SMS_API.STATUS IS '状态';
COMMENT ON COLUMN AR_SMS_API.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_SMS_API.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_SMS_API.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_SMS_API.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_SMS_API_API_NAME_UINDEX ON AR_SMS_API(API_NAME);



-- 文章表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_ARTICLE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ARTICLE
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TITLE         VARCHAR2(255)                   NOT NULL,
  CID           VARCHAR2(32)                   NOT NULL,
  CONTENT       CLOB,
  STATUS        NUMBER(1) DEFAULT 1             NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_ARTICLE IS '文章表';
COMMENT ON COLUMN AR_ARTICLE.TITLE IS '标题';
COMMENT ON COLUMN AR_ARTICLE.CID IS '分类ID';
COMMENT ON COLUMN AR_ARTICLE.CONTENT IS '内容';
COMMENT ON COLUMN AR_ARTICLE.STATUS IS '状态';
COMMENT ON COLUMN AR_ARTICLE.CREATED_AT IS '创建时间';

CREATE UNIQUE INDEX AR_A_TITLE_UINDEX ON AR_ARTICLE(TITLE);

-- 文章分类表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_ARTICLE_CATEGORY';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ARTICLE_CATEGORY
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  CATE_NAME     VARCHAR2(48)                    NOT NULL,
  SORT          NUMBER(2) DEFAULT 10            NOT NULL,
  STATUS        NUMBER(1) DEFAULT 1             NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_ARTICLE_CATEGORY IS '文章分类表';
COMMENT ON COLUMN AR_ARTICLE_CATEGORY.CATE_NAME IS '分类名';
COMMENT ON COLUMN AR_ARTICLE_CATEGORY.STATUS IS '状态';
COMMENT ON COLUMN AR_ARTICLE_CATEGORY.CREATED_AT IS '创建时间';

CREATE UNIQUE INDEX AR_A_C_CATE_NAME_UINDEX ON AR_ARTICLE_CATEGORY(CATE_NAME);

-- 广告位
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_AD_LOCATION';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_AD_LOCATION
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  LOCATION_NAME VARCHAR2(48)                    NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  TYPE          NUMBER(1)                       NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  UPDATE_ADMIN   VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  UPDATED_AT    NUMBER(10) DEFAULT 0
);
COMMENT ON TABLE AR_AD_LOCATION IS '广告位';
COMMENT ON COLUMN AR_AD_LOCATION.LOCATION_NAME IS '分类名';
COMMENT ON COLUMN AR_AD_LOCATION.REMARK IS '状态';
COMMENT ON COLUMN AR_AD_LOCATION.TYPE IS '类型';
COMMENT ON COLUMN AR_AD_LOCATION.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_AD_LOCATION.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_AD_LOCATION.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_AD_LOCATION.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_AD_L_LOCATION_NAME_UINDEX ON AR_AD_LOCATION(LOCATION_NAME);

INSERT INTO AR_AD_LOCATION (ID, LOCATION_NAME, REMARK, TYPE, CREATE_ADMIN, CREATED_AT) VALUES ('CF4D22A9BB6147AC8A4A655166B40827', '手机APP首页顶部广告', '手机APP首页导航栏下方的幻灯广告位', 1, '65F27BCE7FD278FFE055736AECE8644D', 1523245926);
INSERT INTO AR_AD_LOCATION (ID, LOCATION_NAME, REMARK, TYPE, CREATE_ADMIN, CREATED_AT) VALUES ('44AC521CCA2E4E21B05E131EE54A259A', '手机APP首页底部广告', '手机APP首页底部图片广告', 2, '65F27BCE7FD278FFE055736AECE8644D', 1523245926);
commit ;

-- 广告
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_AD';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_AD
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TITLE         VARCHAR2(48)                    NOT NULL,
  IMAGE         VARCHAR2(1000)                  NOT NULL,
  TYPE          NUMBER(1)                       NOT NULL,
  LID           VARCHAR2(32)                    NOT NULL,
  CONTENT       VARCHAR2(1000),
  SORT          NUMBER(2) DEFAULT 10            NOT NULL,
  STATUS        NUMBER(1) DEFAULT 1             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  UPDATE_ADMIN   VARCHAR2(32),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  UPDATED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_AD IS '广告';
COMMENT ON COLUMN AR_AD.TITLE IS '标题';
COMMENT ON COLUMN AR_AD.IMAGE IS '图片地址';
COMMENT ON COLUMN AR_AD.TYPE IS '类型';
COMMENT ON COLUMN AR_AD.LID IS '广告位ID';
COMMENT ON COLUMN AR_AD.CONTENT IS '内容';
COMMENT ON COLUMN AR_AD.SORT IS '排序';
COMMENT ON COLUMN AR_AD.STATUS IS '状态';
COMMENT ON COLUMN AR_AD.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_AD.UPDATE_ADMIN IS '更新管理员';
COMMENT ON COLUMN AR_AD.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_AD.UPDATED_AT IS '更新时间';

CREATE UNIQUE INDEX AR_AD_TITLE_UINDEX ON AR_AD(TITLE);

-- 站内信内容
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_MESSAGE_TEXT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_MESSAGE_TEXT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  TITLE         VARCHAR2(48)                    NOT NULL,
  CONTENT       VARCHAR2(4000)                  NOT NULL,
  TO_UID        VARCHAR2(32) DEFAULT '0'        NOT NULL,
  IS_DEL        NUMBER(1) DEFAULT 0             NOT NULL,
  ADMIN_ID      VARCHAR2(32)                    NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_MESSAGE_TEXT IS '站内信内容';
COMMENT ON COLUMN AR_MESSAGE_TEXT.TITLE IS '标题';
COMMENT ON COLUMN AR_MESSAGE_TEXT.CONTENT IS '内容';
COMMENT ON COLUMN AR_MESSAGE_TEXT.TO_UID IS '发给某个会员';
COMMENT ON COLUMN AR_MESSAGE_TEXT.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_MESSAGE_TEXT.ADMIN_ID IS '管理员ID';
COMMENT ON COLUMN AR_MESSAGE_TEXT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_MESSAGE_TEXT.DELETED_AT IS '删除时间';

CREATE INDEX AR_M_T_TO_UID_INDEX ON AR_MESSAGE_TEXT(TO_UID);

-- 站内信收件人拉取
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_MESSAGE';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_MESSAGE
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  TEXT_ID       VARCHAR2(32)                    NOT NULL,
  IS_READ       NUMBER(1) DEFAULT 0             NOT NULL,
  IS_DEL        NUMBER(1) DEFAULT 0             NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  READ_AT     NUMBER(10) DEFAULT 0            NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_MESSAGE IS '站内信';
COMMENT ON COLUMN AR_MESSAGE.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_MESSAGE.TEXT_ID IS '站内信内容ID';
COMMENT ON COLUMN AR_MESSAGE.IS_READ IS '是否已读';
COMMENT ON COLUMN AR_MESSAGE.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_MESSAGE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_MESSAGE.READ_AT IS '已读时间';
COMMENT ON COLUMN AR_MESSAGE.DELETED_AT IS '删除时间';

CREATE INDEX AR_M_USER_ID_INDEX ON AR_MESSAGE(USER_ID);
CREATE INDEX AR_M_IS_READ_INDEX ON AR_MESSAGE(IS_READ);
CREATE INDEX AR_M_IS_DEL_INDEX ON AR_MESSAGE(IS_DEL);

-- 业绩单
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_PERF_ORDER';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERF_ORDER
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  SN    			VARCHAR2(32)                    NOT NULL,
  DEC_SN      VARCHAR2(32),
  DEC_TYPE        VARCHAR2(32)                    NOT NULL,
  DEC_STATUS        NUMBER(1),
  USER_ID     VARCHAR2(32)                    NOT NULL,
  LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_STATUS   NUMBER(1)     DEFAULT 0,
  LAST_REC_USER_NAME        VARCHAR2(16)      DEFAULT '',
  LAST_REC_REAL_NAME        VARCHAR2(128)     DEFAULT '',
  PV          NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  DEC_AMOUNT  NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  LAST_SUB_COM_ID       VARCHAR2(32) DEFAULT '',
  LAST_PROVINCE    NUMBER(6) DEFAULT 0,
  LAST_CITY        NUMBER(6) DEFAULT 0,
  LAST_COUNTY      NUMBER(6) DEFAULT 0,
  DEC_USER_ID  VARCHAR2(32)                   DEFAULT '',
  LAST_DEC_DEC_LV   VARCHAR2(32)                    DEFAULT '',
  LAST_DEC_SUB_COM_ID       VARCHAR2(32) DEFAULT '',
  LAST_DEC_PROVINCE    NUMBER(6) DEFAULT 0,
  LAST_DEC_CITY        NUMBER(6) DEFAULT 0,
  LAST_DEC_COUNTY      NUMBER(6) DEFAULT 0,
  PERIOD_NUM  NUMBER(10)                      NOT NULL,
  CALC_MONTH  NUMBER(10)                      NOT NULL,
  P_CALC_MONTH DATE             							NOT NULL,
  CREATED_AT  NUMBER(10)                      NOT NULL,
  CLOSED_AT  NUMBER(10)                      NOT NULL
)
PARTITION BY RANGE(P_CALC_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_PERF_ORDER IS '业绩单';
COMMENT ON COLUMN AR_PERF_ORDER.SN IS '业绩单编号';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_SN IS '报单编号';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_TYPE IS '报单类型';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_STATUS IS '业绩单状态';
COMMENT ON COLUMN AR_PERF_ORDER.USER_ID IS '产生业绩会员ID';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_USER_ID IS '报单会员ID';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_STATUS IS '结算时会员状态';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_REC_USER_NAME IS '结算时开拓者编号';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_REC_REAL_NAME IS '结算时开拓者姓名';
COMMENT ON COLUMN AR_PERF_ORDER.PV IS '业绩单PV';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_AMOUNT IS '报单金额';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_SUB_COM_ID IS '结算时所属分公司';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_PROVINCE IS '结算时省份';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_CITY IS '结算时城市';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_COUNTY IS '结算时地区';
COMMENT ON COLUMN AR_PERF_ORDER.DEC_USER_ID IS '报单主体ID';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_DEC_LV IS '结算时报单主体级别';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_SUB_COM_ID IS '结算时报单主体所属分公司';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_PROVINCE IS '结算时报单主体省份';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_CITY IS '结算时报单主体城市';
COMMENT ON COLUMN AR_PERF_ORDER.LAST_DEC_COUNTY IS '结算时报单主体地区';
COMMENT ON COLUMN AR_PERF_ORDER.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_PERF_ORDER.CALC_MONTH IS '结算月';
COMMENT ON COLUMN AR_PERF_ORDER.P_CALC_MONTH IS '分区结算月';
COMMENT ON COLUMN AR_PERF_ORDER.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_PERF_ORDER.CLOSED_AT IS '置废时间';

CREATE UNIQUE INDEX AR_P_O_SN_UNINDEX ON AR_PERF_ORDER(SN);
CREATE INDEX AR_P_O_USER_ID_INDEX ON AR_PERF_ORDER(USER_ID) LOCAL;
CREATE INDEX AR_P_O_DEC_USER_ID_INDEX ON AR_PERF_ORDER(DEC_USER_ID) LOCAL;
CREATE INDEX AR_P_O_DEC_TYPE_INDEX ON AR_PERF_ORDER(DEC_TYPE) LOCAL;
CREATE INDEX AR_P_O_PERIOD_NUM_INDEX ON AR_PERF_ORDER(PERIOD_NUM) LOCAL;

-- Excel导入记录
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXCEL_IMPORT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXCEL_IMPORT
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  OPTION_NAME     VARCHAR2(32)                    NOT NULL,
  TABLE_NAME      VARCHAR2(32),
  UPLOAD_ID       VARCHAR2(32),
  AUDIT_STATUS    NUMBER(1) DEFAULT 0             NOT NULL,
  IMPORT_ADMIN_ID VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN_ID  VARCHAR2(32),
  CREATED_AT      NUMBER(10)                      NOT NULL,
  AUDITED_AT      NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_EXCEL_IMPORT IS 'Excel导入记录';
COMMENT ON COLUMN AR_EXCEL_IMPORT.OPTION_NAME IS '业务名称';
COMMENT ON COLUMN AR_EXCEL_IMPORT.TABLE_NAME IS '对应的待导入数据表名';
COMMENT ON COLUMN AR_EXCEL_IMPORT.UPLOAD_ID IS '上传文件ID';
COMMENT ON COLUMN AR_EXCEL_IMPORT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_EXCEL_IMPORT.IMPORT_ADMIN_ID IS '导入管理员ID';
COMMENT ON COLUMN AR_EXCEL_IMPORT.AUDIT_ADMIN_ID IS '审核管理员ID';
COMMENT ON COLUMN AR_EXCEL_IMPORT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_EXCEL_IMPORT.AUDITED_AT IS '审核时间';

-- 空单录入待导入表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXCEL_ADD_USER';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXCEL_ADD_USER
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  EXCEL_IMPORT_ID VARCHAR2(32)                    NOT NULL,
  USER_NAME       VARCHAR2(32),
  DEC_LV          VARCHAR2(32),
  REAL_NAME       VARCHAR2(32),
  ID_CARD         VARCHAR2(32),
  MOBILE          VARCHAR2(32),
  TEL             VARCHAR2(32),
  AREA_PROVINCE   VARCHAR2(32),
  AREA_CITY       VARCHAR2(32),
  AREA_COUNTY     VARCHAR2(32),
  ADDRESS         VARCHAR2(32),
  OPEN_BANK       VARCHAR2(32),
  BANK_ADDRESS    VARCHAR2(32),
  BANK_NO         VARCHAR2(32),
  BANK_PROVINCE   VARCHAR2(32),
  BANK_CITY       VARCHAR2(32),
  BANK_COUNTY     VARCHAR2(32),
  IS_DEC          VARCHAR2(32),
  DEC_ROLE        VARCHAR2(32),
  DEC_USER_NAME   VARCHAR2(32),
  BIRTHDAY        VARCHAR2(32),
  CON_USER_NAME   VARCHAR2(32),
  REC_USER_NAME   VARCHAR2(32),
  LOCATION        VARCHAR2(32),
  SORT            NUMBER(10)                      NOT NULL,
  STATUS          NUMBER(1) DEFAULT 0             NOT NULL,
  ERROR_REMARK    VARCHAR2(4000),
  CREATED_AT      NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_EXCEL_ADD_USER IS '空单录入待导入表';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.EXCEL_IMPORT_ID IS '导入记录表ID';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.USER_NAME IS '用户名';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.DEC_LV IS '会员级别';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.ID_CARD IS '身份证';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.MOBILE IS '手机';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.TEL IS '电话';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.AREA_PROVINCE IS '省市';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.AREA_CITY IS '市区';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.AREA_COUNTY IS '区县';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.ADDRESS IS '地址';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.OPEN_BANK IS '开户银行';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BANK_ADDRESS IS '开户行地址';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BANK_NO IS '银行账号';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BANK_PROVINCE IS '银行省市';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BANK_CITY IS '银行市区';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BANK_COUNTY IS '银行区县';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.IS_DEC IS '是否报单中心';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.DEC_ROLE IS '报单中心级别';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.DEC_USER_NAME IS '所属报单中心编号';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.BIRTHDAY IS '生日';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.CON_USER_NAME IS '接点人';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.REC_USER_NAME IS '开拓人';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.LOCATION IS '区位';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.SORT IS '序号';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.STATUS IS '状态';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.ERROR_REMARK IS '错误备注';
COMMENT ON COLUMN AR_EXCEL_ADD_USER.CREATED_AT IS '创建时间';

-- 补发区域津贴表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_RESEND_QY';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RESEND_QY
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    LAST_DEC_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_EMP_LV   VARCHAR2(32)                    DEFAULT '',
    LAST_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    LAST_SUB_COM_ID       VARCHAR2(32) DEFAULT '',
    LAST_PROVINCE    NUMBER(6) DEFAULT 0,
    LAST_CITY        NUMBER(6) DEFAULT 0,
    LAST_COUNTY      NUMBER(6) DEFAULT 0,
    LAST_SYSTEM_ID       VARCHAR2(32)                    NOT NULL,
    BONUS_QY      NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    SHOULD_QY     NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
    QY_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    QY_LS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_LS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PERIOD_NUM    NUMBER(10)                      NOT NULL,
    CALC_YEAR     NUMBER(10)                      NOT NULL,
    CALC_MONTH    NUMBER(10)                      NOT NULL,
    RESEND_STATUS   NUMBER(1)     DEFAULT 0              NOT NULL,
    RESEND_AUDIT_ID   VARCHAR2(32),
    RESEND_AUDIT_STATUS   NUMBER(1)     DEFAULT 0,
    P_CALC_MONTH  DATE                            NOT NULL,
    CREATED_AT    NUMBER(10)                      NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);

COMMENT ON TABLE AR_RESEND_QY IS '总奖金结算记录';
COMMENT ON COLUMN AR_RESEND_QY.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RESEND_QY.LAST_DEC_LV IS '结算时会员级别';
COMMENT ON COLUMN AR_RESEND_QY.LAST_EMP_LV IS '结算时会员聘级';
COMMENT ON COLUMN AR_RESEND_QY.LAST_STATUS IS '结算时状态';
COMMENT ON COLUMN AR_RESEND_QY.LAST_SUB_COM_ID IS '结算时所属分公司';
COMMENT ON COLUMN AR_RESEND_QY.LAST_PROVINCE IS '结算时所属省份';
COMMENT ON COLUMN AR_RESEND_QY.LAST_CITY IS '结算时所属城市';
COMMENT ON COLUMN AR_RESEND_QY.LAST_COUNTY IS '结算时所属地区';
COMMENT ON COLUMN AR_RESEND_QY.LAST_SYSTEM_ID IS '结算时体系';
COMMENT ON COLUMN AR_RESEND_QY.BONUS_QY IS '区域津贴';
COMMENT ON COLUMN AR_RESEND_QY.SHOULD_QY IS '应发区域津贴';
COMMENT ON COLUMN AR_RESEND_QY.QY_1L IS '一市场区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_1L IS '一市场结余业绩';
COMMENT ON COLUMN AR_RESEND_QY.QY_2L IS '二市场区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_2L IS '二市场结余业绩';
COMMENT ON COLUMN AR_RESEND_QY.QY_3L IS '三市场区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_3L IS '三市场结余业绩';
COMMENT ON COLUMN AR_RESEND_QY.QY_4L IS '四市场区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_4L IS '四市场结余业绩';
COMMENT ON COLUMN AR_RESEND_QY.QY_5L IS '五市场区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_5L IS '五市场结余业绩';
COMMENT ON COLUMN AR_RESEND_QY.QY_LS IS '虚拟零售区区域业绩';
COMMENT ON COLUMN AR_RESEND_QY.SURPLUS_LS IS '虚拟零售区结余';
COMMENT ON COLUMN AR_RESEND_QY.PERIOD_NUM IS '结算期数';
COMMENT ON COLUMN AR_RESEND_QY.CALC_YEAR IS '所在结算年';
COMMENT ON COLUMN AR_RESEND_QY.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_RESEND_QY.RESEND_STATUS IS '补发状态';
COMMENT ON COLUMN AR_RESEND_QY.RESEND_AUDIT_ID IS '审核对应ID';
COMMENT ON COLUMN AR_RESEND_QY.RESEND_AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_RESEND_QY.P_CALC_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_RESEND_QY.CREATED_AT IS '创建时间';

CREATE INDEX AR_RESEND_QY_UID ON AR_RESEND_QY (USER_ID);

-- 补发区域津贴审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_RESEND_QY_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RESEND_QY_AUDIT
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID         VARCHAR2(32)                    NOT NULL,
  RESEND_ID         VARCHAR2(32)                    NOT NULL,
  SHOULD_BONUS    NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  RESEND_BONUS    NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  PERIOD_NUM      NUMBER(10)                      NOT NULL,
  AUDIT_STATUS    NUMBER(1) DEFAULT 0             NOT NULL,
  RESEND_ADMIN_ID VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN_ID  VARCHAR2(32),
  RESEND_REMARK   VARCHAR2(4000),
  AUDIT_REMARK    VARCHAR2(4000),
  CREATED_AT      NUMBER(10)                      NOT NULL,
  AUDITED_AT      NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_RESEND_QY_AUDIT IS '补发区域津贴审核表';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.RESEND_ID IS '补发表ID';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.SHOULD_BONUS IS '应发金额';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.RESEND_BONUS IS '补发金额';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.PERIOD_NUM IS '补发期数';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.RESEND_ADMIN_ID IS '补发管理员ID';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.AUDIT_ADMIN_ID IS '审核管理员ID';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.RESEND_REMARK IS '补发备注';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_RESEND_QY_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_RESEND_QY_AUDIT ON AR_RESEND_QY_AUDIT (USER_ID);

-- 会员注册信息审核表(用于提现)
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_REG_INFO_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_REG_INFO_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  REG_TYPE      VARCHAR2(32)                    NOT NULL,
  REG_NAME      VARCHAR2(255)                  NOT NULL,
  CREDIT_CODE   VARCHAR2(255)                  NOT NULL,
  PREMISES      VARCHAR2(255),
  LEGAL_PERSON  VARCHAR2(255),
  REG_EXPIRES   NUMBER(10)                      NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  CREATE_PERIOD  NUMBER(10) DEFAULT 0           NOT NULL,
  AUDIT_PERIOD  NUMBER(10) DEFAULT 0            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_REG_INFO_AUDIT IS '会员注册信息审核表';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.REG_TYPE IS '注册类型';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.REG_NAME IS '注册名称';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.CREDIT_CODE IS '统一社会信用代码';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.PREMISES IS '经营场所';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.LEGAL_PERSON IS '法人';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.REG_EXPIRES IS '注册有效期';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.CREATE_REMARK IS '申请备注';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.CREATE_PERIOD IS '创建期数';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.AUDIT_PERIOD IS '审核期数';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_REG_INFO_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_R_I_A_USER_ID_INDEX ON AR_REG_INFO_AUDIT(USER_ID);
CREATE INDEX AR_R_I_A_TYPE_INDEX ON AR_REG_INFO_AUDIT(REG_TYPE);
CREATE INDEX AR_R_I_A_AUDIT_STATUS_INDEX ON AR_REG_INFO_AUDIT(AUDIT_STATUS);

-- 发票余额审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_INVOICE_BALANCE_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_INVOICE_BALANCE_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  AMOUNT        NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_INVOICE_BALANCE_AUDIT IS '发票余额审核表';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.AMOUNT IS '调整金额';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.CREATE_REMARK IS '申请备注';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_INVOICE_BALANCE_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_I_B_A_USER_ID_INDEX ON AR_INVOICE_BALANCE_AUDIT(USER_ID);
CREATE INDEX AR_I_B_A_AUDIT_STATUS_INDEX ON AR_INVOICE_BALANCE_AUDIT(AUDIT_STATUS);

-- 发票审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_INVOICE_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_INVOICE_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  WITHDRAW_ID   VARCHAR2(32)                    NOT NULL,
  INVOICE_CODE  VARCHAR2(255)                   NOT NULL,
  INVOICE_NUM   VARCHAR2(255)                   NOT NULL,
  INVOICE_DATE  VARCHAR2(255)                   NOT NULL,
  AMOUNT        NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  TAX_RATE      VARCHAR2(10) ,
  PURCHASER_NAME VARCHAR2(255)                  NOT NULL,
  PURCHASER_REGISTER_NUM  VARCHAR2(255)         NOT NULL,
  PURCHASER_ADDRESS VARCHAR2(255)               NOT NULL,
  PURCHASER_BANK VARCHAR2(255)                  NOT NULL,
  SELLER_NAME    VARCHAR2(255)                  NOT NULL,
  SELLER_REGISTER_NUM  VARCHAR2(255)            NOT NULL,
  SELLER_ADDRESS VARCHAR2(255)                  NOT NULL,
  SELLER_BANK VARCHAR2(255)                     NOT NULL,
  ITEM_NAME     VARCHAR2(255)                   NOT NULL,
  INVOICE_REMARK VARCHAR2(255),
  UPLOAD_ID     VARCHAR2(255),
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32),
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_INVOICE_AUDIT IS '发票审核表';
COMMENT ON COLUMN AR_INVOICE_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_INVOICE_AUDIT.WITHDRAW_ID IS '提现ID';
COMMENT ON COLUMN AR_INVOICE_AUDIT.INVOICE_CODE IS '发票代码';
COMMENT ON COLUMN AR_INVOICE_AUDIT.INVOICE_NUM IS '发票号码';
COMMENT ON COLUMN AR_INVOICE_AUDIT.INVOICE_DATE IS '开票日期';
COMMENT ON COLUMN AR_INVOICE_AUDIT.AMOUNT IS '交易金额';
COMMENT ON COLUMN AR_INVOICE_AUDIT.TAX_RATE IS '税率';
COMMENT ON COLUMN AR_INVOICE_AUDIT.PURCHASER_NAME IS '购买方名称';
COMMENT ON COLUMN AR_INVOICE_AUDIT.PURCHASER_REGISTER_NUM IS '购买方纳税人识别号';
COMMENT ON COLUMN AR_INVOICE_AUDIT.PURCHASER_ADDRESS IS '购买方地址电话';
COMMENT ON COLUMN AR_INVOICE_AUDIT.PURCHASER_BANK IS '购买方开户行及帐号';
COMMENT ON COLUMN AR_INVOICE_AUDIT.SELLER_NAME IS '销售方名称';
COMMENT ON COLUMN AR_INVOICE_AUDIT.SELLER_REGISTER_NUM IS '销售方纳税人识别号';
COMMENT ON COLUMN AR_INVOICE_AUDIT.SELLER_ADDRESS IS '销售方地址电话';
COMMENT ON COLUMN AR_INVOICE_AUDIT.SELLER_BANK IS '销售方开户行及帐号';
COMMENT ON COLUMN AR_INVOICE_AUDIT.ITEM_NAME IS '货物或应税劳务、服务名称';
COMMENT ON COLUMN AR_INVOICE_AUDIT.INVOICE_REMARK IS '发票备注';
COMMENT ON COLUMN AR_INVOICE_AUDIT.UPLOAD_ID IS '上传ID';
COMMENT ON COLUMN AR_INVOICE_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_INVOICE_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_INVOICE_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_INVOICE_AUDIT.CREATE_REMARK IS '申请备注';
COMMENT ON COLUMN AR_INVOICE_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_INVOICE_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_INVOICE_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_I_A_INVOICE_NUM_INDEX ON AR_INVOICE_AUDIT(INVOICE_NUM);
CREATE INDEX AR_I_A_USER_ID_INDEX ON AR_INVOICE_AUDIT(USER_ID);
CREATE INDEX AR_I_A_AUDIT_STATUS_INDEX ON AR_INVOICE_AUDIT(AUDIT_STATUS);

-- 发票交易记录表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_INVOICE_FLOW';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_INVOICE_FLOW
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  REAL_NAME     VARCHAR2(128)                   NOT NULL,
  DEC_LV        VARCHAR2(32)                    NOT NULL,
  EMP_LV        VARCHAR2(32)                    NOT NULL,
  MOBILE        VARCHAR2(32)                    NOT NULL,
  REG_TYPE      VARCHAR2(32)                    NOT NULL,
  REG_NAME      VARCHAR2(255)                   NOT NULL,
  CREDIT_CODE   VARCHAR2(255)                   NOT NULL,
  SALE_NAME     VARCHAR2(255)                   ,
  TAXPAYER_NUMBER VARCHAR2(255)                 ,
  INVOICE_ACCOUNT VARCHAR2(255)                 NOT NULL,
  INVOICE_SN VARCHAR2(255)                 ,
  TAX_ACCOUNT   VARCHAR2(255)                   NOT NULL,
  OUTED_AT      NUMBER(10) DEFAULT 0            NOT NULL,
  DEDUCT_PERIOD_NUM NUMBER(32) DEFAULT 0        NOT NULL,
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  TOTAL         NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  WITHDRAW_SN   VARCHAR2(255),
  IS_INCR       NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  CREATE_REMARK VARCHAR2(4000)                  ,
  CREATE_TIME   NUMBER(10)                      NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32)                    NOT NULL,
  AUDIT_REMARK  VARCHAR2(4000)                  ,
  AUDIT_TIME    NUMBER(10)                      NOT NULL,
  P_MONTH       DATE                            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL
)
  PARTITION BY RANGE(P_MONTH)
  INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_INVOICE_FLOW IS '发票交易记录表';
COMMENT ON COLUMN AR_INVOICE_FLOW.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_INVOICE_FLOW.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_INVOICE_FLOW.DEC_LV IS '报单级别';
COMMENT ON COLUMN AR_INVOICE_FLOW.EMP_LV IS '聘级';
COMMENT ON COLUMN AR_INVOICE_FLOW.MOBILE IS '手机号';
COMMENT ON COLUMN AR_INVOICE_FLOW.REG_TYPE IS '注册类型';
COMMENT ON COLUMN AR_INVOICE_FLOW.REG_NAME IS '注册名称';
COMMENT ON COLUMN AR_INVOICE_FLOW.CREDIT_CODE IS '统一社会信用代码';
COMMENT ON COLUMN AR_INVOICE_FLOW.SALE_NAME IS '销售方名称';
COMMENT ON COLUMN AR_INVOICE_FLOW.TAXPAYER_NUMBER IS '纳税人识别号';
COMMENT ON COLUMN AR_INVOICE_FLOW.INVOICE_ACCOUNT IS '交易账户-发票账户';
COMMENT ON COLUMN AR_INVOICE_FLOW.INVOICE_SN IS '发票号';
COMMENT ON COLUMN AR_INVOICE_FLOW.TAX_ACCOUNT IS '交易账户-税款账户';
COMMENT ON COLUMN AR_INVOICE_FLOW.OUTED_AT IS '开票日期';
COMMENT ON COLUMN AR_INVOICE_FLOW.DEDUCT_PERIOD_NUM IS '发票冲减期数';
COMMENT ON COLUMN AR_INVOICE_FLOW.AMOUNT IS '金额';
COMMENT ON COLUMN AR_INVOICE_FLOW.TOTAL IS '当前总金额';
COMMENT ON COLUMN AR_INVOICE_FLOW.WITHDRAW_SN IS '提现流水号';
COMMENT ON COLUMN AR_INVOICE_FLOW.IS_INCR IS '是否增加';
COMMENT ON COLUMN AR_INVOICE_FLOW.REMARK IS '备注';
COMMENT ON COLUMN AR_INVOICE_FLOW.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_INVOICE_FLOW.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_INVOICE_FLOW.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_INVOICE_FLOW.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_INVOICE_FLOW.CREATE_TIME IS '创建时间';
COMMENT ON COLUMN AR_INVOICE_FLOW.AUDIT_ADMIN IS '审核人';
COMMENT ON COLUMN AR_INVOICE_FLOW.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_INVOICE_FLOW.AUDIT_TIME IS '审核时间';
COMMENT ON COLUMN AR_INVOICE_FLOW.P_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_INVOICE_FLOW.CREATED_AT IS '创建时间';

-- 车房养老奖年度发放审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_CF_LX_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CF_LX_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  CF            NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  LX            NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  YEAR          NUMBER(4) DEFAULT 0             NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_CF_LX_AUDIT IS '车房领袖年度发放审核表';
COMMENT ON COLUMN AR_CF_LX_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_CF_LX_AUDIT.CF IS '车房养老';
COMMENT ON COLUMN AR_CF_LX_AUDIT.LX IS '领袖分红';
COMMENT ON COLUMN AR_CF_LX_AUDIT.YEAR IS '类型';
COMMENT ON COLUMN AR_CF_LX_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_CF_LX_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_CF_LX_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_CF_LX_AUDIT.CREATE_REMARK IS '申请备注';
COMMENT ON COLUMN AR_CF_LX_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_CF_LX_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_CF_LX_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_C_L_AUDIT_YEAR_INDEX ON AR_CF_LX_AUDIT(YEAR);
CREATE INDEX AR_C_L_AUDIT_STATUS_INDEX ON AR_CF_LX_AUDIT(AUDIT_STATUS);

-- 调整业绩审核表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_PERF_AUDIT';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_PERF_AUDIT
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID       VARCHAR2(32)                    NOT NULL,
    PV_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PV_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_1L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_2L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_3L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_4L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_5L        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    SURPLUS_LS        NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PERF_TYPE  NUMBER(1) DEFAULT 0             NOT NULL,
    PERF_LOCATION  NUMBER(1) DEFAULT 1             NOT NULL,
    PERF_BEFORE  NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PERF_AFTER  NUMBER(16,3) DEFAULT 0.000       NOT NULL,
    PERIOD_NUM  NUMBER(10) DEFAULT 0       NOT NULL,
    AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
    CREATE_ADMIN  VARCHAR2(32) DEFAULT '',
    REMARK VARCHAR2(4000) DEFAULT '',
    AUDIT_ADMIN   VARCHAR2(32) DEFAULT '',
    CREATED_AT    NUMBER(10)                      NOT NULL,
    AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_PERF_AUDIT IS '调整业绩审核表';
COMMENT ON COLUMN AR_PERF_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_PERF_AUDIT.PV_1L IS '一市场累计';
COMMENT ON COLUMN AR_PERF_AUDIT.PV_2L IS '二市场累计';
COMMENT ON COLUMN AR_PERF_AUDIT.PV_3L IS '三市场累计';
COMMENT ON COLUMN AR_PERF_AUDIT.PV_4L IS '四市场累计';
COMMENT ON COLUMN AR_PERF_AUDIT.PV_5L IS '五市场累计';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_1L IS '一市场结余';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_2L IS '二市场结余';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_3L IS '三市场结余';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_4L IS '四市场结余';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_5L IS '五市场结余';
COMMENT ON COLUMN AR_PERF_AUDIT.SURPLUS_LS IS '虚拟零售区结余';
COMMENT ON COLUMN AR_PERF_AUDIT.PERF_TYPE IS '业绩类型';
COMMENT ON COLUMN AR_PERF_AUDIT.PERF_LOCATION IS '业绩区域';
COMMENT ON COLUMN AR_PERF_AUDIT.PERF_BEFORE IS '业绩调整前';
COMMENT ON COLUMN AR_PERF_AUDIT.PERF_AFTER IS '业绩调整后';
COMMENT ON COLUMN AR_PERF_AUDIT.PERIOD_NUM IS '调整期数';
COMMENT ON COLUMN AR_PERF_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_PERF_AUDIT.CREATE_ADMIN IS '创建管理员';
COMMENT ON COLUMN AR_PERF_AUDIT.REMARK IS '备注';
COMMENT ON COLUMN AR_PERF_AUDIT.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_PERF_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_PERF_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_PERF_AUDIT_STATUS_INDEX ON AR_PERF_AUDIT(AUDIT_STATUS);

-- 交易类型表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_DEAL_TYPE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DEAL_TYPE
(
    ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    TYPE_NAME     VARCHAR2(255)                   NOT NULL,
    CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
    UPDATE_ADMIN   VARCHAR2(32),
    CREATE_REMARK VARCHAR2(4000),
    UPDATE_REMARK  VARCHAR2(4000),
    IS_PRESET     NUMBER(1) DEFAULT 0 NOT NULL ,
    IS_ENABLE     NUMBER(1) DEFAULT 0 NOT NULL ,
    CREATED_AT    NUMBER(10)                      NOT NULL,
    UPDATED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
    SORT_ORDER    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_DEAL_TYPE IS '交易类型表';
COMMENT ON COLUMN AR_DEAL_TYPE.TYPE_NAME IS '类型名称';
COMMENT ON COLUMN AR_DEAL_TYPE.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_DEAL_TYPE.UPDATE_ADMIN IS '修改人';
COMMENT ON COLUMN AR_DEAL_TYPE.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_DEAL_TYPE.UPDATE_REMARK IS '修改备注';
COMMENT ON COLUMN AR_DEAL_TYPE.IS_PRESET IS '是否系统预置';
COMMENT ON COLUMN AR_DEAL_TYPE.IS_ENABLE IS '是否启用';
COMMENT ON COLUMN AR_DEAL_TYPE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_DEAL_TYPE.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_DEAL_TYPE.SORT_ORDER IS '排序';

INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('141E52002AAE43B7AC304F4BAEFDA268', '奖金发放', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('6626ED606DB34A11B6CCEA768B6E36C2', '奖金提现', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('7E3255C33BD6457B8F7155F2A86FFF73', '责任业绩扣除', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('01A753D2548F44FA99B847133C1B5F79', '提现退回', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('DAA0FB1465F748908680D941D589326E', '转出', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('DB62879E6C6B4B2F8591FAD920A2822C', '转入', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('E57A779B2E064081B335C5D6B9E4B59B', '点位绑定转出', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('082485287F3148B7A44DC62D5D17473A', '点位绑定转入', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('38EB53BCAAF24BA38B2E5FDA313EC928', '点位合作转出', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('64198F701D374D2996AA8EF1D37769AB', '点位合作转入', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('A6BDF8A2E5F7450B80CBF3B28D8010D2', '复消积分发放', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('12840830348E456696834E0624FE2331', '领袖分红发放', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('01C2916A2ECA4D1B9C29AA333C6D13E7', '复消积分转出', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('3CD904D1D0764A3FA3E9114DA1D930BD', '领袖分红转出', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('F6AA8D767E654D86917BBF1A5C24F439', '复消积分转入', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
-- INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('0C092D8D6D804F4B84134DBAB5BBE05C', '领袖分红转入', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('1145D8ABA7A7471FB59B6760BDB19019', '短信服务费', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('37B81A45F38646A0A16499AB27B51923', '补发', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('37EFF25E5E3F46A6BB84B8C55997F276', '永久关停扣除', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
INSERT INTO AR_DEAL_TYPE (ID, TYPE_NAME, CREATE_ADMIN, UPDATE_ADMIN, CREATE_REMARK, UPDATE_REMARK, IS_PRESET, IS_ENABLE, CREATED_AT, UPDATED_AT, SORT_ORDER) VALUES ('A1F1E76F34EE4981AB3BF4F8D20BB53E', '注销扣除', '65F27BCE7FD278FFE055736AECE8644D', null, null, null, 1, 1, 1561942800, 0, 0);
COMMIT;

-- 会员状态审核表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_USER_STATUS_AUDIT';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_STATUS_AUDIT
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  STATUS_VALUE  NUMBER(1) DEFAULT 1             NOT NULL,
  ORI_VALUE     NUMBER(1) DEFAULT 1             NOT NULL,
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  AUDIT_STATUS  NUMBER(1) DEFAULT 0             NOT NULL,
  DEC_LV        VARCHAR2(32) ,
  EMP_LV        VARCHAR2(32) ,
  PV_1L         NUMBER(16,2) ,
  PV_2L         NUMBER(16,2) ,
  PV_3L         NUMBER(16,2) ,
  PV_4L         NUMBER(16,2) ,
  PV_5L         NUMBER(16,2) ,
  SURPLUS_1L    NUMBER(16,2) ,
  SURPLUS_2L    NUMBER(16,2) ,
  SURPLUS_3L    NUMBER(16,2) ,
  SURPLUS_4L    NUMBER(16,2) ,
  SURPLUS_5L    NUMBER(16,2) ,
  IS_PERIOD_ADD_T  NUMBER(1) DEFAULT 0             NOT NULL,
  ADD_T_PERIOD_NUM NUMBER(10) ,
  IS_PERIOD_OPEN NUMBER(1) DEFAULT 0             NOT NULL,
  OPEN_PERIOD_NUM NUMBER(10) ,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  AUDIT_ADMIN   VARCHAR2(32),
  CREATE_REMARK VARCHAR2(4000),
  AUDIT_REMARK  VARCHAR2(4000),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  AUDITED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_USER_STATUS_AUDIT IS '会员状态审核表';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.STATUS_VALUE IS '修改后状态值';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.ORI_VALUE IS '原始状态值';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.DEC_LV IS '修改状态时报单级别';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.EMP_LV IS '修改状态时聘级';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PV_1L IS '修改状态时一市场业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PV_2L IS '修改状态时二市场业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PV_3L IS '修改状态时三市场业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PV_4L IS '修改状态时四市场业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.PV_5L IS '修改状态时五市场业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.SURPLUS_1L IS '修改状态时一市场剩余业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.SURPLUS_2L IS '修改状态时二市场剩余业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.SURPLUS_3L IS '修改状态时三市场剩余业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.SURPLUS_4L IS '修改状态时四市场剩余业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.SURPLUS_5L IS '修改状态时五市场剩余业绩';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.IS_PERIOD_ADD_T IS '是否按照期数加T';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.ADD_T_PERIOD_NUM IS '身份证加T的期数';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.IS_PERIOD_OPEN IS '是否按照期数开通';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.OPEN_PERIOD_NUM IS '开通期数';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.AUDIT_ADMIN IS '审核人';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.CREATE_REMARK IS '创建备注';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.AUDIT_REMARK IS '审核备注';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_USER_STATUS_AUDIT.AUDITED_AT IS '审核时间';

CREATE INDEX AR_U_S_A_UID_INDEX ON AR_USER_STATUS_AUDIT(USER_ID);
CREATE INDEX AR_U_S_A_PN_INDEX ON AR_USER_STATUS_AUDIT(PERIOD_NUM);
CREATE INDEX AR_U_S_A_AS_INDEX ON AR_USER_STATUS_AUDIT(AUDIT_STATUS);

-- 公司银行信息表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_COMPANY_BANK';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_COMPANY_BANK
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  OPEN_NAME     VARCHAR2(255)                   NOT NULL,
  OPEN_BANK     VARCHAR2(255)                   NOT NULL,
  BANK_ADDRESS  VARCHAR2(255)                   NOT NULL,
  BANK_NO       VARCHAR2(32)                    NOT NULL,
  BANK_PROVINCE NUMBER(6)                       NOT NULL,
  BANK_CITY     NUMBER(6)                       NOT NULL,
  BANK_COUNTY   NUMBER(6)                       NOT NULL,
  CREATE_ADMIN  VARCHAR2(32)                    NOT NULL,
  UPDATE_ADMIN  VARCHAR2(32),
  REMARK        VARCHAR2(4000),
  CREATED_AT    NUMBER(10)                      NOT NULL,
  UPDATED_AT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_COMPANY_BANK IS '公司银行信息';
COMMENT ON COLUMN AR_COMPANY_BANK.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_COMPANY_BANK.OPEN_NAME IS '开户名';
COMMENT ON COLUMN AR_COMPANY_BANK.OPEN_BANK IS '开户行';
COMMENT ON COLUMN AR_COMPANY_BANK.BANK_ADDRESS IS '银行地址';
COMMENT ON COLUMN AR_COMPANY_BANK.BANK_NO IS '银行账号';
COMMENT ON COLUMN AR_COMPANY_BANK.BANK_PROVINCE IS '银行省份';
COMMENT ON COLUMN AR_COMPANY_BANK.BANK_CITY IS '银行城市';
COMMENT ON COLUMN AR_COMPANY_BANK.BANK_COUNTY IS '银行地区';
COMMENT ON COLUMN AR_COMPANY_BANK.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_COMPANY_BANK.UPDATE_ADMIN IS '修改人';
COMMENT ON COLUMN AR_COMPANY_BANK.REMARK IS '备注';
COMMENT ON COLUMN AR_COMPANY_BANK.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_COMPANY_BANK.UPDATED_AT IS '修改时间';

-- 提现标记失败待导入表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXCEL_WITHDRAW_PAID_FALSE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXCEL_WITHDRAW_PAID_FALSE (
  ID                  VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  EXCEL_IMPORT_ID     VARCHAR2(32)                    NOT NULL,
  SN                  VARCHAR2(32)                    NOT NULL,
  WITHDRAW_PERIOD_NUM NUMBER(10) DEFAULT 0            NOT NULL,
  PAID_AT             VARCHAR2(32) DEFAULT ''         NOT NULL,
  PAID_FAIL_REMARK    VARCHAR2(1000) DEFAULT '',
  USER_NAME           VARCHAR2(16)                    NOT NULL,
  REAL_NAME           VARCHAR2(32)                    NOT NULL,
  AMOUNT              NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  BANK_REAL_NAME      VARCHAR2(255)                   NOT NULL,
  BANK_NO             VARCHAR2(32)                    NOT NULL,
  SORT                NUMBER(5) DEFAULT 0             NOT NULL,
  STATUS              NUMBER(1) DEFAULT 0             NOT NULL,
  ERROR_REMARK        VARCHAR2(1000) DEFAULT '',
  CREATED_AT          NUMBER(10) DEFAULT 0            NOT NULL
);
CREATE INDEX AR_E_W_PAID_FALSE_EIID ON AR_EXCEL_WITHDRAW_PAID_FALSE (EXCEL_IMPORT_ID);
CREATE INDEX AR_E_W_PAID_FALSE_UN ON AR_EXCEL_WITHDRAW_PAID_FALSE (USER_NAME);
COMMENT ON TABLE AR_EXCEL_WITHDRAW_PAID_FALSE IS '提现标记失败待导入表';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.EXCEL_IMPORT_ID IS '导入记录表ID';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.SN IS '提现流水号';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.WITHDRAW_PERIOD_NUM IS '提现期数';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.PAID_AT IS '付款日期';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.PAID_FAIL_REMARK IS '付款失败原因';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.USER_NAME IS '会员编号';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.AMOUNT IS '实付金额';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.BANK_REAL_NAME IS '实时开户名';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.BANK_NO IS '实时银行账户';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.SORT IS '序号';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.STATUS IS '状态';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.ERROR_REMARK IS '错误记录';
COMMENT ON COLUMN AR_EXCEL_WITHDRAW_PAID_FALSE.CREATED_AT IS '创建时间';

-- 调整会员余额待导入表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXCEL_CHANGE_BALANCE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXCEL_CHANGE_BALANCE (
  ID                  VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  EXCEL_IMPORT_ID     VARCHAR2(32)                    NOT NULL,
  USER_NAME           VARCHAR2(16)                    NOT NULL,
  REAL_NAME           VARCHAR2(32)                    NOT NULL,
  TYPE        		  VARCHAR2(20)                    NOT NULL,
  AMOUNT              NUMBER(16,2) DEFAULT 0.00       NOT NULL,
  DEAL_TYPE           VARCHAR2(128)                    NOT NULL,
  REMARK              VARCHAR2(2000) DEFAULT '',
  REMARK_IS_SHOW      NUMBER(1) DEFAULT 0            NOT NULL,
  SORT                NUMBER(5) DEFAULT 0             NOT NULL,
  STATUS              NUMBER(1) DEFAULT 0             NOT NULL,
  ERROR_REMARK        VARCHAR2(1000) DEFAULT '',
  CREATED_AT          NUMBER(10) DEFAULT 0            NOT NULL
);

COMMENT ON TABLE AR_EXCEL_CHANGE_BALANCE IS '调整会员余额待导入表';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.EXCEL_IMPORT_ID IS '导入记录表ID';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.USER_NAME IS '会员编号';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.TYPE IS '账户类型';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.AMOUNT IS '调整金额';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.DEAL_TYPE IS '交易类型';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.REMARK IS '备注';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.REMARK_IS_SHOW IS '备注显示';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.SORT IS '序号';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.STATUS IS '状态';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.ERROR_REMARK IS '错误记录';
COMMENT ON COLUMN AR_EXCEL_CHANGE_BALANCE.CREATED_AT IS '创建时间';

-- 注册信息待导入表
BEGIN
  EXECUTE IMMEDIATE 'DROP TABLE AR_EXCEL_REG_INFO';
  EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_EXCEL_REG_INFO
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  EXCEL_IMPORT_ID VARCHAR2(32)                    NOT NULL,
  USER_NAME       VARCHAR2(32),
  REAL_NAME       VARCHAR2(32),
  ID_CARD         VARCHAR2(32),
  REG_TYPE        VARCHAR2(32),
  REG_NAME        VARCHAR2(255),
  CREDIT_CODE     VARCHAR2(255),
  PREMISES        VARCHAR2(255),
  REG_EXPIRES     VARCHAR2(255),
  LEGAL_PERSON    VARCHAR2(255),
  OPEN_NAME       VARCHAR2(255),
  OPEN_BANK       VARCHAR2(255),
  BANK_ADDRESS    VARCHAR2(255),
  BANK_NO         VARCHAR2(32),
  BANK_PROVINCE   VARCHAR2(32),
  BANK_CITY       VARCHAR2(32),
  BANK_COUNTY     VARCHAR2(32),
  REMARK          VARCHAR2(4000),
  SORT            NUMBER(10)                      NOT NULL,
  STATUS          NUMBER(1) DEFAULT 0             NOT NULL,
  ERROR_REMARK    VARCHAR2(4000),
  CREATED_AT      NUMBER(10)                      NOT NULL
);
COMMENT ON TABLE AR_EXCEL_REG_INFO IS '注册信息待导入表';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.EXCEL_IMPORT_ID IS '导入记录表ID';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.USER_NAME IS '会员编号';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.ID_CARD IS '身份证';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.REG_TYPE IS '注册类型';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.REG_NAME IS '注册名称';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.CREDIT_CODE IS '统一社会信用代码';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.PREMISES IS '经营场所';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.LEGAL_PERSON IS '法人';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.REG_EXPIRES IS '注册有效期';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.OPEN_NAME IS '企业开户名称';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.OPEN_BANK IS '企业开户银行';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.BANK_ADDRESS IS '企业开户行地址';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.BANK_NO IS '企业银行账号';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.BANK_PROVINCE IS '企业银行省市';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.BANK_CITY IS '企业银行市区';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.BANK_COUNTY IS '企业银行区县';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.REMARK IS '备注';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.SORT IS '序号';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.STATUS IS '状态';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.ERROR_REMARK IS '错误备注';
COMMENT ON COLUMN AR_EXCEL_REG_INFO.CREATED_AT IS '创建时间';

DROP TABLE AR_YEAR_HIGHEST_EMP_LV;
CREATE TABLE AR_YEAR_HIGHEST_EMP_LV
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID VARCHAR2(32) NOT NULL,
    YEAR NUMBER(4) DEFAULT 0 NOT NULL,
    HIGHEST_EMP_LV VARCHAR2(32) NOT NULL,
    HIGHEST_EMP_LV_SORT NUMBER(10) DEFAULT 0 NOT NULL,
    HIGHEST_EMP_LV_PERIOD NUMBER(10) DEFAULT 0 NOT NULL,
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    PARTITION_DATE        DATE           DEFAULT SYSDATE NOT NULL
)
    PARTITION BY RANGE (PARTITION_DATE)
    INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
(
    PARTITION A_Y_H_E_L_P1 VALUES LESS THAN (TO_DATE('2019-06-01', 'YYYY-MM-DD'))
);
COMMENT ON TABLE AR_YEAR_HIGHEST_EMP_LV IS '会员年度最高聘级';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.YEAR IS '年度';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.HIGHEST_EMP_LV IS '年度最高聘级';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.HIGHEST_EMP_LV_SORT IS '年度最高聘级排序';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.HIGHEST_EMP_LV_PERIOD IS '达到年度最高聘级的期数';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_YEAR_HIGHEST_EMP_LV.UPDATED_AT IS '修改时间';
CREATE INDEX AR_YEAR_H_EMP_LV_UID ON AR_YEAR_HIGHEST_EMP_LV (USER_ID) LOCAL ;
CREATE INDEX AR_YEAR_H_EMP_LV_Y ON AR_YEAR_HIGHEST_EMP_LV (YEAR) LOCAL;

-- 任务队列
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_TASK_QUEUE';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_TASK_QUEUE
(
    ID          VARCHAR2(32) DEFAULT SYS_GUID()     NOT NULL PRIMARY KEY,
    MAIN_ID     VARCHAR2(32)                        NOT NULL,
    TYPE        NUMBER(10) DEFAULT 1                NOT NULL,
    CONTENT     VARCHAR2(255)                       NOT NULL,
    PARAMS      VARCHAR2(4000)                      NOT NULL,
    TOTAL_LOOP  NUMBER(10) DEFAULT 0                NOT NULL,
    DONE_TIMES  NUMBER(10) DEFAULT 0                NOT NULL,
    LOOP_TYPE   NUMBER(10) DEFAULT 0                NOT NULL,
    LOOP_CYCLE_CONTENT VARCHAR2(255) ,
    NEXT_AT     NUMBER(10) DEFAULT 0                NOT NULL,
    CREATED_AT  NUMBER(10)                          NOT NULL,
    STARTED_AT  NUMBER(10) DEFAULT 0                NOT NULL,
    FINISHED_AT  NUMBER(10) DEFAULT 0               NOT NULL
);
COMMENT ON TABLE AR_TASK_QUEUE IS '任务队列列表';
COMMENT ON COLUMN AR_TASK_QUEUE.ID IS '任务ID';
COMMENT ON COLUMN AR_TASK_QUEUE.MAIN_ID IS '主任务ID';
COMMENT ON COLUMN AR_TASK_QUEUE.TYPE IS '任务类型';
COMMENT ON COLUMN AR_TASK_QUEUE.CONTENT IS '任务内容';
COMMENT ON COLUMN AR_TASK_QUEUE.PARAMS IS '参数';
COMMENT ON COLUMN AR_TASK_QUEUE.TOTAL_LOOP IS '主任务循环次数';
COMMENT ON COLUMN AR_TASK_QUEUE.DONE_TIMES IS '完成次数';
COMMENT ON COLUMN AR_TASK_QUEUE.LOOP_TYPE IS '循环类型';
COMMENT ON COLUMN AR_TASK_QUEUE.LOOP_CYCLE_CONTENT IS '循环周期内容';
COMMENT ON COLUMN AR_TASK_QUEUE.NEXT_AT IS '下次执行任务的时间';
COMMENT ON COLUMN AR_TASK_QUEUE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_TASK_QUEUE.STARTED_AT IS '任务开始时间';
COMMENT ON COLUMN AR_TASK_QUEUE.FINISHED_AT IS '任务完成时间';

COMMIT;

-- 地区表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_REGION';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_REGION
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    REGION_CODE NUMBER(6) DEFAULT NULL NOT NULL,
    DEEP NUMBER(2) DEFAULT 0 NOT NULL,
    REGION_NAME VARCHAR2(128) DEFAULT NULL NOT NULL,
    PID NUMBER(6) DEFAULT 0 NOT NULL,
    AREA_CODE VARCHAR2(6) DEFAULT NULL NOT NULL,
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATER VARCHAR2(16) DEFAULT '',
    ADM_NAME VARCHAR2(16) DEFAULT NULL NOT NULL,
    STATUS NUMBER(1) DEFAULT 1 NOT NULL
);
COMMENT ON TABLE AR_REGION IS '地区';
COMMENT ON COLUMN AR_REGION.REGION_CODE IS '编码';
COMMENT ON COLUMN AR_REGION.DEEP IS '深度';
COMMENT ON COLUMN AR_REGION.REGION_NAME IS '名称';
COMMENT ON COLUMN AR_REGION.PID IS '父级ID';
COMMENT ON COLUMN AR_REGION.AREA_CODE IS '区号';
COMMENT ON COLUMN AR_REGION.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_REGION.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_REGION.UPDATER IS '修改人';
COMMENT ON COLUMN AR_REGION.ADM_NAME IS '操作人';
COMMENT ON COLUMN AR_REGION.STATUS IS '状态';
CREATE UNIQUE INDEX AR_REGION_REGION_CODE_UINDEX ON AR_REGION (REGION_CODE);

-- 报单表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_DEC_ORDER';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DEC_ORDER
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    DEC_SN VARCHAR2(32) DEFAULT NULL NOT NULL,
    ORDER_SN VARCHAR2(32) DEFAULT NULL NOT NULL,
    USER_ID VARCHAR2(32) NOT NULL,
    TO_USER_ID VARCHAR2(32) NOT NULL,
    TYPE VARCHAR2(32) NOT NULL,
    IS_ADMIN NUMBER(1) DEFAULT 0 NOT NULL,
    DEC_AMOUNT NUMBER(16,3) DEFAULT 0.000 NOT NULL,
    DEC_PV NUMBER(16,3) DEFAULT 0.000 NOT NULL,
    PAID_WALLET VARCHAR2(48) NOT NULL,
    IS_BATCH NUMBER(1) DEFAULT 0 NOT NULL,
    REMARK VARCHAR2(4000) DEFAULT '',
    REC_USER_ID VARCHAR2(32) DEFAULT '',
    CON_USER_ID VARCHAR2(32) DEFAULT '',
    PERIOD_NUM NUMBER(10) NOT NULL,
    P_CALC_MONTH DATE NOT NULL,
    CALC_MONTH NUMBER(8) DEFAULT 0 NOT NULL,
    CREATED_AT NUMBER(10) NOT NULL,
    UPDATER VARCHAR2(32) DEFAULT '',
    UPDATED_AT VARCHAR2(32) DEFAULT 0 NOT NULL,
    IS_DEL NUMBER(1) DEFAULT 0 NOT NULL,
    DELETED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    DEC_ID VARCHAR2(32) DEFAULT ''
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_DEC_ORDER IS '报单';
COMMENT ON COLUMN AR_DEC_ORDER.DEC_SN IS '报单编号';
COMMENT ON COLUMN AR_DEC_ORDER.ORDER_SN IS '订单编号';
COMMENT ON COLUMN AR_DEC_ORDER.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_DEC_ORDER.TO_USER_ID IS '报单对象ID';
COMMENT ON COLUMN AR_DEC_ORDER.TYPE IS '报单类型';
COMMENT ON COLUMN AR_DEC_ORDER.IS_ADMIN IS '是否管理员操作';
COMMENT ON COLUMN AR_DEC_ORDER.DEC_AMOUNT IS '报单金额';
COMMENT ON COLUMN AR_DEC_ORDER.DEC_PV IS '报单PV';
COMMENT ON COLUMN AR_DEC_ORDER.PAID_WALLET IS '支付钱包';
COMMENT ON COLUMN AR_DEC_ORDER.IS_BATCH IS '是否批量报单';
COMMENT ON COLUMN AR_DEC_ORDER.REMARK IS '备注';
COMMENT ON COLUMN AR_DEC_ORDER.REC_USER_ID IS '开拓人ID';
COMMENT ON COLUMN AR_DEC_ORDER.CON_USER_ID IS '上级ID';
COMMENT ON COLUMN AR_DEC_ORDER.PERIOD_NUM IS '报单期数';
COMMENT ON COLUMN AR_DEC_ORDER.P_CALC_MONTH IS '分区结算月';
COMMENT ON COLUMN AR_DEC_ORDER.CALC_MONTH IS '结算月';
COMMENT ON COLUMN AR_DEC_ORDER.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_DEC_ORDER.UPDATER IS '操作人';
COMMENT ON COLUMN AR_DEC_ORDER.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_DEC_ORDER.IS_DEL IS '是否删除';
COMMENT ON COLUMN AR_DEC_ORDER.DELETED_AT IS '删除时间';
CREATE UNIQUE INDEX AR_D_O_DECLARATION_SN_IDX ON AR_DEC_ORDER (DEC_SN);
CREATE INDEX AR_D_O_USER_ID_INDEX ON AR_DEC_ORDER (USER_ID);
CREATE INDEX AR_D_O_TYPE_INDEX ON AR_DEC_ORDER (TYPE);
CREATE INDEX AR_D_O_PERIOD_NUM_INDEX ON AR_DEC_ORDER (PERIOD_NUM);
CREATE INDEX AR_D_O_IS_DEL_INDEX ON AR_DEC_ORDER (IS_DEL);
CREATE INDEX AR_D_O_ORDER_SN_INDEX ON AR_DEC_ORDER (ORDER_SN);

-- 会员钱包
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_USER_WALLET';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_USER_WALLET
(
    USER_ID VARCHAR2(32) NOT NULL PRIMARY KEY,
    CASH NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    CLEAR_BY_CLOSED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL
);
COMMENT ON TABLE AR_USER_WALLET IS '钱包';
COMMENT ON COLUMN AR_USER_WALLET.USER_ID IS '用户ID';
COMMENT ON COLUMN AR_USER_WALLET.CASH IS '现金';
COMMENT ON COLUMN AR_USER_WALLET.CLEAR_BY_CLOSED_AT IS '清空关停会员钱包时间';
COMMENT ON COLUMN AR_USER_WALLET.UPDATED_AT IS '修改时间';

-- 订单
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_ORDER';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ORDER
(
    SN VARCHAR2(32) DEFAULT NULL NOT NULL PRIMARY KEY,
    DEC_SN VARCHAR2(32) DEFAULT '',
    USER_ID VARCHAR2(32) NOT NULL,
    USER_NAME VARCHAR2(16) NOT NULL,
    ORDER_TYPE VARCHAR2(12) NOT NULL,
    ORDER_AMOUNT NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    PV NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    PAY_AMOUNT NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    PAY_PV NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    PAY_AT NUMBER(10) DEFAULT 0 NOT NULL,
    FREIGHT NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    PAY_FREIGHT NUMBER(10,2) DEFAULT 0.00 NOT NULL,
    DELIVERY_STATUS NUMBER(2) DEFAULT 0 NOT NULL,
    DELIVERY_PERIOD NUMBER(10) DEFAULT 0 NOT NULL,
    DELIVERY_AT NUMBER(10) DEFAULT 0 NOT NULL,
    EXPRESS_COMPANY VARCHAR2(128) DEFAULT '',
    ORDER_TRACK_NO VARCHAR2(32) DEFAULT '',
    EXPRESS_TYPE NUMBER(1) DEFAULT 0 NOT NULL,
    FRONT_REMARK VARCHAR2(1000) DEFAULT '',
    REMARK VARCHAR2(4000) DEFAULT '',
    PERIOD_NUM NUMBER(10) DEFAULT 0 NOT NULL,
    STATUS NUMBER(3) DEFAULT 0 NOT NULL,
    CONSIGNEE VARCHAR2(120) DEFAULT '',
    MOBILE VARCHAR2(11) DEFAULT '',
    TEL VARCHAR2(16) DEFAULT '',
    PROVINCE NUMBER(6) DEFAULT 0 NOT NULL,
    CITY NUMBER(6) DEFAULT 0 NOT NULL,
    COUNTY NUMBER(6) DEFAULT 0 NOT NULL,
    ADDRESS VARCHAR2(255) DEFAULT '' NOT NULL,
    P_CALC_MONTH DATE DEFAULT SYSDATE NOT NULL,
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    CREATE_USER VARCHAR2(16) NOT NULL,
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATER VARCHAR2(16) DEFAULT '',
    IS_DELETE NUMBER(10) DEFAULT 0 NOT NULL,
    DELETED_AT NUMBER(10) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_ORDER IS '商品订单';
COMMENT ON COLUMN AR_ORDER.SN IS '订单号';
COMMENT ON COLUMN AR_ORDER.DEC_SN IS '报单编号';
COMMENT ON COLUMN AR_ORDER.USER_ID IS '用户ID';
COMMENT ON COLUMN AR_ORDER.USER_NAME IS '会员编号';
COMMENT ON COLUMN AR_ORDER.ORDER_TYPE IS '订货类型';
COMMENT ON COLUMN AR_ORDER.ORDER_AMOUNT IS '订单总价格';
COMMENT ON COLUMN AR_ORDER.PV IS '订货PV';
COMMENT ON COLUMN AR_ORDER.PAY_AMOUNT IS '支付价格';
COMMENT ON COLUMN AR_ORDER.PAY_PV IS '实付PV';
COMMENT ON COLUMN AR_ORDER.PAY_AT IS '支付时间';
COMMENT ON COLUMN AR_ORDER.FREIGHT IS '运费';
COMMENT ON COLUMN AR_ORDER.PAY_FREIGHT IS '实付运费金额';
COMMENT ON COLUMN AR_ORDER.DELIVERY_STATUS IS '发货状态';
COMMENT ON COLUMN AR_ORDER.DELIVERY_PERIOD IS '发货期数';
COMMENT ON COLUMN AR_ORDER.DELIVERY_AT IS '发货时间';
COMMENT ON COLUMN AR_ORDER.EXPRESS_COMPANY IS '快递公司';
COMMENT ON COLUMN AR_ORDER.ORDER_TRACK_NO IS '快递单号';
COMMENT ON COLUMN AR_ORDER.EXPRESS_TYPE IS '发货方式';
COMMENT ON COLUMN AR_ORDER.FRONT_REMARK IS '前台备注';
COMMENT ON COLUMN AR_ORDER.REMARK IS '后台备注';
COMMENT ON COLUMN AR_ORDER.PERIOD_NUM IS '期数';
COMMENT ON COLUMN AR_ORDER.STATUS IS '订单状态';
COMMENT ON COLUMN AR_ORDER.CONSIGNEE IS '收货人';
COMMENT ON COLUMN AR_ORDER.MOBILE IS '收货人手机';
COMMENT ON COLUMN AR_ORDER.TEL IS '固定电话';
COMMENT ON COLUMN AR_ORDER.PROVINCE IS '省份名称';
COMMENT ON COLUMN AR_ORDER.CITY IS '城市名称';
COMMENT ON COLUMN AR_ORDER.COUNTY IS '县区';
COMMENT ON COLUMN AR_ORDER.ADDRESS IS '详细地址';
COMMENT ON COLUMN AR_ORDER.P_CALC_MONTH IS '分区日期';
COMMENT ON COLUMN AR_ORDER.CREATED_AT IS '订单创建时间';
COMMENT ON COLUMN AR_ORDER.CREATE_USER IS '订单创建人';
COMMENT ON COLUMN AR_ORDER.UPDATED_AT IS '修改时间';
COMMENT ON COLUMN AR_ORDER.UPDATER IS '修改人';
COMMENT ON COLUMN AR_ORDER.IS_DELETE IS '是否删除';
COMMENT ON COLUMN AR_ORDER.DELETED_AT IS '删除时间';
CREATE INDEX AR_ORDER_IDX_UID ON AR_ORDER (USER_ID);
CREATE INDEX AR_ORDER_IDX_UN ON AR_ORDER (USER_NAME);
CREATE INDEX AR_ORDER_IDX_AT ON AR_ORDER (CREATED_AT);
CREATE INDEX AR_ORDER_IDX_DEL ON AR_ORDER (IS_DELETE);

-- 订单商品
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_ORDER_GOODS';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_ORDER_GOODS
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    ORDER_SN VARCHAR2(32) NOT NULL,
    GOODS_ID VARCHAR2(32) NOT NULL,
    GOODS_TITLE VARCHAR2(255) NOT NULL,
    PRICE NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    REAL_PRICE NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    PV NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    REAL_PV NUMBER(16,2) DEFAULT 0.00 NOT NULL,
    SKU_CODE VARCHAR2(16) NOT NULL,
    BUY_NUMS NUMBER(10) DEFAULT 0 NOT NULL,
    P_CALC_MONTH DATE DEFAULT SYSDATE NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_ORDER_GOODS IS '订单中包含的商品';
COMMENT ON COLUMN AR_ORDER_GOODS.ORDER_SN IS '订单ID';
COMMENT ON COLUMN AR_ORDER_GOODS.GOODS_ID IS '商品ID';
COMMENT ON COLUMN AR_ORDER_GOODS.GOODS_TITLE IS '商品名称';
COMMENT ON COLUMN AR_ORDER_GOODS.PRICE IS '价格';
COMMENT ON COLUMN AR_ORDER_GOODS.REAL_PRICE IS '实际价格';
COMMENT ON COLUMN AR_ORDER_GOODS.PV IS '订货PV';
COMMENT ON COLUMN AR_ORDER_GOODS.REAL_PV IS '实际PV';
COMMENT ON COLUMN AR_ORDER_GOODS.SKU_CODE IS '商品编码';
COMMENT ON COLUMN AR_ORDER_GOODS.BUY_NUMS IS '购买数量';
COMMENT ON COLUMN AR_ORDER_GOODS.P_CALC_MONTH IS '分区日期';
CREATE INDEX AR_ORDER_GOODS_GID ON AR_ORDER_GOODS (GOODS_ID);
CREATE INDEX AR_ORDER_GOODS_OSN ON AR_ORDER_GOODS (ORDER_SN);

-- 收货地址
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_RECEIVE_ADDRESS';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RECEIVE_ADDRESS
(
    ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
    USER_ID VARCHAR2(32) NOT NULL,
    USER_NAME VARCHAR2(16) NOT NULL,
    CONSIGNEE VARCHAR2(120) NOT NULL,
    MOBILE VARCHAR2(11) NOT NULL,
    PROVINCE NUMBER(6) NOT NULL,
    CITY NUMBER(6) NOT NULL,
    COUNTY NUMBER(6) NOT NULL,
    ADDRESS VARCHAR2(255) NOT NULL,
    IS_DEFAULT NUMBER(1) DEFAULT 0 NOT NULL,
    CREATED_AT NUMBER(10) DEFAULT 0 NOT NULL,
    UPDATER VARCHAR2(10) DEFAULT '',
    UPDATED_AT NUMBER(10) DEFAULT 0 NOT NULL
);
COMMENT ON TABLE AR_RECEIVE_ADDRESS IS '收货地址';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.USER_ID IS '用户ID';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.USER_NAME IS '用户编号';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.CONSIGNEE IS '收货人';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.MOBILE IS '收货人手机';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.PROVINCE IS '省份名称';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.CITY IS '城市名称';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.COUNTY IS '县区名称';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.ADDRESS IS '详细地址';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.IS_DEFAULT IS '是否默认';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.UPDATER IS '修改人';
COMMENT ON COLUMN AR_RECEIVE_ADDRESS.UPDATED_AT IS '修改时间';
CREATE INDEX AR_RECEIVE_ADDRESS_UID ON AR_RECEIVE_ADDRESS (USER_ID);
CREATE INDEX AR_RECEIVE_ADDRESS_UN ON AR_RECEIVE_ADDRESS (USER_NAME);

COMMIT;


-- 充值申请
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_RECHARGE';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_RECHARGE
(
  ID              VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  SN              VARCHAR2(32),
  USER_ID         VARCHAR2(32)                    NOT NULL,
  ID_CARD         VARCHAR2(20) ,
  RECHARGE_PERIOD_NUM NUMBER(10),
  RECHARGE_YEAR   NUMBER(4),
  RECHARGE_MONTH  NUMBER(2),
  AMOUNT          NUMBER(16, 2) DEFAULT 0.00      NOT NULL,
  REAL_NAME       VARCHAR2(255),
  OPEN_BANK       VARCHAR2(32),
  BANK_ADDRESS    VARCHAR2(255),
  BANK_NO         VARCHAR2(32),
  BANK_PROVINCE   NUMBER(6),
  BANK_CITY       NUMBER(6),
  BANK_COUNTY     NUMBER(6),
  P_MONTH         DATE                            NOT NULL,
  AUDIT_STATUS    NUMBER(1) DEFAULT 0             NOT NULL,
  BANK_PROVE          VARCHAR2(255),
  REMARK          VARCHAR2(4000),
  AUDIT_ADMIN     VARCHAR2(32),
  CREATED_AT      NUMBER(10)                      NOT NULL,
  AUDITED_AT      NUMBER(10) DEFAULT 0            NOT NULL
)
PARTITION BY RANGE(P_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_RECHARGE IS '充值申请';
COMMENT ON COLUMN AR_RECHARGE.SN IS '单号';
COMMENT ON COLUMN AR_RECHARGE.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_RECHARGE.ID_CARD IS '身份证号';
COMMENT ON COLUMN AR_RECHARGE.RECHARGE_PERIOD_NUM IS '充值期数';
COMMENT ON COLUMN AR_RECHARGE.RECHARGE_YEAR IS '充值年份';
COMMENT ON COLUMN AR_RECHARGE.RECHARGE_MONTH IS '充值月份';
COMMENT ON COLUMN AR_RECHARGE.AMOUNT IS '提现金额';
COMMENT ON COLUMN AR_RECHARGE.REAL_NAME IS '会员姓名';
COMMENT ON COLUMN AR_RECHARGE.OPEN_BANK IS '开户行';
COMMENT ON COLUMN AR_RECHARGE.BANK_ADDRESS IS '银行地址';
COMMENT ON COLUMN AR_RECHARGE.BANK_NO IS '银行账号';
COMMENT ON COLUMN AR_RECHARGE.BANK_PROVINCE IS '银行省份';
COMMENT ON COLUMN AR_RECHARGE.BANK_CITY IS '银行城市';
COMMENT ON COLUMN AR_RECHARGE.BANK_COUNTY IS '银行地区';
COMMENT ON COLUMN AR_RECHARGE.BANK_PROVE IS '银行地区';
COMMENT ON COLUMN AR_RECHARGE.P_MONTH IS '表分区标识';
COMMENT ON COLUMN AR_RECHARGE.AUDIT_STATUS IS '审核状态';
COMMENT ON COLUMN AR_RECHARGE.REMARK IS '备注';
COMMENT ON COLUMN AR_RECHARGE.AUDIT_ADMIN IS '审核管理员';
COMMENT ON COLUMN AR_RECHARGE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_RECHARGE.AUDITED_AT IS '审核时间';

CREATE UNIQUE INDEX AR_RECHARGE_SN_UINDEX ON AR_RECHARGE(SN);

-- 现金钱包流水
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_WALLET';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_WALLET
(
  ID            VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_ID       VARCHAR2(32)                    NOT NULL,
  CALC_ID       VARCHAR2(32),
  AMOUNT        NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  TOTAL         NUMBER(16, 3) DEFAULT 0.000     NOT NULL,
  IS_INCR       NUMBER(1) DEFAULT 1             NOT NULL,
  REMARK        VARCHAR2(255)                   NOT NULL,
  ADMIN_NAME    VARCHAR2(32),
  PERIOD_NUM    NUMBER(10)                      NOT NULL,
  CALC_MONTH    NUMBER(10)                      NOT NULL,
  P_MONTH       DATE                            NOT NULL,
  CREATED_AT    NUMBER(10)                      NOT NULL,
  DELETED       NUMBER(1) DEFAULT 0             NOT NULL,
  DELETED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  SORT    NUMBER(10) DEFAULT 0            NOT NULL
)
PARTITION BY RANGE(P_MONTH)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
  PARTITION P0 VALUES LESS THAN (TO_DATE('2018-03-01','YYYY-MM-DD'))
);
COMMENT ON TABLE AR_FLOW_WALLET IS '现金钱包流水';
COMMENT ON COLUMN AR_FLOW_WALLET.USER_ID IS '会员ID';
COMMENT ON COLUMN AR_FLOW_WALLET.CALC_ID IS '奖金结算表ID';
COMMENT ON COLUMN AR_FLOW_WALLET.AMOUNT IS '金额';
COMMENT ON COLUMN AR_FLOW_WALLET.TOTAL IS '当前总金额';
COMMENT ON COLUMN AR_FLOW_WALLET.IS_INCR IS '是否增加';
COMMENT ON COLUMN AR_FLOW_WALLET.REMARK IS '备注';
COMMENT ON COLUMN AR_FLOW_WALLET.ADMIN_NAME IS '操作人名称';
COMMENT ON COLUMN AR_FLOW_WALLET.PERIOD_NUM IS '所在期数';
COMMENT ON COLUMN AR_FLOW_WALLET.CALC_MONTH IS '所在结算月';
COMMENT ON COLUMN AR_FLOW_WALLET.P_MONTH IS '表分区的日期索引';
COMMENT ON COLUMN AR_FLOW_WALLET.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_FLOW_WALLET.DELETED IS '是否删除';
COMMENT ON COLUMN AR_FLOW_WALLET.DELETED_AT IS '删除时间';
COMMENT ON COLUMN AR_FLOW_WALLET.SORT IS '排序';

-- 报单套餐
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_DECLARATION_PACKAGE';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_DECLARATION_PACKAGE
(
	ID         VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
	PACKAGE_NAME VARCHAR2(48)                    NOT NULL,
	AMOUNT NUMBER(16, 2) DEFAULT 0.00     NOT NULL,
	PV NUMBER(16, 2) DEFAULT 0.00     NOT NULL,
	LEVEL_ID VARCHAR2(32)                    NOT NULL,
	PACKAGE_CONTENT VARCHAR2(4000) DEFAULT '',
	CREATED_AT    NUMBER(10)            NOT NULL,
	CREATE_ADMIN VARCHAR2(32)                  NOT NULL,
	UPDATE_ADMIN VARCHAR2(32),
	UPDATED_AT NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_DECLARATION_PACKAGE IS '报单套餐';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.PACKAGE_NAME IS '套餐名称';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.LEVEL_ID IS '所属报单级别ID';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.AMOUNT IS '报单套餐金额';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.PV IS '报单套餐PV';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.PACKAGE_CONTENT IS '套餐内容';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.CREATE_ADMIN IS '创建人';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.UPDATE_ADMIN IS '更新人';
COMMENT ON COLUMN AR_DECLARATION_PACKAGE.UPDATED_AT IS '更新时间';
CREATE UNIQUE INDEX AR_DEC_P_NAME_UNINDEX ON AR_DECLARATION_PACKAGE(PACKAGE_NAME);

-- 商城商品
BEGIN
	EXECUTE IMMEDIATE 'DROP TABLE AR_SHOP_GOODS';
	EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_SHOP_GOODS
(
	ID         VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
	GOODS_NAME VARCHAR2(255)                    NOT NULL,
	CATE_ID VARCHAR2(32)                    NOT NULL,
	TYPE       NUMBER(2) DEFAULT 1        NOT NULL,
	GOODS_NO VARCHAR2(32)                    NOT NULL,
	UNIT VARCHAR2(16)                    NOT NULL,
	COVER VARCHAR2(255)                    NOT NULL,
	IMAGES VARCHAR2(4000)                    NOT NULL,
	CONTENT VARCHAR2(4000)                    NOT NULL,
	SELL_PRICE NUMBER(16, 2) DEFAULT 0.00     NOT NULL,
	MARKET_PRICE NUMBER(16, 2) DEFAULT 0.00     NOT NULL,
	PRICE_PV NUMBER(16, 2) DEFAULT 0.00     NOT NULL,
	STORE_NUMS NUMBER(10) DEFAULT 0            NOT NULL,
	STATUS NUMBER(1) DEFAULT 1        NOT NULL,
	CREATED_AT    NUMBER(10)                      NOT NULL,
  UPDATED_AT    NUMBER(10) DEFAULT 0            NOT NULL,
  SORT    NUMBER(10) DEFAULT 0            NOT NULL
);
COMMENT ON TABLE AR_SHOP_GOODS IS '商品';
COMMENT ON COLUMN AR_SHOP_GOODS.GOODS_NAME IS '商品名称';
COMMENT ON COLUMN AR_SHOP_GOODS.CATE_ID IS '所属分类ID';
COMMENT ON COLUMN AR_SHOP_GOODS.TYPE IS '商品类型';
COMMENT ON COLUMN AR_SHOP_GOODS.GOODS_NO IS '商品编号';
COMMENT ON COLUMN AR_SHOP_GOODS.UNIT IS '商品单位';
COMMENT ON COLUMN AR_SHOP_GOODS.COVER IS '商品封面';
COMMENT ON COLUMN AR_SHOP_GOODS.IMAGES IS '商品图片';
COMMENT ON COLUMN AR_SHOP_GOODS.CONTENT IS '商品内容';
COMMENT ON COLUMN AR_SHOP_GOODS.SELL_PRICE IS '销售价格';
COMMENT ON COLUMN AR_SHOP_GOODS.MARKET_PRICE IS '市场价格';
COMMENT ON COLUMN AR_SHOP_GOODS.PRICE_PV IS '价格PV';
COMMENT ON COLUMN AR_SHOP_GOODS.STORE_NUMS IS '商品库存';
COMMENT ON COLUMN AR_SHOP_GOODS.STATUS IS '是否上架';
COMMENT ON COLUMN AR_SHOP_GOODS.CREATED_AT IS '创建时间';
COMMENT ON COLUMN AR_SHOP_GOODS.UPDATED_AT IS '更新时间';
COMMENT ON COLUMN AR_SHOP_GOODS.SORT IS '排序';

--AR_SHOP_GOODS表结构修改
ALTER TABLE AR_SHOP_GOODS ADD IS_DEL NUMBER(2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_SHOP_GOODS.IS_DEL IS '是否删除';
ALTER TABLE AR_SHOP_GOODS ADD DELETED_AT NUMBER(10) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_SHOP_GOODS.DELETED_AT IS '删除时间';
ALTER TABLE AR_SHOP_GOODS ADD POINT NUMBER(10) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_SHOP_GOODS.POINT IS '兑换积分';
ALTER TABLE AR_SHOP_GOODS ADD SELL_TYPE VARCHAR2(32) DEFAULT '1,2' NOT NULL;
COMMENT ON COLUMN AR_SHOP_GOODS.SELL_TYPE IS '出售方式';

--AR_ORDER_GOODS表结构修改
ALTER TABLE AR_ORDER_GOODS ADD POINT NUMBER(5) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_ORDER_GOODS.POINT IS '兑换积分';

--AR_ORDER表结构修改
ALTER TABLE AR_ORDER ADD PAY_TYPE VARCHAR2(32) DEFAULT 'cash' NOT NULL;
COMMENT ON COLUMN AR_ORDER.PAY_TYPE IS '支付方式';

--AR_CONFIG表数据修改
--AR_CALC_BONUS_QY表结构修改
ALTER TABLE AR_CALC_BONUS_QY ADD ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_QY.ORI_BONUS IS '原奖金';
ALTER TABLE AR_CALC_BONUS_QY ADD RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_QY.RECONSUME_POINTS IS '重复消费积分';
ALTER TABLE AR_CALC_BONUS_QY ADD MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_QY.MANAGE_TAX IS '管理费';
--AR_CALC_BONUS_YC表结构修改
ALTER TABLE AR_CALC_BONUS_YC ADD ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_YC.ORI_BONUS IS '原奖金';
ALTER TABLE AR_CALC_BONUS_YC ADD RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_YC.RECONSUME_POINTS IS '重复消费积分';
ALTER TABLE AR_CALC_BONUS_YC ADD MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS_YC.MANAGE_TAX IS '管理费';
--AR_DEC_ORDER 表结构修改
ALTER TABLE AR_DEC_ORDER RENAME COLUMN REC_USER_NAME TO REC_USER_ID;
ALTER TABLE AR_DEC_ORDER RENAME COLUMN CON_USER_NAME TO CON_USER_ID;
ALTER TABLE AR_DEC_ORDER DROP COLUMN REC_REAL_NAME;
ALTER TABLE AR_DEC_ORDER DROP COLUMN CON_REAL_NAME;
COMMENT ON COLUMN AR_DEC_ORDER.REC_USER_ID IS '推荐人ID';
COMMENT ON COLUMN AR_DEC_ORDER.CON_USER_ID IS '接点人ID';
ALTER TABLE AR_DEC_ORDER ADD DEC_ID VARCHAR2(32) DEFAULT '' NULL;
COMMENT ON COLUMN AR_DEC_ORDER.DEC_ID IS '报单中心ID';
--AR_EMPLOY_LEVEL 表字段修改
-- ALTER TABLE AR_EMPLOY_LEVEL ADD RX_PERCENT NUMBER(16,2) DEFAULT 0.00 NOT NULL;
-- COMMENT ON COLUMN AR_EMPLOY_LEVEL.RX_PERCENT IS '荣衔奖比例';
-- ALTER TABLE AR_EMPLOY_LEVEL ADD OTHER_DEPART_PERF NUMBER(16,2) DEFAULT 0.00 NOT NULL;
-- COMMENT ON COLUMN AR_EMPLOY_LEVEL.OTHER_DEPART_PERF IS '去除最大部门，其它部门的累计推荐业绩';
--AR_DECLARATION_LEVEL 表字段修改
-- ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_ONE NUMBER(10) DEFAULT 1 NOT NULL;
-- COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_ONE IS '共享奖推荐1人拿的代数';
-- ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_TWO NUMBER(10) DEFAULT 1 NOT NULL;
-- COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_TWO IS '共享奖推荐2人拿的代数';
-- ALTER TABLE AR_DECLARATION_LEVEL ADD GL_ODD_DEEP_THREE NUMBER(10) DEFAULT 1 NOT NULL;
-- COMMENT ON COLUMN AR_DECLARATION_LEVEL.GL_ODD_DEEP_THREE IS '共享奖推荐3人拿的代数';
-- ALTER TABLE AR_DECLARATION_LEVEL ADD INCOME_CAP NUMBER(16,2) DEFAULT 0.00 NOT NULL;
-- COMMENT ON COLUMN AR_DECLARATION_LEVEL.INCOME_CAP IS '共享奖推荐3人拿的代数';
--AR_PERF_PERIOD 表字段修改
ALTER TABLE AR_PERF_PERIOD ADD PV_PSS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_PERF_PERIOD.PV_PSS IS '推荐团队业绩';
--AR_PERF_MONTH 表字段修改
ALTER TABLE AR_PERF_MONTH ADD PV_PSS NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_PERF_MONTH.PV_PSS IS '推荐团队业绩';
ALTER TABLE AR_PERF_MONTH ADD PV_PSS_TOTAL NUMBER(16,3) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_PERF_MONTH.PV_PSS_TOTAL IS '累计推荐团队业绩';
--AR_CALC_BONUS 表字段修改
ALTER TABLE AR_CALC_BONUS ADD BONUS_BD NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_BD IS '报单奖';
ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_BD NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_BD IS '报单奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD BONUS_TG NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_TG IS '推广奖';
ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_TG NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_TG IS '推广奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD BONUS_YJ NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_YJ IS '业绩奖';
ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_YJ NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_YJ IS '业绩奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_QY NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_QY IS '团队奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_YC NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_YC IS '荣衔奖奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD BONUS_GX NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_GX IS '共享奖';
ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_GX NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_GX IS '共享奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD BONUS_GL NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.BONUS_GL IS '管理奖';
ALTER TABLE AR_CALC_BONUS ADD ORI_BONUS_GL NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.ORI_BONUS_GL IS '管理奖原奖金';

ALTER TABLE AR_CALC_BONUS ADD RECONSUME_POINTS NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.RECONSUME_POINTS IS '复消积分';

ALTER TABLE AR_CALC_BONUS ADD MANAGE_TAX NUMBER(16,3) default 0.000 NOT NULL;
COMMENT ON COLUMN AR_CALC_BONUS.MANAGE_TAX IS '管理费';

--AR_USER_PERF 表字段修改
ALTER TABLE AR_USER_PERF ADD PV_PSS NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_PERF.PV_PSS IS '推荐团队累计业绩';

--AR_USER_BONUS 表字段修改
ALTER TABLE AR_USER_BONUS ADD BD_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.BD_TOTAL IS '报单奖累计';
ALTER TABLE AR_USER_BONUS ADD TG_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.TG_TOTAL IS '推广奖累计';
ALTER TABLE AR_USER_BONUS ADD YJ_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.YJ_TOTAL IS '业绩奖累计';
ALTER TABLE AR_USER_BONUS ADD GX_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.GX_TOTAL IS '共享奖累计';
ALTER TABLE AR_USER_BONUS ADD GL_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.GL_TOTAL IS '管理奖累计';

ALTER TABLE AR_USER_BONUS ADD RECONSUME_POINTS NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.RECONSUME_POINTS IS '复消积分';
ALTER TABLE AR_USER_BONUS ADD RECONSUME_POINTS_EXPIRED NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.RECONSUME_POINTS_EXPIRED IS '过期的复消积分';
ALTER TABLE AR_USER_BONUS ADD RECONSUME_POINTS_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.RECONSUME_POINTS_TOTAL IS '复消积分累计';
ALTER TABLE AR_USER_BONUS ADD MANAGE_TAX NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.MANAGE_TAX IS '管理费累计';

ALTER TABLE AR_USER_BONUS ADD ORI_QY_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_QY_TOTAL IS '团队奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_YC_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_YC_TOTAL IS '荣衔奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_BD_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_BD_TOTAL IS '报单奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_TG_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_TG_TOTAL IS '推广奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_YJ_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_YJ_TOTAL IS '业绩奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_GX_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_GX_TOTAL IS '共享奖原奖金累计';
ALTER TABLE AR_USER_BONUS ADD ORI_GL_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.ORI_GL_TOTAL IS '管理奖原奖金累计';

ALTER TABLE AR_USER_BONUS ADD BONUS_TOTAL NUMBER(16,2) DEFAULT 0 NOT NULL;
COMMENT ON COLUMN AR_USER_BONUS.BONUS_TOTAL IS '总奖金累计';

--新增表如下：
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_FLOW_RECONSUME_POINTS';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_FLOW_RECONSUME_POINTS
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000 NOT NULL,
	TOTAL NUMBER(16,3) DEFAULT 0.000 NOT NULL,
	IS_INCR NUMBER(1) DEFAULT 1 NOT NULL,
	REMARK VARCHAR2(255) NOT NULL,
	REMARK_IS_SHOW NUMBER(1) DEFAULT 1 NOT NULL,
	DEAL_TYPE_ID VARCHAR2(32),
	DEAL_TYPE_IS_PRESET NUMBER(1) DEFAULT 1 NOT NULL,
	ADMIN_NAME VARCHAR2(32),
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_MONTH DATE NOT NULL,
	CREATED_AT NUMBER(10) NOT NULL,
	DELETED NUMBER(1) DEFAULT 0 NOT NULL,
	DELETED_AT NUMBER(10) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
/

COMMENT ON TABLE AR_FLOW_RECONSUME_POINTS IS '重消积分流水'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.LAST_DEC_LV IS '记录时会员级别'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.LAST_EMP_LV IS '记录时会员聘级'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.LAST_STATUS IS '记录时状态'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.AMOUNT IS '金额'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.TOTAL IS '当前总金额'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.IS_INCR IS '是否增加'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.REMARK IS '备注'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.REMARK_IS_SHOW IS '备注是否显示'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.DEAL_TYPE_ID IS '交易类型ID'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.DEAL_TYPE_IS_PRESET IS '交易类型是否预置'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.ADMIN_NAME IS '操作人名称'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.PERIOD_NUM IS '所在期数'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.P_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.DELETED IS '是否删除'
/

COMMENT ON COLUMN AR_FLOW_RECONSUME_POINTS.DELETED_AT IS '删除时间'
/

CREATE INDEX AR_FLOW_RP_USER_ID_INDEX
	ON AR_FLOW_RECONSUME_POINTS (USER_ID)
/

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_BD';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_BD
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0             NOT NULL,
	FROM_USER_ID VARCHAR2(32) NOT NULL,
  LAST_FROM_DEC_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_EMP_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000     NOT NULL,
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_YEAR NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_CALC_MONTH DATE NOT NULL,
	LOGS VARCHAR2(2000) DEFAULT '',
	CREATED_AT NUMBER(10) NOT NULL,
	ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL,
	RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL,
	MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
/

COMMENT ON TABLE AR_CALC_BONUS_BD IS '报单奖结算记录'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_DEC_LV IS '结算时会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_EMP_LV IS '结算时会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_STATUS IS '结算时状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.FROM_USER_ID IS '来源会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_FROM_DEC_LV IS '结算时来源会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_FROM_EMP_LV IS '结算时来源会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LAST_FROM_STATUS IS '结算时来源状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.AMOUNT IS '奖金金额'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.PERIOD_NUM IS '结算期数'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.CALC_YEAR IS '所在结算年'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.P_CALC_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.LOGS IS '日志'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.ORI_BONUS IS '原奖金'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.RECONSUME_POINTS IS '重复消费积分'
/

COMMENT ON COLUMN AR_CALC_BONUS_BD.MANAGE_TAX IS '管理费'
/


BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_TG';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_TG
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0             NOT NULL,
	FROM_USER_ID VARCHAR2(32) NOT NULL,
  LAST_FROM_DEC_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_EMP_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000     NOT NULL,
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_YEAR NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_CALC_MONTH DATE NOT NULL,
	LOGS VARCHAR2(2000) DEFAULT '',
	CREATED_AT NUMBER(10) NOT NULL,
	ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL,
	RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL,
	MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
/

COMMENT ON TABLE AR_CALC_BONUS_TG IS '推广奖结算记录'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_DEC_LV IS '结算时会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_EMP_LV IS '结算时会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_STATUS IS '结算时状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.FROM_USER_ID IS '来源会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_FROM_DEC_LV IS '结算时来源会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_FROM_EMP_LV IS '结算时来源会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LAST_FROM_STATUS IS '结算时来源状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.AMOUNT IS '奖金金额'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.PERIOD_NUM IS '结算期数'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.CALC_YEAR IS '所在结算年'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.P_CALC_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.LOGS IS '日志'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.ORI_BONUS IS '原奖金'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.RECONSUME_POINTS IS '重复消费积分'
/

COMMENT ON COLUMN AR_CALC_BONUS_TG.MANAGE_TAX IS '管理费'
/


BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_YJ';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_YJ
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0             NOT NULL,
  FROM_USER_ID VARCHAR2(32) NOT NULL,
  LAST_FROM_DEC_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_EMP_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000     NOT NULL,
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_YEAR NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_CALC_MONTH DATE NOT NULL,
	LOGS VARCHAR2(2000) DEFAULT '',
	CREATED_AT NUMBER(10) NOT NULL,
	ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL,
	RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL,
	MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
/

COMMENT ON TABLE AR_CALC_BONUS_YJ IS '业绩奖结算记录'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_DEC_LV IS '结算时会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_EMP_LV IS '结算时会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_STATUS IS '结算时状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.FROM_USER_ID IS '来源会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_FROM_DEC_LV IS '结算时来源会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_FROM_EMP_LV IS '结算时来源会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LAST_FROM_STATUS IS '结算时来源状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.AMOUNT IS '奖金金额'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.PERIOD_NUM IS '结算期数'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.CALC_YEAR IS '所在结算年'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.P_CALC_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.LOGS IS '日志'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.ORI_BONUS IS '原奖金'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.RECONSUME_POINTS IS '重复消费积分'
/

COMMENT ON COLUMN AR_CALC_BONUS_YJ.MANAGE_TAX IS '管理费'
/


BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_GX';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_GX
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0             NOT NULL,
	FROM_USER_ID VARCHAR2(32) NOT NULL,
  LAST_FROM_DEC_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_EMP_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000     NOT NULL,
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_YEAR NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_CALC_MONTH DATE NOT NULL,
	LOGS VARCHAR2(2000) DEFAULT '',
	CREATED_AT NUMBER(10) NOT NULL,
	ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL,
	RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL,
	MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
CREATE INDEX AKBONUS.AR_CALC_B_GX_USER_ID ON AR_CALC_BONUS_GX(USER_ID);
CREATE INDEX AKBONUS.AR_CALC_B_GX_FROM_USER_ID ON AR_CALC_BONUS_GX(FROM_USER_ID);
CREATE INDEX AKBONUS.AR_CALC_B_GX_PERIOD_NUM ON AR_CALC_BONUS_GX(PERIOD_NUM);
/

COMMENT ON TABLE AR_CALC_BONUS_GX IS '共享奖结算记录'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_DEC_LV IS '结算时会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_EMP_LV IS '结算时会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_STATUS IS '结算时状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.FROM_USER_ID IS '来源会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_FROM_DEC_LV IS '结算时来源会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_FROM_EMP_LV IS '结算时来源会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LAST_FROM_STATUS IS '结算时来源状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.AMOUNT IS '奖金金额'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.PERIOD_NUM IS '结算期数'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.CALC_YEAR IS '所在结算年'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.P_CALC_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.LOGS IS '日志'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.ORI_BONUS IS '原奖金'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.RECONSUME_POINTS IS '重复消费积分'
/

COMMENT ON COLUMN AR_CALC_BONUS_GX.MANAGE_TAX IS '管理费'
/

BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_CALC_BONUS_GL';
EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_CALC_BONUS_GL
(
	ID VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL
		PRIMARY KEY,
	USER_ID VARCHAR2(32) NOT NULL,
	LAST_DEC_LV VARCHAR2(32) DEFAULT '',
	LAST_EMP_LV VARCHAR2(32) DEFAULT '',
	LAST_STATUS NUMBER(1) DEFAULT 0             NOT NULL,
	FROM_USER_ID VARCHAR2(32) NOT NULL,
  LAST_FROM_DEC_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_EMP_LV VARCHAR2(32) DEFAULT '',
  LAST_FROM_STATUS NUMBER(1) DEFAULT 0 NOT NULL,
	AMOUNT NUMBER(16,3) DEFAULT 0.000     NOT NULL,
	PERIOD_NUM NUMBER(10) NOT NULL,
	CALC_YEAR NUMBER(10) NOT NULL,
	CALC_MONTH NUMBER(10) NOT NULL,
	P_CALC_MONTH DATE NOT NULL,
	LOGS VARCHAR2(2000) DEFAULT '',
	CREATED_AT NUMBER(10) NOT NULL,
	ORI_BONUS NUMBER(16,3) DEFAULT 0 NOT NULL,
	RECONSUME_POINTS NUMBER(16,3) DEFAULT 0 NOT NULL,
	MANAGE_TAX NUMBER(16,3) DEFAULT 0 NOT NULL
)
    PARTITION BY RANGE(P_CALC_MONTH)
    INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
    PARTITION P0 VALUES LESS THAN (TO_DATE('2019-03-01','YYYY-MM-DD'))
);
/

COMMENT ON TABLE AR_CALC_BONUS_GL IS '管理奖结算记录'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.USER_ID IS '会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_DEC_LV IS '结算时会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_EMP_LV IS '结算时会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_STATUS IS '结算时状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.FROM_USER_ID IS '来源会员ID'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_FROM_DEC_LV IS '结算时来源会员级别'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_FROM_EMP_LV IS '结算时来源会员聘级'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LAST_FROM_STATUS IS '结算时来源状态'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.AMOUNT IS '奖金金额'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.PERIOD_NUM IS '结算期数'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.CALC_YEAR IS '所在结算年'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.CALC_MONTH IS '所在结算月'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.P_CALC_MONTH IS '表分区的日期索引'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.LOGS IS '日志'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.CREATED_AT IS '创建时间'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.ORI_BONUS IS '原奖金'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.RECONSUME_POINTS IS '重复消费积分'
/

COMMENT ON COLUMN AR_CALC_BONUS_GL.MANAGE_TAX IS '管理费'
/

-- 老系统用户表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_TMP_OLD_USER';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_TMP_OLD_USER
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_NAME         VARCHAR2(16)                    NOT NULL,
  REAL_NAME         VARCHAR2(128)                    NOT NULL,
  REC_USER_NAME  VARCHAR2(16)                    NOT NULL,
  REC_REAL_NAME  VARCHAR2(128)                    NOT NULL,
  NET_USER_NAME  VARCHAR2(16)                    NOT NULL,
  NET_REAL_NAME  VARCHAR2(128)                    NOT NULL,
  SORT  NUMBER(10) DEFAULT 0                      NOT NULL
);
COMMENT ON TABLE AR_TMP_OLD_USER IS '老系统会员关系临时表';
COMMENT ON COLUMN AR_TMP_OLD_USER.USER_NAME IS '编号';
COMMENT ON COLUMN AR_TMP_OLD_USER.REAL_NAME IS '名称';
COMMENT ON COLUMN AR_TMP_OLD_USER.REC_USER_NAME IS '推荐人编号';
COMMENT ON COLUMN AR_TMP_OLD_USER.REC_REAL_NAME IS '推荐人姓名';
COMMENT ON COLUMN AR_TMP_OLD_USER.NET_USER_NAME IS '安置人编号';
COMMENT ON COLUMN AR_TMP_OLD_USER.NET_REAL_NAME IS '安置人姓名';
COMMENT ON COLUMN AR_TMP_OLD_USER.SORT IS '排序';

CREATE INDEX AR_TO_USER_USER_NAME ON AR_TMP_OLD_USER(USER_NAME);
CREATE INDEX AR_TO_USER_REC_USER_NAME ON AR_TMP_OLD_USER(REC_USER_NAME);
CREATE INDEX AR_TO_USER_NET_USER_NAME ON AR_TMP_OLD_USER(NET_USER_NAME);
CREATE INDEX AR_TO_USER_SORT ON AR_TMP_OLD_USER(SORT);
COMMIT ;

-- 老系统会员关系临时表
BEGIN
    EXECUTE IMMEDIATE 'DROP TABLE AR_TMP_OLD_NETWORK';
    EXCEPTION WHEN OTHERS THEN NULL;
END;
CREATE TABLE AR_TMP_OLD_NETWORK
(
  ID          VARCHAR2(32) DEFAULT SYS_GUID() NOT NULL PRIMARY KEY,
  USER_NAME         VARCHAR2(16)                    NOT NULL,
  REAL_NAME         VARCHAR2(128)                    NOT NULL,
  PARENT_USER_NAME  VARCHAR2(16)                    NOT NULL,
  PARENT_REAL_NAME  VARCHAR2(128)                    NOT NULL,
  NET_USER_NAME  VARCHAR2(16)                    NOT NULL,
  NET_REAL_NAME  VARCHAR2(128)                    NOT NULL,
  SORT  NUMBER(10) DEFAULT 0                      NOT NULL
);
COMMENT ON TABLE AR_TMP_OLD_NETWORK IS '老系统会员关系临时表';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.USER_NAME IS '编号';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.REAL_NAME IS '姓名';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.PARENT_USER_NAME IS '上级编号';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.PARENT_REAL_NAME IS '上级姓名';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.NET_USER_NAME IS '安置人编号';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.NET_REAL_NAME IS '安置人姓名';
COMMENT ON COLUMN AR_TMP_OLD_NETWORK.SORT IS '排序';

CREATE INDEX AR_TO_NETWORK_USER_NAME ON AR_TMP_OLD_NETWORK(USER_NAME);
CREATE INDEX AR_TO_NETWORK_PARENT_USER_NAME ON AR_TMP_OLD_NETWORK(PARENT_USER_NAME);
CREATE INDEX AR_TO_NETWORK_NET_USER_NAME ON AR_TMP_OLD_NETWORK(NET_USER_NAME);
CREATE INDEX AR_TO_NETWORK_SORT ON AR_TMP_OLD_NETWORK(SORT);
COMMIT ;