/*
 Navicat Premium Data Transfer

 Source Server         : localhost
 Source Server Type    : MySQL
 Source Server Version : 80030
 Source Host           : localhost:3306
 Source Schema         : invitation

 Target Server Type    : MySQL
 Target Server Version : 80030
 File Encoding         : 65001

 Date: 22/11/2022 18:57:34
*/

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for aa1_eventlog
-- ----------------------------
DROP TABLE IF EXISTS `aa1_eventlog`;
CREATE TABLE `aa1_eventlog` (
  `id` int NOT NULL AUTO_INCREMENT,
  `create_time` datetime NOT NULL,
  `account` varchar(64) NOT NULL,
  `operator` varchar(64) CHARACTER SET utf8mb4  NOT NULL COMMENT 'twitter_id',
  `event` varchar(32) NOT NULL COMMENT '1:注册 2:lv1关联推荐 3:lv2关联人推荐',
  `point` int NOT NULL COMMENT '奖励积分',
  PRIMARY KEY (`id`),
  UNIQUE KEY `user_index` (`create_time`,`account`,`operator`),
  KEY `account` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=47 DEFAULT CHARSET=utf8mb4 ;

-- ----------------------------
-- Table structure for aa1_leadboard
-- ----------------------------
DROP TABLE IF EXISTS `aa1_leadboard`;
CREATE TABLE `aa1_leadboard` (
  `id` int NOT NULL AUTO_INCREMENT,
  `rank` int NOT NULL,
  `account` varchar(64) NOT NULL,
  `twitter` varchar(64) CHARACTER SET utf8mb4  NOT NULL,
  `clan` int NOT NULL,
  `point` varchar(64) NOT NULL,
  PRIMARY KEY (`id`,`account`),
  UNIQUE KEY `account` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=32 DEFAULT CHARSET=utf8mb4 ;

-- ----------------------------
-- Table structure for aa1_user
-- ----------------------------
DROP TABLE IF EXISTS `aa1_user`;
CREATE TABLE `aa1_user` (
  `id` int NOT NULL AUTO_INCREMENT,
  `point` int NOT NULL DEFAULT '0' COMMENT '积分',
  `create_time` datetime DEFAULT NULL,
  `success_time` datetime DEFAULT NULL,
  `account` varchar(64) CHARACTER SET utf8mb4  NOT NULL COMMENT '钱包地址',
  `quest_status` int DEFAULT NULL COMMENT '??',
  `invite_account` varchar(64) CHARACTER SET utf8mb4  DEFAULT NULL COMMENT '推荐人钱包地址',
  `invite_code` varchar(64) DEFAULT NULL,
  `my_invite_code` varchar(64) CHARACTER SET utf8mb4  NOT NULL COMMENT '6-8位推荐码',
  `comefrom` varchar(64) CHARACTER SET utf8mb4  DEFAULT NULL COMMENT '用户所在国家',
  `email` varchar(64) DEFAULT NULL,
  `twitter_account` varchar(64) DEFAULT NULL,
  `discord_account` varchar(64) DEFAULT NULL,
  `clan_member` int NOT NULL DEFAULT '0' COMMENT '关联推荐人数',
  `rank` int DEFAULT NULL,
  PRIMARY KEY (`id`,`account`),
  UNIQUE KEY `account` (`account`),
  KEY `point` (`point` DESC) USING BTREE
) ENGINE=InnoDB AUTO_INCREMENT=150 DEFAULT CHARSET=utf8mb4 ;

-- ----------------------------
-- Table structure for user
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
  `id` int NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
  `create_time` datetime DEFAULT NULL COMMENT 'Create Time',
  `name` varchar(255) DEFAULT NULL,
  `headpic` varchar(255) DEFAULT NULL,
  `account` varchar(255) CHARACTER SET utf8mb4  NOT NULL COMMENT 'btc account id, wallet address',
  `commander` varchar(255) DEFAULT NULL COMMENT 'Uplink commander',
  `cache_c_num` int DEFAULT '0' COMMENT '司令下线数量',
  `ambassador` varchar(255) DEFAULT NULL COMMENT 'Uplink ambassador',
  `cache_a_num` int DEFAULT '0' COMMENT '大使下线数量',
  `rank_level` int NOT NULL DEFAULT '0' COMMENT '0-user / 1-commander / 2-ambassador',
  `email` varchar(255) DEFAULT NULL,
  `comefrom` varchar(255) CHARACTER SET utf8mb4  DEFAULT NULL,
  `bcexp` int DEFAULT '0' COMMENT 'Blockchain experience',
  `followcebg` int DEFAULT '0' COMMENT 'Follow CEBG’s Twitter',
  `joinedcebg` int DEFAULT '0' COMMENT 'Joined CEBG Discord',
  `aboutme` varchar(512) CHARACTER SET utf8mb4  DEFAULT NULL,
  PRIMARY KEY (`id`,`account`) USING BTREE,
  UNIQUE KEY `account` (`account`)
) ENGINE=InnoDB AUTO_INCREMENT=1995 DEFAULT CHARSET=utf8mb4 ;

-- ----------------------------
-- View structure for aa1_rank
-- ----------------------------
DROP VIEW IF EXISTS `aa1_rank`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `aa1_rank` AS
    select @rank:=@rank + 1 AS rank,a.* from
    (select account, `aa1_user`.`twitter_account` AS `twitter_account`,`aa1_user`.`clan_member` AS `clan_member`,`aa1_user`.`point` AS `point` from `aa1_user` WHERE `aa1_user`.`success_time` IS NOT NULL ORDER BY `aa1_user`.`point` desc) a,
    (SELECT @rank:= 0) b;

select row_number() OVER (ORDER BY `aa1_user`.`point` desc )  AS `rank`,`aa1_user`.`id` AS `id`,`aa1_user`.`twitter_account` AS `twitter_account`,`aa1_user`.`clan_member` AS `clan_member`,`aa1_user`.`point` AS `point` from `aa1_user`;

-- ----------------------------
-- View structure for tttt
-- ----------------------------
DROP VIEW IF EXISTS `tttt`;
CREATE ALGORITHM = UNDEFINED SQL SECURITY DEFINER VIEW `tttt` AS select `user`.`account` AS `account` from `user` where (`user`.`rank_level` = 2);

-- ----------------------------
-- Procedure structure for NewProc
-- ----------------------------
DROP PROCEDURE IF EXISTS `NewProc`;
delimiter ;;
CREATE PROCEDURE `NewProc`(param1 int)
BEGIN
  #Routine body goes here...
END
;;
delimiter ;

SET FOREIGN_KEY_CHECKS = 1;
