发布时间:2024-07-05编辑:lianpenglin阅读(756)
接下来就到我们最为重要的订单数据库设计了,订单数据库我们暂时设计8张表,分别是预估数据表,用来存储用户下单之前的预估数据,订单主表,存储订单的基本信息,订单扩展表,存储读写频率低的订单数据,订单地址表,用来存储订单相关地址信息,如下单经纬度,目的地经纬度,下单地址和目的地地址以及经纬度类型,订单广播表,用来存储每个订单广播的司机和订单基本信息,订单图片表,用来存储订单关联的一些图片地址,订单时间表,用来存储订单各个节点的时间,如下单时间、接单时间、就位时间、支付时间、结算时间等,状态机表,用于存储订单当前状态和历史状态。
预估表结构:
-- auto-generated definition create table t_customer_estimate_log( id int unsigned auto_increment primary key, estimate_group_id varchar(32) default '' null comment '预估批次id', estimate_id varchar(255) default '' not null comment '预估id', user_center_id varchar(100) default '' not null comment '用户ID', city_id varchar(100) default '' not null comment '城市id', order_number varchar(100) default '' not null comment '订单号', source int default 0 not null comment 'source', channel varchar(255) not null comment 'channel', business_id int default 0 not null comment '业务ID', distance decimal(10, 2) default 0.00 not null comment '里程', duration decimal(10, 2) default 0.00 not null comment '时长(分钟)', fee decimal(10, 2) default 0.00 not null comment '费用', real_fee decimal(10, 2) default 0.00 not null comment '费用(含优惠券)', address_from varchar(255) default '' not null comment '出发地', address_to varchar(255) default '' not null comment '目的地', start_lat decimal(10, 6) default 0.000000 not null comment '出发地经度', start_lng decimal(10, 6) default 0.000000 not null comment '出发地纬度', end_lat decimal(10, 6) default 0.000000 not null comment '目的地经度', end_lng decimal(10, 6) default 0.000000 not null comment '目的地纬度', created datetime not null comment '创建时间', estimate_json text null comment '预估费用详情', constraint estimate_id unique (estimate_id));create index channel on t_customer_estimate_log (channel);create index group_id on t_customer_estimate_log (estimate_group_id);create index order_number on t_customer_estimate_log (order_number);create index source on t_customer_estimate_log (source);create index user_center_id on t_customer_estimate_log (user_center_id); --订单主表结构:-- auto-generated definition create table t_order( order_id int auto_increment primary key, order_number varchar(100) not null, source smallint not null, channel varchar(5) default '0' null, business_id int default 0 not null comment '订单业务类型1--取送车2--验车', name varchar(20) not null, end_name varchar(100) default '' not null comment '目的地联系人姓名', phone varchar(20) not null, end_phone varchar(100) default '' not null comment '目的地联系人电话', user_center_id varchar(32) default '' not null comment '用户中心ID', contact_phone varchar(20) null, vipcard varchar(15) not null, driver varchar(30) not null, driver_id varchar(50) not null, driver_phone varchar(20) not null, city_id varchar(100) default '' not null comment '下单城市行政编码', city_name varchar(255) default '' not null comment '城市中文名称', booking_time int not null, distance decimal(10, 2) default 0.00 not null, location_start varchar(255) not null comment '订单起始地址', location_end varchar(255) not null comment '订单结束地址', income decimal(10, 2) default 0.00 not null comment '收入', price decimal(10, 2) default 0.00 not null comment '订单价格', cast decimal(10, 2) not null, status smallint not null comment '0--新订单1--已抢单2服务中--3已报单未确认支付方式4--已报单未支付5-已支付', state varchar(100) default '0' not null comment '订单状态000-新订单 102 开始派单...', end_city_id varchar(100) default '' not null comment '下单目的地行政编码', created int null); create index booking_time on t_order (booking_time);create index channel on t_order (channel);create index city_id on t_order (city_id);create index city_id_2 on t_order (city_id, booking_time);create index contact_phone on t_order (contact_phone);create index created on t_order (created);create index driver_id on t_order (driver_id);create index driver_phone on t_order (driver_phone);create index idx_user_center_id on t_order (user_center_id);create index order_number on t_order (order_number);create index phone on t_order (phone);create index source on t_order (source);create index status on t_order (status);create index t_order_state_index on t_order (state);create index vipcard on t_order (vipcard); --订单时间表结构:-- auto-generated definition create table t_order_time( id int auto_increment primary key, order_number varchar(100) not null, order_date varchar(8) not null, multi_time int default 0 not null comment '下单时间', booking_time int not null, grab_time int default 0 not null comment '抢单时间', accept_time int default 0 not null comment '接单时间', arrive_time int default 0 not null comment '就位时间', start_time int not null, end_time int not null, submit_time int default 0 not null comment '报单时间', settle_time int default 0 not null comment '结算时间', pay_time int default 0 not null comment '支付时间', cancel_time int default 0 not null comment '取消时间');create index booking_time on t_order_time (booking_time);create index t_order_accept_time_index on t_order_time (accept_time);create index t_order_arrive_time_index on t_order_time (arrive_time);create index t_order_end_time_index on t_order_time (end_time);create index t_order_grab_time_index on t_order_time (grab_time);create index t_order_order_number_index on t_order_time (order_number);create index t_order_pay_time_index on t_order_time (pay_time);create index t_order_settle_time_index on t_order_time (settle_time);create index t_order_start_time_index on t_order_time (start_time);create index t_order_submit_time_index on t_order_time (submit_time);create index t_order_time_cancel_time_index on t_order_time (cancel_time);create index t_order_time_multi_time_index on t_order_time (multi_time); --订单扩展表结构:-- auto-generated definition create table t_order_ext( id int auto_increment primary key, order_number varchar(100) not null, distance decimal(10, 2) default 0.00 not null, description varchar(512) default '' not null, arrive_time int default 0 not null comment '司机就位耗时', arrive_distance decimal(10, 2) default 0.00 not null comment '司机就位距离', cancel_desc varchar(256) not null, cancel_code varchar(100) default '' null, accept_type int default 1 not null comment '成单方式1--抢单2--派单', pay_type int default 1 not null comment '支付方式1--在线支付2--余额支付3--现金支付4--余额+在线5--余额+现金', customer_app_ver varchar(100) default '' not null comment '用户版本号', driver_app_ver varchar(100) default '' not null comment '司机版本号', car_number varchar(100) default '' not null comment '车牌号', mark varchar(500) default '' not null comment '订单备注', created int null);create index order_number on t_order_ext (order_number); ---订单地址表结构:-- auto-generated definition create table t_order_address( id int auto_increment primary key, order_number varchar(225) default '' not null, gps_type varchar(20) not null comment '经纬度类型baidu;gaode;', lat decimal(10, 6) not null, lng decimal(10, 6) not null, address varchar(100) not null, customer_lat decimal(10, 6) default 0.000000 not null comment '定位纬度', customer_lng decimal(10, 6) default 0.000000 not null comment '定位经度', customer_address varchar(1000) default '' not null comment '定位地址', destination_lat decimal(10, 6) default 0.000000 not null comment '目的地纬度', destination_lng decimal(10, 6) default 0.000000 not null comment '目的地经度', destination_address varchar(255) default '' not null comment '目的地地址', input_type int default 1 not null comment '类型1--下单默认2-用户修改目的地3-司机修改目的地', created timestamp default CURRENT_TIMESTAMP not null);create index idx_order_id on t_order_address (order_number); --订单广播表结构:-- auto-generated definition create table t_order_grab( id bigint auto_increment primary key, order_number varchar(255) default '' not null comment '订单号', driver_id varchar(255) default '' not null comment '司机工号', start_address varchar(500) default '' not null comment '订单出发地', start_lat decimal(10, 6) default 0.000000 not null comment '出发地纬度', start_lng decimal(10, 6) default 0.000000 not null comment '出发地经度', start_user_name varchar(100) default '' not null comment '出发地联系人姓名', start_phone varchar(100) default '' not null comment '出发地联系人电话', end_address varchar(500) default '' not null comment '订单目的地', end_phone varchar(100) default '' not null comment '目的地联系人电话', end_lat decimal(10, 6) default 0.000000 not null comment '目的地纬度', end_lng decimal(10, 6) default 0.000000 not null comment '目的地经度', end_user_name varchar(100) default '' not null comment '目的地联系人姓名', fee decimal(10, 2) default 0.00 not null comment '订单金额', title varchar(100) default '' not null comment '业务名称', car_number varchar(100) default '' not null comment '车牌号', mark varchar(1000) default '' not null comment '留言', booking_time int default 0 not null comment '预约时间', grab_count int default 1 not null comment '广播次数', status int default 1 not null comment '状态1--未被抢2--已被抢3--已删除4--已开启', created_at int default 0 not null comment '创建时间', constraint t_order_grab_driver_number_index unique (order_number, driver_id)) comment '广播记录表'; create index t_order_grab_booking_index on t_order_grab (booking_time); create index t_order_grab_driver_id_index on t_order_grab (driver_id); ---订单状态机表结构:-- auto-generated definition create table t_order_process_202405( id int auto_increment comment 'ID' primary key, queue_id int default 0 null comment 'QueueID', order_id int default 0 not null comment '订单ID', state varchar(10) default '' not null comment '状态(101-新建、201-正在派、301-已接单、302-已到达、303-已上车、401-系统取消、402-客户取消、403-客户取消、404-司机取消、501-已完成即报单)', created datetime not null, driver_id varchar(50) null, fail_type smallint null, description varchar(512) null, order_microtime varchar(50) null comment '写入毫秒时间', order_number varchar(100) not null comment '订单号', exec_count int default 1 not null comment '执行次数', is_del int default 1 not null comment '是否删除1--否2--是', updated datetime not null, order_channel_id int default 0 not null comment '派单业务表ID', order_channel varchar(50) default '' not null comment '订单业务', lat decimal(10, 6) not null, lng decimal(10, 6) not null);create index order_id on t_order_process_202405 (order_id);create index order_number on t_order_process_202405 (order_number); ---订单图片表结构:-- auto-generated definition create table t_order_photo( id bigint auto_increment primary key, order_number varchar(100) default '' not null comment '订单号', driver_id varchar(100) default '' not null comment '司机工号', `desc` varchar(100) default '' not null comment '描述,车外部信息、照片、等', field varchar(100) default '' not null comment '照片字段', value varchar(500) default '' not null comment '照片地址', status int default 0 not null comment '照片状态--预留字段', created_at datetime not null comment '创建时间', updated_at datetime not null comment '更新时间') comment '订单图片表';create index created_at on t_order_photo (created_at);create index driver_id on t_order_photo (driver_id);create index order_number on t_order_photo (order_number);
其中状态机表,我们按照月份进行了分表,每个订单状态按照下单时间进入到对应的月份表中,订单数据库也只是实现了基本功能,大家可以自行扩展。
标签: golang
如果对你有用打赏一下吧!
上一篇: 从0开始开发基于地理位置的派单系统Day2-司机数据库设计
下一篇: 没有了