-- ----------------------------
--  Title:车型库_品牌
--  Author:lcc
--  Table:lc_auto_brand
-- ---------------------------
drop table if exists lc_auto_brand;
create table lc_auto_brand (
  id       int(10) unsigned not null auto_increment comment '品牌id',
  name     char(16)         not null   default ''   comment '品牌',
  status   tinyint(1)       not null   default '1'  comment '状态： 1正常 -1删除 0下架',
  c_time   int(10) unsigned not null   default '0'  comment '创建时间',
  u_time   timestamp        not null   default current_timestamp on update current_timestamp,
  primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型库_品牌';
alter table lc_auto_brand add logo varchar(70) not null default '' comment '品牌logo' after name;

-- ----------------------------
--  Title:车型库_车系
--  Author:lcc
--  Table:lc_auto_series
-- ---------------------------
drop table if exists lc_auto_series;
create table lc_auto_series (
  id       int(10) unsigned  not null auto_increment comment '车系id',
  brand_id int(11)           not null                comment '品牌id',
  name     char(32)          not null                comment '车系名字',
  status   tinyint(1)        not null default '1'    comment '状态(1正常 0下架 -1删除)',
  c_time   int(10) unsigned  not null default '0'    comment '创建时间',
  u_time   timestamp         not null default current_timestamp on update current_timestamp,
  primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型库_车系';

-- ----------------------------
--  Title:车型属性
--  Author:lcc
--  Table:lc_auto_attr
-- ---------------------------
drop table if exists lc_auto_attr;
create table lc_auto_attr (
  id       int(10)     not null auto_increment comment '自增id',
  s_id     int(10)     not null                comment '车系id',
  title    varchar(50) not null default ''     comment '标题',
  type     tinyint(2)  not null default '0'    comment '0颜色 1型号 2内饰颜色',
  jsondata json                 default null   comment '参数数据',
  u_time   timestamp   not null default current_timestamp on update current_timestamp comment '更新时间',
  c_time   int(10)     not null default '0'    comment '创建时间',
  primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型属性';
alter table lc_auto_attr add status tinyint(1) not null default 1 comment '状态(-1删除 0禁用 1正常)' after jsondata;

-- ----------------------------
--  Title:车型库
--  Author:xusir
--  Table:lc_auto_cars
-- ----------------------------
-- attrs：属性组合，颜色ID_型号ID_内饰ID
-- ----------------------------
drop table if exists lc_auto_cars;
create table lc_auto_cars (
  id              int(10)      not null auto_increment comment '自增id',
  brand_id        int(11)      not null                comment '品牌id',
  s_id            int(10)      not null                comment '车系id',
  attrs           char(30)     not null                comment '属性组合：{type0id}_{type1id}_{type2id}',
  price_car       double(10,2) not null default 0.0    comment '裸车报价',
  price_insure    double(10,2) not null default 0.0    comment '保险报价',
  price_fine      double(10,2) not null default 0.0    comment '精品报价',
  price_finance   double(10,2) not null default 0.0    comment '金融报价',
  first_pay       double(10,2) not null default 0.0    comment '分期首付',
  price_coplus    double(10,2) not null default 0.0    comment '公司加价',
  brokerage_1     double(10,2) not null default 0.0    comment '一级分销佣金',
  brokerage_2     double(10,2) not null default 0.0    comment '二级分销佣金',
  status          tinyint(1)   not null default '0'    comment '状态(1开启 0关闭 -1删除)',
  u_time          timestamp    not null default current_timestamp on update current_timestamp comment '更新时间',
  c_time          int(10)      not null default '0'    comment '创建时间',
  primary key (id),
  unique(attrs)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型库';
alter table lc_auto_cars add column month_pay  double(10,2) not null default 0.0    comment '月供' after first_pay;
alter table lc_auto_cars add column price_book double(10,2) not null default 0.0    comment '定金' after price_car;
alter table lc_auto_cars
  add column v_id       int unsigned not null default '0'    comment '车型id' after s_id,
  add column cor_id     int unsigned not null default '0'    comment '车身颜色id' after v_id,
  add column incor_id   int unsigned not null default '0'    comment '内饰颜色' after cor_id;
alter table lc_auto_cars modify attrs char(30)  not null default '' comment '属性组合：{type0id}_{type1id}_{type2id}';
alter table lc_auto_cars drop index attrs;


-- ----------------------------
--  Title:车辆精品
--  Author:xusir
--  Table:lc_auto_fine
-- ---------------------------
drop table if exists lc_auto_fine;
create table lc_auto_fine (
  id              int(10)     not null auto_increment comment '自增id',
  title           varchar(50) not null default ''     comment '标题',
  status          tinyint(1)  not null default '0'    comment '状态(1开启 0关闭 -1删除)',
  u_time          timestamp   not null default current_timestamp on update current_timestamp comment '更新时间',
  c_time          int(10)     not null default '0'    comment '创建时间',
  primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车辆精品';


-- ----------------------------
--  Title:车型金融信息
--  Author:lcc
--  Table:lc_auto_car_finance
-- ---------------------------
drop table if exists lc_auto_car_finance;
create table lc_auto_car_finance (
  id        int(10) unsigned    not null auto_increment comment '自增id',
  car_id    int(10) unsigned    not null default '0'    comment '车型库id',
  fin_id    int(10) unsigned    not null default '0'    comment '金融产品id',
  first_pay decimal(12,2)       not null default '0.00' comment '首付(万元)',
  mouth_pay decimal(12,2)       not null default '0.00' comment '月供',
  srv_pay   decimal(12,2)       not null default '0.00' comment '服务费',
  num       int(3) unsigned     not null default '0'    comment '金融期数',
  status    tinyint(1)          not null default '1'    comment '状态：-1删除，0关闭，1开启',
  c_time    int(10)             not null default '0'    comment '创建时间',
  u_time    timestamp           not null default current_timestamp on update current_timestamp comment '更新时间',
  primary key (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='车型金融信息'
