/*
Navicat MySQL Data Transfer

Source Server         : localhost_3306
Source Server Version : 50540
Source Host           : localhost:3306
Source Database       : building

Target Server Type    : MYSQL
Target Server Version : 50540
File Encoding         : 65001

Date: 2017-08-18 18:26:39
*/

SET FOREIGN_KEY_CHECKS=0;

-- ----------------------------
-- Table structure for bd_aboutwe
-- ----------------------------
DROP TABLE IF EXISTS `bd_aboutwe`;
CREATE TABLE `bd_aboutwe` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `address` varchar(255) DEFAULT NULL,
  `tell` varchar(255) DEFAULT NULL,
  `content` text,
  `wechat` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL COMMENT '是否显示',
  `updated_at` int(11) DEFAULT NULL,
  `coordinate` varchar(255) DEFAULT NULL,
  `company` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='关于我们';

-- ----------------------------
-- Table structure for bd_activity_receive
-- ----------------------------
DROP TABLE IF EXISTS `bd_activity_receive`;
CREATE TABLE `bd_activity_receive` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `activity_id` int(11) NOT NULL COMMENT '活动编号',
  `source_id` int(11) NOT NULL COMMENT '获取来源ID',
  `amount` decimal(10,2) NOT NULL COMMENT '金额',
  `receive_at` int(11) NOT NULL COMMENT '领取时间',
  `valid_at` int(11) NOT NULL COMMENT '有效时间',
  `updated_at` int(11) NOT NULL COMMENT '最后修改时间',
  `status` tinyint(4) NOT NULL COMMENT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for bd_admin_user
-- ----------------------------
DROP TABLE IF EXISTS `bd_admin_user`;
CREATE TABLE `bd_admin_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `auth_key` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `password_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `status` smallint(6) NOT NULL DEFAULT '10',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  `role` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  `realname` varchar(32) COLLATE utf8_unicode_ci DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `password_reset_token` (`password_reset_token`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- ----------------------------
-- Table structure for bd_advert
-- ----------------------------
DROP TABLE IF EXISTS `bd_advert`;
CREATE TABLE `bd_advert` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(64) DEFAULT NULL COMMENT '图片名称',
  `link` varchar(255) DEFAULT NULL COMMENT '链接地址',
  `imgurl` text NOT NULL COMMENT '广告图片/内容',
  `orderby` smallint(6) DEFAULT '10',
  `created_at` int(11) DEFAULT '0' COMMENT '添加时间',
  `updated_at` int(11) DEFAULT NULL COMMENT '修改时间',
  `created_author` int(11) DEFAULT NULL,
  `click_count` mediumint(8) DEFAULT '0',
  `status` tinyint(4) DEFAULT '0',
  `updated_author` int(11) DEFAULT NULL,
  `hid` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='广告表';

-- ----------------------------
-- Table structure for bd_appointment
-- ----------------------------
DROP TABLE IF EXISTS `bd_appointment`;
CREATE TABLE `bd_appointment` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL COMMENT '预约人',
  `type` tinyint(4) NOT NULL COMMENT '类型',
  `pid` int(11) NOT NULL COMMENT '工地编号',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `booking_time` int(11) NOT NULL COMMENT '预定时间',
  `updated_at` int(11) NOT NULL COMMENT '最后修改时间',
  `applicant_tel` varchar(32) DEFAULT NULL COMMENT '联系电话',
  `applicant_name` varchar(32) DEFAULT NULL COMMENT '联系名称',
  `status` tinyint(4) NOT NULL COMMENT '状态',
  `state` tinyint(4) DEFAULT NULL COMMENT '流程进度',
  `remark` varchar(255) DEFAULT NULL COMMENT '备注信息',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='预约记录';

-- ----------------------------
-- Table structure for bd_area
-- ----------------------------
DROP TABLE IF EXISTS `bd_area`;
CREATE TABLE `bd_area` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `area` varchar(40) NOT NULL,
  `father_id` int(11) DEFAULT NULL,
  `area_id` varchar(6) DEFAULT NULL,
  `father_area_id` varchar(6) DEFAULT NULL,
  `type` tinyint(1) DEFAULT NULL,
  `display` tinyint(1) DEFAULT NULL,
  `ishot` tinyint(1) DEFAULT NULL COMMENT '是否是热门城市',
  `letter` varchar(10) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3527 DEFAULT CHARSET=gbk;

-- ----------------------------
-- Table structure for bd_building
-- ----------------------------
DROP TABLE IF EXISTS `bd_building`;
CREATE TABLE `bd_building` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) unsigned zerofill NOT NULL,
  `title` varchar(32) NOT NULL COMMENT '工地/样板房名称',
  `type` tinyint(4) NOT NULL,
  `latitude` varchar(32) DEFAULT NULL,
  `longitude` varchar(32) DEFAULT NULL,
  `hashcode` varchar(32) DEFAULT NULL,
  `city` varchar(32) NOT NULL COMMENT '城市编号',
  `district` varchar(32) NOT NULL COMMENT '地区编号',
  `address` varchar(32) NOT NULL COMMENT '地址',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `status` tinyint(4) NOT NULL,
  `updated_at` int(11) NOT NULL,
  `layout` varchar(32) DEFAULT NULL COMMENT '户型',
  `acreage` float DEFAULT NULL COMMENT '面积',
  `opening_begin` int(11) DEFAULT NULL COMMENT '可约时间',
  `opening_end` int(11) DEFAULT NULL COMMENT '可约时间',
  `contact` varchar(120) DEFAULT NULL COMMENT '联系方式',
  `stage` varchar(32) DEFAULT NULL COMMENT '装修进度',
  `pattern` varchar(32) DEFAULT NULL COMMENT '装修模式',
  `budget` decimal(10,2) DEFAULT NULL COMMENT '预算',
  `style` varchar(32) DEFAULT NULL COMMENT '风格',
  `manager_id` int(11) NOT NULL COMMENT '项目经理id',
  `designer_id` int(11) NOT NULL COMMENT '设计师id',
  `posted` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=59 DEFAULT CHARSET=utf8 COMMENT='工地样板房表';

-- ----------------------------
-- Table structure for bd_building1
-- ----------------------------
DROP TABLE IF EXISTS `bd_building1`;
CREATE TABLE `bd_building1` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `type` tinyint(4) NOT NULL,
  `latitude` varchar(32) DEFAULT NULL,
  `longitude` varchar(32) DEFAULT NULL,
  `city` varchar(32) NOT NULL COMMENT '城市编号',
  `district` varchar(32) NOT NULL COMMENT '地区编号',
  `adress` varchar(32) NOT NULL COMMENT '地址',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `status` tinyint(4) NOT NULL,
  `updated_at` int(11) NOT NULL,
  `layout` varchar(32) DEFAULT NULL COMMENT '户型',
  `acreage` float DEFAULT NULL COMMENT '面积',
  `opening_begin` int(11) DEFAULT NULL COMMENT '可约时间',
  `opening_end` int(11) DEFAULT NULL COMMENT '可约时间',
  `contact` varchar(120) DEFAULT NULL COMMENT '联系方式',
  `stage` varchar(32) DEFAULT NULL COMMENT '装修进度',
  `pattern` varchar(32) DEFAULT NULL COMMENT '装修模式',
  `budget` decimal(10,2) DEFAULT NULL COMMENT '预算',
  `style` varchar(32) DEFAULT NULL COMMENT '风格',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='工地样板房表';

-- ----------------------------
-- Table structure for bd_comment
-- ----------------------------
DROP TABLE IF EXISTS `bd_comment`;
CREATE TABLE `bd_comment` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `pid` int(11) NOT NULL COMMENT '工地ID',
  `type` tinyint(4) NOT NULL COMMENT '类型',
  `uid` int(11) NOT NULL COMMENT '留言人',
  `reply_uid` int(11) DEFAULT NULL COMMENT '回复人',
  `star` smallint(6) NOT NULL DEFAULT '0' COMMENT '星级',
  `content` varchar(120) DEFAULT NULL COMMENT '评价内容',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COMMENT='评价表\r\n';

-- ----------------------------
-- Table structure for bd_designer
-- ----------------------------
DROP TABLE IF EXISTS `bd_designer`;
CREATE TABLE `bd_designer` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `company` int(11) NOT NULL COMMENT '公司编号',
  `realname` varchar(32) NOT NULL COMMENT '姓名',
  `introduction` text NOT NULL COMMENT '简介',
  `created_at` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL,
  `update_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='设计师';

-- ----------------------------
-- Table structure for bd_feedback
-- ----------------------------
DROP TABLE IF EXISTS `bd_feedback`;
CREATE TABLE `bd_feedback` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL COMMENT '用户ID',
  `contact` varchar(120) DEFAULT NULL COMMENT '联系方式',
  `content` text NOT NULL COMMENT '内容',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `status` tinyint(4) NOT NULL COMMENT '状态',
  `updated_at` int(11) NOT NULL COMMENT '最后处理时间',
  `author` int(11) DEFAULT NULL COMMENT '处理人',
  `remark` text COMMENT '备注',
  `state` tinyint(4) DEFAULT NULL,
  `type` tinyint(4) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='反馈表\r\n';

-- ----------------------------
-- Table structure for bd_image
-- ----------------------------
DROP TABLE IF EXISTS `bd_image`;
CREATE TABLE `bd_image` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `type` tinyint(4) NOT NULL COMMENT '类型',
  `topid` int(11) NOT NULL COMMENT '关联ID',
  `pic` varchar(255) NOT NULL COMMENT '图片地址',
  `thumbnail` varchar(255) DEFAULT NULL COMMENT '缩略图地址',
  `created_at` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=utf8 COMMENT='图片资源';

-- ----------------------------
-- Table structure for bd_information
-- ----------------------------
DROP TABLE IF EXISTS `bd_information`;
CREATE TABLE `bd_information` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `type` tinyint(4) NOT NULL,
  `covers` varchar(255) DEFAULT NULL,
  `content` text NOT NULL,
  `status` tinyint(4) NOT NULL,
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for bd_manager
-- ----------------------------
DROP TABLE IF EXISTS `bd_manager`;
CREATE TABLE `bd_manager` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `company` int(11) NOT NULL COMMENT '公司ID',
  `realname` varchar(32) NOT NULL COMMENT '名称',
  `introduction` varchar(255) NOT NULL COMMENT '简介',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `updated_at` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL COMMENT '状态',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='项目经理';

-- ----------------------------
-- Table structure for bd_migration
-- ----------------------------
DROP TABLE IF EXISTS `bd_migration`;
CREATE TABLE `bd_migration` (
  `version` varchar(180) NOT NULL,
  `apply_time` int(11) DEFAULT NULL,
  PRIMARY KEY (`version`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for bd_notice
-- ----------------------------
DROP TABLE IF EXISTS `bd_notice`;
CREATE TABLE `bd_notice` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(32) NOT NULL COMMENT '标题',
  `sid` int(11) NOT NULL,
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `release_time` int(11) NOT NULL,
  `over_time` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL,
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='通知公告';

-- ----------------------------
-- Table structure for bd_red_activity
-- ----------------------------
DROP TABLE IF EXISTS `bd_red_activity`;
CREATE TABLE `bd_red_activity` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `title` varchar(32) NOT NULL COMMENT '标题',
  `rule_id` int(11) NOT NULL COMMENT '规则id',
  `created_at` int(11) NOT NULL,
  `province` varchar(32) NOT NULL,
  `city` varchar(32) NOT NULL COMMENT '城市',
  `type` tinyint(4) NOT NULL COMMENT '类型',
  `total_amount` decimal(10,2) NOT NULL COMMENT '总金额',
  `price_interval` varchar(32) NOT NULL COMMENT '单个红包金额区间',
  `number` int(11) NOT NULL COMMENT '个数/工地',
  `valid_at` int(11) NOT NULL COMMENT '有效时间',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for bd_red_rule
-- ----------------------------
DROP TABLE IF EXISTS `bd_red_rule`;
CREATE TABLE `bd_red_rule` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `red_id` int(11) NOT NULL COMMENT '红包活动id',
  `usecount` int(11) NOT NULL COMMENT '红包被打开次数',
  `joincount` int(11) NOT NULL DEFAULT '0' COMMENT '可参与该活动次数',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `start_price` decimal(10,2) NOT NULL COMMENT '红包最小金额',
  `end_price` decimal(10,2) NOT NULL COMMENT '最大金额',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ----------------------------
-- Table structure for bd_reply
-- ----------------------------
DROP TABLE IF EXISTS `bd_reply`;
CREATE TABLE `bd_reply` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `cid` int(11) NOT NULL COMMENT '评价id',
  `from_userid` int(11) NOT NULL COMMENT '回复人',
  `to_userid` int(11) NOT NULL COMMENT '被回复人',
  `content` text NOT NULL COMMENT '回复内容',
  `created_at` int(11) NOT NULL,
  `status` tinyint(4) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=utf8 COMMENT='评价回复表';

-- ----------------------------
-- Table structure for bd_sort_message
-- ----------------------------
DROP TABLE IF EXISTS `bd_sort_message`;
CREATE TABLE `bd_sort_message` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `tel` varchar(32) NOT NULL,
  `code` varchar(12) NOT NULL,
  `created_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='短信验证表';

-- ----------------------------
-- Table structure for bd_user
-- ----------------------------
DROP TABLE IF EXISTS `bd_user`;
CREATE TABLE `bd_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `auth_key` varchar(32) COLLATE utf8_unicode_ci NOT NULL,
  `passwrd_hash` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
  `password_reset_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `access_token` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `email` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
  `status` smallint(6) NOT NULL DEFAULT '10',
  `created_at` int(11) NOT NULL,
  `updated_at` int(11) NOT NULL,
  `state` smallint(6) DEFAULT '0',
  `role` enum('3','2','1','0') COLLATE utf8_unicode_ci DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `username` (`username`),
  UNIQUE KEY `email` (`email`),
  UNIQUE KEY `password_reset_token` (`password_reset_token`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

-- ----------------------------
-- Table structure for bd_user_company
-- ----------------------------
DROP TABLE IF EXISTS `bd_user_company`;
CREATE TABLE `bd_user_company` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL COMMENT '用户ID',
  `logo` varchar(255) NOT NULL COMMENT 'logo地址',
  `company` varchar(120) NOT NULL COMMENT '公司名称',
  `age` int(11) DEFAULT NULL COMMENT '年限',
  `level` tinyint(4) NOT NULL COMMENT '等级',
  `licence` varchar(255) DEFAULT NULL,
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `tel` varchar(32) DEFAULT NULL COMMENT '联系电话',
  `city` varchar(32) DEFAULT NULL COMMENT '城市',
  `district` varchar(32) DEFAULT NULL COMMENT '地区',
  `address` text COMMENT '地址',
  `updated_at` int(11) NOT NULL,
  `introduction` text COMMENT '公司简介',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='公司信息表';

-- ----------------------------
-- Table structure for bd_user_house
-- ----------------------------
DROP TABLE IF EXISTS `bd_user_house`;
CREATE TABLE `bd_user_house` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL,
  `compound` varchar(32) DEFAULT NULL COMMENT '小区名称',
  `layout` varchar(32) DEFAULT NULL COMMENT '户型',
  `acreage` varchar(32) DEFAULT NULL COMMENT '面积',
  `amount` char(10) DEFAULT NULL COMMENT '预算',
  `province` varchar(32) DEFAULT NULL COMMENT '省份',
  `city` varchar(32) DEFAULT NULL COMMENT '城市',
  `district` varchar(32) DEFAULT NULL COMMENT '地区',
  `address` varchar(255) DEFAULT NULL COMMENT '详细地址',
  `created_at` int(11) NOT NULL COMMENT '创建时间',
  `status` int(11) NOT NULL COMMENT '状态',
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='我的房屋';

-- ----------------------------
-- Table structure for bd_user_info
-- ----------------------------
DROP TABLE IF EXISTS `bd_user_info`;
CREATE TABLE `bd_user_info` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) NOT NULL COMMENT '用户ID',
  `nickname` varchar(32) NOT NULL,
  `portrait` varchar(255) DEFAULT NULL COMMENT '头像',
  `tel` varchar(32) NOT NULL COMMENT '联系电话',
  `updated_at` int(11) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='用户信息表';

-- ----------------------------
-- Table structure for bd_user_wechat
-- ----------------------------
DROP TABLE IF EXISTS `bd_user_wechat`;
CREATE TABLE `bd_user_wechat` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uid` int(11) DEFAULT NULL,
  `openid` varchar(50) NOT NULL COMMENT 'openid',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

-- ----------------------------
-- Function structure for get_distance
-- ----------------------------
DROP FUNCTION IF EXISTS `get_distance`;
DELIMITER ;;
CREATE DEFINER=`root`@`localhost` FUNCTION `get_distance`(`lat1` varchar(20),`long1` varchar(20),`lat2` varchar(20),`long2` varchar(20)) RETURNS int(11)
BEGIN
	#得到两个坐标之间的距离
	DECLARE latitude,longitude,latitude2,longitude2,distance VARCHAR(20);
	DECLARE R INTEGER;
	SET R = 6378137;
	SET latitude = RADIANS(lat1);
	SET longitude = RADIANS(long1);
	SET latitude2 = RADIANS(lat2);
	SET longitude2 = RADIANS(long2);

	SET distance = ACOS(COS(latitude)*COS(latitude2)*COS(longitude-longitude2)+SIN(latitude)*SIN(latitude2))*R;
	
	SET distance = ROUND(distance*10000)/10000;
	SET distance = ROUND(distance);

	RETURN distance;
END
;;
DELIMITER ;
