/*==============================================================*/
/* DBMS name:      MySQL 5.0                                    */
/* Created on:     2018/8/24 18:10:25                           */
/*==============================================================*/


drop table if exists consumer_follow_overview;

drop table if exists feedback_order;

drop table if exists follow_detail;

drop table if exists rel_admin_follow_consumer;

drop table if exists service_evaluation;

/*==============================================================*/
/* Table: consumer_follow_overview                              */
/*==============================================================*/
create table consumer_follow_overview
(
   id                   int not null auto_increment,
   user_id              bigint not null,
   feedback_num         int default 0 comment '回访次数',
   follow_num           int default 0 comment '跟进次数',
   last_follow_at       bigint default 0 comment '最近跟进时间',
   status               tinyint default 1 comment '状态：0-待跟进，1-跟进中',
   create_source        tinyint comment '来源：1-回访工单，2-用户跟进',
   create_at            bigint comment '创建时间',
   create_by            varchar(32) comment '创建人',
   update_at            bigint comment '更新时间',
   update_by            varchar(32) comment '更新人',
   primary key (id)
);

alter table consumer_follow_overview comment '消费者跟进状况';

/*==============================================================*/
/* Table: feedback_order                                        */
/*==============================================================*/
create table feedback_order
(
   id                   int not null auto_increment,
   feedback_user_id     bigint,
   book_detail_id       bigint not null,
   feedback_no          varchar(32) comment '回访编号',
   book_no              varchar(32) comment '预约编号',
   user_id              char(10) comment '用户id',
   merchant_no          national varchar(32) not null comment '商家编号',
   card_type            tinyint default 0 comment '服务卡类型',
   book_time            date comment '预约日期',
   book_week            tinyint default 0 comment '预约星期',
   time_type            tinyint default 0 comment '时间类型',
   address_telephone    national varchar(16) comment '联系人号码',
   linkman              national varchar(16) comment '联系人姓名',
   cleaner_name         national varchar(32) comment '保洁师名称',
   address_id           bigint unsigned not null comment '地址id',
   full_address         national varchar(128) comment '服务地址',
   channel_id           bigint comment '渠道id',
   created_at           bigint unsigned default 0 comment '创建时间',
   created_by           national varchar(32) comment '创建者',
   updated_at           bigint unsigned default 0 comment '更新时间',
   updated_by           national varchar(32) comment '更新者',
   attitude_score       int comment '服务态度评分',
   quality_score        int comment '服务质量评分',
   efficiency_score     int comment '服务速度评分',
   answers_status       tinyint default 0 comment '应答状态：0-未接听，1-正常',
   feedback_status      tinyint default 0 comment '回访状态：0-未回访，1-已回访',
   feedback_content     varchar(255) comment '回访内容',
   feedback_by          varchar(32) comment '回访人',
   feedback_at          bigint comment '回访时间',
   primary key (id)
);

alter table feedback_order comment '回访工单';

/*==============================================================*/
/* Table: follow_detail                                         */
/*==============================================================*/
create table follow_detail
(
   id                   int not null auto_increment,
   follow_overview_id   int not null,
   level                varchar(10) comment '用户等级',
   follow_context       varchar(255) comment '跟进内容',
   create_at            bigint comment '创建时间',
   create_by            varchar(32) comment '创建人',
   primary key (id)
);

alter table follow_detail comment '跟进明细';

/*==============================================================*/
/* Table: rel_admin_follow_consumer                             */
/*==============================================================*/
create table rel_admin_follow_consumer
(
   follow_overview_id   int not null,
   admin_id             bigint not null,
   status               tinyint default 0 comment '跟进状态：1-跟进中，2-已移除',
   feedback_num         int default 0 comment '回访次数',
   follow_num           int default 0 comment '跟进次数',
   create_source        tinyint comment '来源：1-回访工单，2-用户跟进',
   create_at            bigint comment '创建时间',
   create_by            varchar(32) comment '创建人',
   update_by            varchar(32) comment '更新人',
   update_at            bigint comment '更新时间',
   primary key (follow_overview_id, admin_id)
);

alter table rel_admin_follow_consumer comment '员工与消费者跟进情况';

/*==============================================================*/
/* Table: service_evaluation                                    */
/*==============================================================*/
create table service_evaluation
(
   id                   int not null auto_increment comment 'id',
   book_id              bigint not null,
   user_id              bigint not null,
   book_no              varchar(32) comment '预约编号',
   evaluation_no        varchar(32) comment '评价编号',
   time_score           int comment '准时到达评分',
   service_score        int comment '洁净标准评分',
   profession_score     int comment '专业高效评分',
   create_at            bigint comment '创建时间',
   content              varchar(255) comment '评价内容',
   primary key (id)
);

alter table service_evaluation comment '用户服务评价';

