SET NAMES utf8mb4;

DROP TABLE IF EXISTS `pp_config`;

CREATE TABLE `pp_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `config_name` varchar(100) DEFAULT '' COMMENT '配置名称',
  `config_desc` varchar(500) DEFAULT '' COMMENT '配置描述',
  `config_value` text COMMENT '配置值',
  `add_time` datetime COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `config_name` (`config_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '配置表';

DROP TABLE IF EXISTS `pp_file`;

CREATE TABLE `pp_file` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `file_name` varchar(500) DEFAULT '' COMMENT '文件名',
  `file_type` varchar(200) DEFAULT '' COMMENT '文件类型',
  `file_size` int(11) DEFAULT '0' COMMENT '文件大小，单位：B',
  `file_url` varchar(1000) DEFAULT '' COMMENT '文件相对链接',
  `web_url` varchar(1000) DEFAULT '' COMMENT '对外访问的链接，或者CDN链接',
  `upload_time` datetime COMMENT '上传时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '素材文件表';

DROP TABLE IF EXISTS `pp_member`;

CREATE TABLE `pp_member` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT '账号',
  `salt` varchar(64) NOT NULL COMMENT '盐值',
  `password` varchar(64) DEFAULT NULL COMMENT '密码',
  `register_time` datetime COMMENT '注册时间',
  `avatar` varchar(500) DEFAULT '' COMMENT '头像',
  `nickname` varchar(100) DEFAULT '' COMMENT '昵称',
  `email` varchar(100) DEFAULT '' COMMENT '邮箱',
  `sex` varchar(10) DEFAULT '' COMMENT '性别，0未知1男2女',
  `mobile` varchar(20) DEFAULT '' COMMENT '手机号',
  `ip` varchar(60) DEFAULT '' COMMENT '注册IP',
  `uuid` varchar(64) DEFAULT '' COMMENT 'UUID，全局唯一ID',
  `member_level` smallint(4) NOT NULL DEFAULT 0 COMMENT '用户等级(0~99区间表示用户,100~199区间表示开发者, 200~255区间表示内部管理员)',
  `member_status` tinyint(4) NOT NULL DEFAULT 1 COMMENT '用户状态(0表示禁止,1表示正常)',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '用户表';

DROP TABLE IF EXISTS `pp_requests`;

CREATE TABLE `pp_requests` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `service` varchar(150) NOT NULL DEFAULT '' COMMENT '接口名称',
  `app_key` varchar(64) DEFAULT '' COMMENT 'app_key',
  `uid` int(11) DEFAULT '0' COMMENT '登录的用户ID',
  `ret` int(11) DEFAULT '200' COMMENT '返回状态码',
  `msg` text COMMENT '返回的错误信息',
  `excute_time` int(11) DEFAULT '0' COMMENT '执行的时间，单位毫秒',
  `request_time` datetime COMMENT '完成请求的时间',
  `ip` varchar(60) DEFAULT '' COMMENT '客户端IP',
  `method` varchar(20) DEFAULT '' COMMENT 'HTTP请求方式',
  PRIMARY KEY (`id`),
  KEY `service` (`service`),
  KEY `request_time` (`request_time`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '请求日志表';



DROP TABLE IF EXISTS `pp_apps`;

CREATE TABLE `pp_apps` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_key` varchar(100) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'app_key，客户端key',
  `app_secret` varchar(200) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'app密钥',
  `app_name` varchar(100) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '应用名称',
  `app_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '应用状态(0表示禁止,1表示正常)',
  `app_limit` int(11) NOT NULL DEFAULT '0' COMMENT '应用每日接口限制，0表示无限制',
  `uid` int(11) NOT NULL DEFAULT '0' COMMENT '账号ID',
  `app_owner` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '申请机构/授权机构',
  `verify_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '审核状态，0待审核1审核通过2审核不通过',
  `add_time` datetime DEFAULT NULL COMMENT '创建时间',
  `app_icon` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '应用图标',
  `apply_reason` varchar(2000) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '申请说明',
  `rsa_private_key` text  COMMENT 'RSA密钥',
  `rsa_public_key` text  COMMENT 'RSA公钥',
  `allow_ips` text COMMENT 'App应用访问的IP白名单，没有不限制，多个用英文逗号分割',
  PRIMARY KEY (`id`),
  UNIQUE KEY `app_key` (`app_key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '应用表';

DROP TABLE IF EXISTS `pp_login`;

CREATE TABLE `pp_login`  (
                             `id` int(11) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '自增id',
                             `username` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '登陆username',
                             `login_status` tinyint(4) NOT NULL COMMENT '登陆状态(1登陆成功, 2密码错误, 3账号被禁用, 4不是管理员，5账号不存在)',
                             `login_ip` varchar(60) NOT NULL COMMENT '登陆ip',
                             `login_time` datetime COMMENT '登录时间',
                             PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '登陆日志表';

DROP TABLE IF EXISTS `pp_rights`;

CREATE TABLE `pp_rights` (
  `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'ID',
  `app_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'app_key，空表示全部应用',
  `service` varchar(150) COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '接口服务名称',
  `is_allow` tinyint(4) NOT NULL DEFAULT '1' COMMENT '是否允许，1是0否',
  `admin_uid` int(11) DEFAULT '0' COMMENT '管理员ID',
  `add_time` datetime DEFAULT NULL COMMENT '添加时间',
  `member_type` smallint(6) NOT NULL DEFAULT '0' COMMENT '开发者账号类型,100~199之间,0表示全部类型',
  `service_lower` varchar(150) NOT NULL DEFAULT '' COMMENT '接口服务名称，方便查找',
  `uid` int(11) NOT NULL DEFAULT '0' COMMENT '账号ID,0表示全部账号',
      PRIMARY KEY (`id`),
      KEY `idx_s_ak` (`service`,`app_key`),
      INDEX  (`service_lower`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '接口权限表';

insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.Auth.UserLogin', '0', '', 'app.auth.userlogin', '1', '1', '2020-04-14 14:55:19');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.Auth.AppUserLogin', '0', '', 'app.auth.appuserlogin', '1', '1', '2020-04-14 15:20:52');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.HelloWorld.Say', '0', '', 'app.helloworld.say', '1', '1', '2020-04-14 16:08:10');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.Auth.AppUserLogin', '0', '', 'app.auth.appuserlogin', '1', '1', '2020-04-14 16:08:53');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.Auth.ApplyToken', '0', '', 'app.auth.applytoken', '1', '1', '2020-04-15 10:03:52');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.Auth.ApplyToken', '0', '', 'app.auth.applytoken', '1', '1', '2020-04-15 10:25:09');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.Auth.UserLogin', '0', '', 'app.auth.userlogin', '1', '1', '2020-04-15 10:41:42');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.HelloWorld.HiApp', '0', '', 'app.helloworld.hiapp', '1', '1', '2020-04-15 11:45:28');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '100', 'App.HelloWorld.HiMember', '0', '', 'app.helloworld.himember', '1', '1', '2020-04-15 11:45:28');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.HelloWorld.HiApp', '0', '', 'app.helloworld.hiapp', '1', '1', '2020-04-15 11:45:29');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.HelloWorld.HiMember', '0', '', 'app.helloworld.himember', '1', '1', '2020-04-15 11:45:30');
insert into `pp_rights` ( `member_type`, `service`, `uid`, `app_key`, `service_lower`, `is_allow`, `admin_uid`, `add_time`) values ( '101', 'App.HelloWorld.Say', '0', '', 'app.helloworld.say', '1', '1', '2020-04-15 11:45:32');

DROP TABLE IF EXISTS `pp_task_progress`;

CREATE TABLE `pp_task_progress` (
        `id` bigint(20) NOT NULL AUTO_INCREMENT,
        `title` varchar(200) DEFAULT '' COMMENT '任务标题',
        `trigger_class` varchar(50) DEFAULT '' COMMENT '触发器类名',
        `fire_params` varchar(255) DEFAULT '' COMMENT '需要传递的参数，格式自定',
        `interval_time` int(11) DEFAULT '0' COMMENT '执行间隔，单位：秒',
        `enable` tinyint(1) DEFAULT '1' COMMENT '是否启动，1启动，0禁止',
        `result` text COMMENT '运行的结果，以json格式保存',
        `state` tinyint(1) DEFAULT '0' COMMENT '进程状态，0空闲，1运行中，-1异常退出',
        `last_fire_time` int(11) DEFAULT '0' COMMENT '上一次运行时间',
        `api_params` text COMMENT '接口服务的初始参数',
        `crontab_interval_time` int(11) NOT NULL DEFAULT 60 COMMENT '执行间隔周期时间',
        `crontab_last_run_time` int(11) DEFAULT 0 COMMENT '执行时间',
        `add_time` datetime NULL COMMENT '添加时间',
        PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '计划任务表';

DROP TABLE IF EXISTS `pp_task_mq`;

CREATE TABLE `pp_task_mq` (
    `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    `service` varchar(200) DEFAULT '' COMMENT '接口服务名称',
    `params` text COMMENT 'json格式的参数',
    `create_time` int(11) DEFAULT '0',
    `ext_data` text COMMENT 'json data here',
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '计划任务MQ表';

DROP TABLE IF EXISTS `pp_api_design`;

CREATE TABLE `pp_api_design`  (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `uid` int(11) NULL DEFAULT 0 COMMENT '登录的用户ID',
  `api_name` varchar(100)  NOT NULL COMMENT '接口服务名称',
  `api_modules` varchar(50)  NOT NULL COMMENT '接口模块',
  `api_title` varchar(100)  NOT NULL COMMENT '接口标题',
  `api_desc` text COMMENT '接口描述',
  `api_request_params` text COMMENT '接口请求参数(json)',
  `api_response_params` text COMMENT '接口返回参数(json)',
  `api_response_example` text COMMENT '接口返回示例(json)',
  `add_time` datetime NULL COMMENT '添加时间',
  `is_finish` tinyint(4) NOT NULL DEFAULT 0 COMMENT '是否完成(0表示未完成,1表示已完成)',
  PRIMARY KEY (`id`)
) ENGINE = InnoDB DEFAULT CHARSET= utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '接口设计表';

DROP TABLE IF EXISTS `pp_test_sample`;

CREATE TABLE `pp_test_sample`  (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL DEFAULT 0 COMMENT '登录的用户ID',
  `api_name` varchar(50)  NOT NULL COMMENT '待测试的接口名',
  `sample_name` varchar(50)  NOT NULL COMMENT '用例名字',
  `sample_request` varchar(1024)  NOT NULL COMMENT '用例的请求参数(json)',
  `sample_response` varchar(1024)  NOT NULL COMMENT '用例的返回参数(json)',
  `sample_host` varchar(255)  NOT NULL DEFAULT '' COMMENT '测试域名',
  `access_token` varchar(255)  NOT NULL COMMENT '测试使用的accessToken',
  `sample_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '用例测试结果(0为测试,1测试通过,2测试失败，3网络调用无返回,4未找到配置)',
  `add_time` datetime NULL COMMENT '添加时间',
  `last_time` datetime NULL DEFAULT NULL COMMENT '最后测试时间',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '请求用例表';

DROP TABLE IF EXISTS `pp_test_log`;

CREATE TABLE `pp_test_log`  (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `sample_id` bigint(20) NOT NULL,
  `test_time` datetime NOT NULL COMMENT '测试的时间',
  `test_status` tinyint(4) NOT NULL DEFAULT 0 COMMENT '用例测试结果(0为未测试,1测试通过,2测试失败，3网络调用无返回)',
  `test_result` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '测试结果',
  `test_detail` varchar(1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '失败原因',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '用例测试结果快照表';


DROP TABLE IF EXISTS `pp_sms_cache`;

CREATE TABLE `pp_sms_cache`  (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `aliyunKey` varchar(100) NOT NULL COMMENT '缓存key',
  `code` int(11) NOT NULL COMMENT '验证码',
  `expire_in` int(11) NOT NULL COMMENT '过期时间(时间戳)',
  `times` int(11) NOT NULL COMMENT '尝试次数',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '阿里云短信缓存表';

DROP TABLE IF EXISTS `pp_global_at_config`;

CREATE TABLE `pp_global_at_config`  (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL DEFAULT 0 COMMENT '添加的用户ID',
  `title` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT '配置名称',
  `type` tinyint(4) NOT NULL COMMENT '获取方式(1 App.Auth.UserLogin ; 2 App.Auth.ApplyToken)',
  `param` varchar(512) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '账号参数(json)',
  `num` int(11) NOT NULL DEFAULT 0 COMMENT '测试用例绑定用例数量',
  PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB  CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '全局access token配置表';

DROP TABLE IF EXISTS `pp_requests_limit_log`;

CREATE TABLE `pp_requests_limit_log`  (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT '' COMMENT 'app_key，客户端key',
  `service` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '接口服务',
  `record_time` int(11) NOT NULL DEFAULT 0 COMMENT '请求次数',
  `fail_time` int(11) NOT NULL DEFAULT 0 COMMENT '超出次数',
  `record_day` date NOT NULL COMMENT '记录时间',
  PRIMARY KEY (`id`) USING BTREE,
  UNIQUE INDEX `udx_k_d_s`(`app_key`, `record_day`, `service`) USING BTREE
) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '应用次数限制记录表';

DROP TABLE IF EXISTS `pp_rights_service`;
CREATE TABLE `pp_rights_service` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `service` varchar(150) NOT NULL DEFAULT '' COMMENT '接口服务',
  `service_lower` varchar(150) NOT NULL DEFAULT '' COMMENT '接口服务名称小写，以便查找',
  `service_desc` varchar(1000) DEFAULT '' COMMENT '接口描述',
  `add_time` datetime DEFAULT NULL COMMENT '添加时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `service_lower` (`service_lower`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT = '接口服务权限操作表';

DROP TABLE IF EXISTS `pp_operation`;
CREATE TABLE `pp_operation` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `project` varchar(20) NOT NULL DEFAULT '' COMMENT '项目',
  `path` varchar(255) NOT NULL DEFAULT '' COMMENT '路径',
  `title` varchar(200) DEFAULT '' COMMENT '菜单标题',
  `white_list` text COMMENT '账号ID白名单，多个使用英文逗号分割',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=204 DEFAULT CHARSET=utf8mb4 COMMENT='菜单操作';

INSERT INTO `pp_operation` VALUES ('49', 'admin', '/user', '账号管理', ''), ('50', 'admin', '/user/list', '账号列表', ''), ('51', 'admin', '/user/add', '添加账号', ''), ('52', 'admin', '/user/look-over', '账号信息', ''), ('53', 'admin', '/user/compile\'', '编辑账号', ''), ('55', 'admin', '/application/list', '应用列表', ''), ('56', 'admin', '/application/add', '添加应用', ''), ('57', 'admin', '/application/update', '修改应用', ''), ('64', 'platform', '/application', '应用管理', ''), ('65', 'platform', '/application/list', '应用管理列表', ''), ('66', 'platform', '/permission', '接口权限', ''), ('67', 'platform', '/permission/settings', '接口权限', ''), ('68', 'platform', '/account', '开发者中心', ''), ('69', 'platform', '/account/accountInfo', '开发者资料', ''), ('70', 'platform', '/account/resetPassword', '修改密码', ''), ('71', 'platform', '/account/accountSettings', '修改资料', ''), ('165', 'admin', '/application', '应用管理', ''), ('166', 'admin', '/user/compile', '账号信息修改', ''), ('167', 'admin', '/techzones/apis-mangement', '接口权限', ''), ('168', 'admin', '/techzones', '接口管理', ''), ('169', 'admin', '/techzones/techzones/assignment', '接口权限分配', ''), ('170', 'admin', '/techzones/techzones/assignmentList', '权限预览', ''), ('171', 'admin', '/techzones/techzones/assignmentRules', '接口权限规则设置', ''), ('172', 'admin', '/techzones/techzones/apisList', '接口服务操作列表', ''), ('173', 'admin', '/techzones/apitest', '接口测试', ''), ('174', 'admin', '/techzones/design', '可视化接口设计', ''), ('175', 'admin', '/techzones/apitest/test', '接口测试列表', ''), ('176', 'admin', '/techzones/apitest/add', '添加新用例', ''), ('177', 'admin', '/techzones/apitest/compile', '编辑用例', ''), ('178', 'admin', '/techzones/apitest/look', '查看用例', ''), ('179', 'admin', '/pictures', '素材库', ''), ('180', 'admin', '/techzones/apitest/config', '全局access_token配置', ''), ('181', 'admin', '/pictures/assets_manage', '文件管理', ''), ('182', 'admin', '/pictures/assets_upload', '上传文件', ''), ('183', 'admin', '/account', '个人中心', ''), ('184', 'admin', '/account/accountInfo', '个人资料', ''), ('185', 'admin', '/account/loginRecord', '最近登录', ''), ('186', 'admin', '/account/resetPassword', '修改密码', ''), ('187', 'admin', '/account/accountSettings', '个人资料修改', ''), ('188', 'admin', '/configuration', '配置管理', ''), ('189', 'admin', '/configuration/list', '配置管理列表', ''), ('190', 'admin', '/configuration/add', '添加配置', ''), ('191', 'admin', '/scheduledtask', '计划任务', ''), ('192', 'admin', '/configuration/edit', '修改配置', ''), ('193', 'admin', '/scheduledtask/list', '计划任务列表', ''), ('194', 'admin', '/scheduledtask/add', '添加计划任务', ''), ('195', 'admin', '/scheduledtask/edit', '编辑计划任务', ''), ('196', 'admin', '/database/statis', '数据库统计', ''), ('197', 'admin', '/stats/port_stats', '接口统计', ''), ('198', 'admin', '/database', '数据库管理', ''), ('199', 'admin', '/database/process', '数据库实时进程', ''), ('200', 'admin', '/stats', '统计', ''), ('201', 'admin', '/stats/register_stats', '注册统计', ''), ('202', 'admin', '/stats/login_stats', '登录统计', ''), ('203', 'admin', '/stats/accessLog', '访问日志', '');

DROP TABLE IF EXISTS `pp_operation_permission`;
CREATE TABLE `pp_operation_permission` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `op_id` int(11) NOT NULL DEFAULT '0' COMMENT '菜单操作ID',
  `is_allow` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否允许，1允许0禁止',
  `member_level` smallint(6) NOT NULL DEFAULT '0',
  `project` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=123 DEFAULT CHARSET=utf8mb4 COMMENT='菜单操作授权';

INSERT INTO `pp_operation_permission` VALUES ('55', '68', '1', '100', 'platform'), ('56', '68', '1', '101', 'platform'), ('57', '69', '1', '101', 'platform'), ('58', '69', '1', '100', 'platform'), ('59', '71', '1', '101', 'platform'), ('60', '71', '1', '100', 'platform'), ('61', '70', '1', '101', 'platform'), ('62', '70', '1', '100', 'platform'), ('65', '67', '1', '101', 'platform'), ('66', '67', '1', '100', 'platform'), ('67', '66', '1', '101', 'platform'), ('68', '66', '1', '100', 'platform'), ('71', '64', '1', '100', 'platform'), ('72', '64', '1', '101', 'platform'), ('74', '52', '1', '200', 'admin'), ('75', '50', '1', '200', 'admin'), ('76', '53', '1', '200', 'admin'), ('77', '166', '1', '200', 'admin'), ('78', '183', '1', '200', 'admin'), ('79', '51', '1', '200', 'admin'), ('80', '174', '1', '200', 'admin'), ('81', '184', '1', '200', 'admin'), ('82', '178', '1', '200', 'admin'), ('83', '187', '1', '200', 'admin'), ('84', '180', '1', '200', 'admin'), ('85', '185', '1', '200', 'admin'), ('86', '177', '1', '200', 'admin'), ('87', '186', '1', '200', 'admin'), ('88', '176', '1', '200', 'admin'), ('89', '56', '1', '200', 'admin'), ('90', '49', '1', '200', 'admin'), ('92', '57', '1', '200', 'admin'), ('93', '175', '1', '200', 'admin'), ('94', '188', '1', '200', 'admin'), ('95', '190', '1', '200', 'admin'), ('96', '192', '1', '200', 'admin'), ('97', '173', '1', '200', 'admin'), ('98', '171', '1', '200', 'admin'), ('99', '170', '1', '200', 'admin'), ('100', '169', '1', '200', 'admin'), ('101', '189', '1', '200', 'admin'), ('102', '172', '1', '200', 'admin'), ('103', '198', '1', '200', 'admin'), ('104', '199', '1', '200', 'admin'), ('105', '196', '1', '200', 'admin'), ('106', '179', '1', '200', 'admin'), ('107', '181', '1', '200', 'admin'), ('108', '167', '1', '200', 'admin'), ('109', '182', '1', '200', 'admin'), ('110', '168', '1', '200', 'admin'), ('111', '191', '1', '200', 'admin'), ('112', '201', '1', '200', 'admin'), ('113', '197', '1', '200', 'admin'), ('114', '194', '1', '200', 'admin'), ('115', '195', '1', '200', 'admin'), ('116', '202', '1', '200', 'admin'), ('117', '203', '1', '200', 'admin'), ('118', '193', '1', '200', 'admin'), ('119', '200', '1', '200', 'admin'), ('121', '55', '1', '200', 'admin'), ('122', '165', '1', '200', 'admin');

INSERT INTO `pp_operation_permission` ( `member_level`, `project`, `op_id`, `is_allow`) values ( '100', 'platform', '65', '1');
INSERT INTO `pp_operation_permission` ( `member_level`, `project`, `op_id`, `is_allow`) values ( '101', 'platform', '65', '1');

DROP TABLE IF EXISTS `pp_mall_config`;
CREATE TABLE `pp_mall_config` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `config_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '配置名称',
  `config_desc` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '配置描述',
  `config_value` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci COMMENT '配置值',
  `add_time` datetime DEFAULT NULL COMMENT '创建时间',
  PRIMARY KEY (`id`),
  UNIQUE KEY `config_name` (`config_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='商城配置表';

DROP TABLE IF EXISTS `pp_mall_flow`;
CREATE TABLE `pp_mall_flow` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `member_id` int(11) NOT NULL,
  `product_name` varchar(200) NOT NULL DEFAULT '' COMMENT '接口名称',
  `product_key` varchar(100) NOT NULL DEFAULT '' COMMENT '接口服务',
  `product_key_lower` varchar(100) NOT NULL DEFAULT '' COMMENT '接口服务，小写',
  `total_amount` int(11) NOT NULL DEFAULT '0' COMMENT '总次数',
  `used_amount` int(11) NOT NULL DEFAULT '0' COMMENT '已使用次数',
  `expire_time` bigint(11) NOT NULL DEFAULT '0' COMMENT '过期时间戳',
  `add_time` datetime DEFAULT NULL,
  `flow_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '流量套餐状态，0已失效10未使用20使用中30已用完40已过期',
  `product_type` varchar(50) NOT NULL DEFAULT '' COMMENT '接口套餐类型',
  `order_id` varchar(100) NOT NULL DEFAULT '',
  `username` varchar(50) NOT NULL DEFAULT '',
  `finish_time` datetime DEFAULT NULL COMMENT '消耗完时间',
  PRIMARY KEY (`id`),
  KEY `member_id` (`member_id`),
  KEY `product_key_lower` (`product_key_lower`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='接口流量套餐';

DROP TABLE IF EXISTS `pp_mall_order`;
CREATE TABLE `pp_mall_order` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `member_id` int(11) NOT NULL DEFAULT '0' COMMENT '会员ID',
  `order_id` varchar(100) NOT NULL DEFAULT '' COMMENT '订单编号',
  `order_name` varchar(500) NOT NULL DEFAULT '' COMMENT '订单名称',
  `price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '订单总价格，单位：元',
  `add_time` datetime DEFAULT NULL COMMENT '下单时间',
  `product_key` varchar(200) NOT NULL COMMENT '产品key',
  `product_type` varchar(50) NOT NULL COMMENT '产品类型',
  `product_expire_time` int(11) NOT NULL COMMENT '有效时间，单位：秒',
  `product_amount` int(11) NOT NULL COMMENT '产品规格数量',
  `order_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '订单状态，0待支付10已支付20已购买30已退款40已取消',
  `product_id` int(11) NOT NULL DEFAULT '0' COMMENT '产品ID',
  `product_expire_time_desc` varchar(100) NOT NULL DEFAULT '' COMMENT '产品有效时间描述',
  `username` varchar(50) NOT NULL DEFAULT '' COMMENT '账号',
  `num` int(11) NOT NULL DEFAULT '0' COMMENT '购买数量',
  `pay_type` varchar(20) NOT NULL DEFAULT '' COMMENT '支付方式，alipay支付宝，paypal，cash现金',
  `note` text COMMENT '买家备注',
  `is_deliver` tinyint(4) NOT NULL DEFAULT '0' COMMENT '是否发货，1是0否',
  `pay_time` datetime DEFAULT NULL COMMENT '支付时间',
  `third_payment_id` varchar(40) NOT NULL DEFAULT '' COMMENT '第三方支付ID',
  PRIMARY KEY (`id`),
  UNIQUE KEY `order_id` (`order_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DROP TABLE IF EXISTS `pp_mall_product`;
CREATE TABLE `pp_mall_product` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `product_name` varchar(200) NOT NULL DEFAULT '' COMMENT '产品名称',
  `product_key` varchar(100) NOT NULL DEFAULT '' COMMENT '产品key',
  `product_type` varchar(50) NOT NULL DEFAULT '' COMMENT '产品类型，api_free为免费试用接口流量，api_buy为付费购买接口流量',
  `price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '产品售价，单位：元',
  `original_price` decimal(10,2) NOT NULL DEFAULT '0.00' COMMENT '产品原始价格，用于对比，单位：元',
  `amount` int(11) NOT NULL DEFAULT '1' COMMENT '产品规格数量，例如接口流量多少次',
  `expire_time` int(11) NOT NULL DEFAULT '86400' COMMENT '产品有效时间，单位：秒，多少秒内有效',
  `product_desc` text COMMENT '套餐说明',
  `product_status` tinyint(4) NOT NULL DEFAULT '1' COMMENT '产品状态，0关闭1正常',
  `add_time` datetime DEFAULT NULL COMMENT '添加时间',
  `expire_time_desc` varchar(100) DEFAULT '' COMMENT '有效时间描述',
  `product_key_lower` varchar(200) NOT NULL DEFAULT '' COMMENT '小写',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service', '205', 'admin', '服务大厅', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/set-meal', '206', 'admin', '接口流量套餐', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/set-meal/list', '207', 'admin', '接口流量套餐列表', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/set-meal/add', '208', 'admin', '添加套餐', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/order-manage', '209', 'admin', '订单管理', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/set-meal-manage', '210', 'admin', '套餐管理', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/config', '211', 'admin', '支付配置', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service', '212', 'platform', '服务大厅', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/my-order', '213', 'platform', '我的订单', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/service/my-set-meal', '214', 'platform', '我的套餐', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/place-an-order', '216', 'platform', '下单', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/place-an-order/index', '217', 'platform', '下单流程', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/place-an-order/result', '218', 'platform', '下单结果', '');

insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '125', '101', 'platform', '65', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '126', '100', 'platform', '65', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '127', '101', 'platform', '69', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '128', '100', 'platform', '69', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '131', '100', 'platform', '212', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '132', '101', 'platform', '212', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '133', '100', 'platform', '213', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '134', '101', 'platform', '213', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '135', '100', 'platform', '215', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '136', '100', 'platform', '216', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '137', '101', 'platform', '216', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '138', '100', 'platform', '217', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '139', '101', 'platform', '217', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '140', '101', 'platform', '218', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '141', '100', 'platform', '218', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '142', '101', 'platform', '215', '1');


DROP TABLE IF EXISTS `pp_work_order`;
CREATE TABLE `pp_work_order` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `order_no` varchar(64) NOT NULL DEFAULT '' COMMENT '订单号',
  `title` text COMMENT '工单标题',
  `module_id` int(11) NOT NULL DEFAULT '0' COMMENT '模块id',
  `problem_desc` text NOT NULL COMMENT '问题描述',
  `email` text COMMENT '邮箱',
  `phone_pre` varchar(255) NOT NULL DEFAULT '' COMMENT '手机前缀',
  `phone` varchar(11) NOT NULL DEFAULT '' COMMENT '手机号码',
  `file_ids` text COMMENT '文件ids',
  `status` tinyint(1) unsigned NOT NULL DEFAULT '1' COMMENT '审核状态：1待受理，2待回复 3已解决 4已关闭',
  `chat_recode` text NOT NULL COMMENT '聊天记录',
  `admin_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户ID',
  `accept_service_id` int(11) NOT NULL DEFAULT '0' COMMENT '受理客户id',
  `accept_service_name` varchar(255) NOT NULL DEFAULT '' COMMENT '受理客户名字',
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL COMMENT '更新时间',
  `app_key` varchar(100) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='工单表';


insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/api-usb-workorder/list', '219', 'platform', '工单列表', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/api-usb-workorder/add', '220', 'platform', '创建工单', '');
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/api-usb-workorder', '221', 'platform', '工单管理', '');

insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '143', '100', 'platform', '219', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '144', '101', 'platform', '219', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '145', '100', 'platform', '220', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '146', '101', 'platform', '220', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '147', '100', 'platform', '221', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '148', '101', 'platform', '221', '1');

DROP TABLE IF EXISTS `pp_app_daily_stat`;
CREATE TABLE `pp_app_daily_stat` (
      `id` int(11) NOT NULL AUTO_INCREMENT,
      `app_key` varchar(100) DEFAULT '' COMMENT '为空时表示全部',
      `stat_day` date DEFAULT NULL COMMENT '统计的日期',
      `total_order` int(11) NOT NULL DEFAULT 0 COMMENT '总订单量',
      `total_user` int(11) NOT NULL DEFAULT '0' COMMENT '总用户数量',
      `add_time` datetime DEFAULT NULL,
      `total_app` int(11) NOT NULL DEFAULT '0' COMMENT 'app数量',
      `app_key_visit` int(11) DEFAULT '0' COMMENT 'app的日活量',
      `user_visit` int(11) DEFAULT '0' COMMENT '用户日活',
      `api_request_times` int(11) DEFAULT '0' COMMENT '接口访问次数',
      PRIMARY KEY (`id`),
      KEY `app_key` (`app_key`),
      KEY `stat_day` (`stat_day`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='应用日常统计汇总';

insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/stats/app_stats', '224', 'admin', '应用统计', '');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '150', '200', 'admin', '224', '1');


ALTER TABLE `pp_member` ADD COLUMN `from_channel`  varchar(100) NOT NULL DEFAULT '' COMMENT '来源';


DROP TABLE IF EXISTS `pp_authorization`;
CREATE TABLE `pp_authorization` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `openid` varchar(10000) NOT NULL DEFAULT '0' COMMENT '第三方平台对应用户的唯一id',
  `unionid` varchar(1000) NOT NULL DEFAULT '0' COMMENT '微信开放平台对应的unionidid',
  `authorization_type` int(11) NOT NULL DEFAULT '0' COMMENT '第三登录类型：0无 1微信 2微信小程序 3qq 4是短信 5程序员客栈 等等',
  `member_id` int(11) NOT NULL DEFAULT '0' COMMENT '版本的用户id',
  `add_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='第三方授权表';


DROP TABLE IF EXISTS `pp_authorization_details`;
CREATE TABLE `pp_authorization_details` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nickname` varchar(255) NOT NULL DEFAULT '' COMMENT '昵称',
  `sex` tinyint(2) unsigned NOT NULL DEFAULT '0' COMMENT '性别：1未知 2男 3女',
  `headimgurl` varchar(10000) NOT NULL DEFAULT '' COMMENT '用户头像url',
  `province` varchar(255) NOT NULL DEFAULT '' COMMENT '省',
  `city` varchar(255) NOT NULL DEFAULT '' COMMENT '城市',
  `country` varchar(255) NOT NULL DEFAULT '' COMMENT '国家',
  `privilege` varchar(1000) NOT NULL DEFAULT '' COMMENT '用户特权信息',
  `add_time` datetime DEFAULT NULL,
  `authorization_id` int(11) NOT NULL DEFAULT '0' COMMENT '关联第三方表',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8mb4 COMMENT='授权详情表';

-- 工单详情菜单权限
insert into `pp_operation` ( `path`, `id`, `project`, `title`, `white_list`) values ( '/api-usb-workorder/info', '227', 'platform', '工单详情', '');

insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '175', '101', 'platform', '227', '1');
insert into `pp_operation_permission` ( `id`, `member_level`, `project`, `op_id`, `is_allow`) values ( '176', '100', 'platform', '227', '1');

SHOW TABLES; -- 最后结束

