发布时间:2024-07-05编辑:lianpenglin阅读(688)
现在我们来讲讲司机服务数据库相关设计,司机服务主要功能有:司机登录、司机注册、司机上下线、经纬度同步、push推送、司机钱包、充值、抢单、订单状态变更等。和用户数据库一样,我们司机数据库也只存储司机相关的信息,具体如下:
数据库名:db_driver
司机信息表:t_driver,表结构如下:
create table t_driver( id int auto_increment primary key, driver_id varchar(10) default '' not null, name varchar(255) default '' not null comment '司机姓名', gender tinyint(1) default 1 not null comment '性别', phone varchar(20) default '' not null comment '工作手机号', register_city varchar(20) default '' not null comment '注册城市', register_city_name varchar(255) default '' not null comment '注册城市名称', address varchar(255) default '' not null comment '联系地址', year int default 0 not null comment '司机年龄', driver_year int default 0 not null comment '司机驾龄', score decimal(4, 2) default 0.00 not null comment '司机评分', ext_phone varchar(255) default '' not null comment '备用手机号', status int default 0 not null comment '司机状态1--正常2---屏蔽3--带审核4--未扣费', shield_time int default 0 not null comment '屏蔽到期时间', shield_reason varchar(500) default '' not null comment '屏蔽原因', work_status int default 3 not null comment '工作状态1--空闲2--忙碌3--下线4--登录未上线', work_type tinyint default 0 not null comment '工作类型', work_city varchar(8000) default '' not null comment '工作城市', service_quality_score decimal(10, 2) default 0.00 not null comment '司机服务品质分', `rank` varchar(10) default '' not null comment '司机等级ABCD', balance decimal(10, 2) default 0.00 not null comment '司机账户余额', created datetime not null comment '创建时间', constraint phone unique (phone), constraint t_driver_driver_id_index unique (driver_id));create index created on t_driver (created);create index driver_id on t_driver (driver_id);create index ext_phone on t_driver (ext_phone);create index idx_name on t_driver (name);create index shield_time on t_driver (shield_time);create index t_driver_create_index on t_driver (created);
司机表大部分数据是通过司机注册填入的,司机工号是以司机注册城市首字母缩写在加上5位随机数生成的,避免重复,我们加了唯一索引。针对司机状态,我们分为正常、未审核、未扣费、屏蔽四种,刚刚注册的司机为未审核状态,虽然通过ocr能识别到司机上传的身份证和驾驶证,但还需要后台人员人工审核司机信息。人工确认司机信息无误之后,会流转为未扣费状态。这个状态下的司机,就可以登录我们司机端app了,登录之后需要进行充值,充值成功就可以在后台进行扣款处理,主要是扣除软件使用费,1-99元不等,正常扣费之后,司机就可以上线听单了。如果司机在服务中出现事故或者是违章,我们就可以屏蔽司机,被屏蔽的司机不能正常上线抢单。
司机工作状态我们分为4中,空闲-忙碌-下线-登录未上线,空闲状态就代表司机能正常被广播订单,正常抢单,忙碌状态就代表司机正在服务中,下线就代表司机已经退出app了,登录未上线代表司机打开app,但是没有上线。针对司机工作状态需要额外考虑一些异常场景,比如司机直接上线状态杀了app,或者是app一段时间弱网,针对这些异常场景,服务端都需要做一些兼容。这些问题等到我们讲解代码的时候会一一解答。
司机证件表:t_driver_card
create table t_driver_card ( id int auto_increment primary key, driver_id varchar(10) default '' not null, face varchar(500) default '' not null comment '司机头像', id_card varchar(100) default '' not null comment '身份证号', id_card_start_date varchar(100) default '' not null comment '身份证有效期开始时间', id_card_end_date varchar(100) default '' not null comment '身份证有效期结束时间', id_card_pic_front varchar(500) default '' not null comment '身份证正面照片', id_card_pic_back varchar(500) default '' not null comment '身份证背面照片', driver_card varchar(255) default '' not null comment '驾驶证编号', driver_card_start_date varchar(50) default '' not null comment '驾照生效日期', driver_card_end_date varchar(50) default '' not null comment '驾照有效结束时间', driver_card_pic varchar(500) default '' not null comment '驾驶证照片', created datetime not null comment '创建时间', constraint idx_id_card unique (id_card), constraint t_driver_driver_card_index unique (driver_card), constraint t_driver_driver_id_index unique (driver_id) ); create index t_driver_create_index on t_driver_card (created);
driver_card表主要存储司机身份证、驾驶证、头像等证件信息,包含图片地址等,和司机信息表拆分开来主要就是因为证件类信息读写频率低,拆开之后可以提升效率。
司机token表:t_driver_token
create table t_driver_token ( id int auto_increment primary key, driver_id varchar(100) default '' not null comment '司机工号', authtoken varchar(32) default '' not null comment '授权token', app_ver varchar(32) default '' not null comment '登录版本号', expire_time int default 0 not null comment '过期时间', created datetime not null, constraint t_driver_token_token_index unique (authtoken) ); create index t_driver_token_driver_id_index on t_driver_token (driver_id);
司机每次登录会生成token,同时会将之前未过期的token踢掉。
司机消息表:t_message
create table t_message ( id bigint auto_increment primary key, driver_id varchar(100) default '' not null comment '司机工号', title varchar(255) default '' not null comment '消息标题', content text null comment '消息内容', msg_type tinyint default 0 not null comment '消息类型1--提现消息', status int default 0 not null comment '消息状态1--未读2--已读', created_at int default 0 not null comment '创建时间', read_time int default 0 not null comment '阅读时间' ) comment '司机消息表'; create index created_at on t_message (created_at); create index driver_id on t_message (driver_id);
司机消息表主要是用于存储给司机发的通知类或结果类消息,比如司机充值到账、司机被屏蔽等。
司机屏蔽记录表:t_driver_shield_log
create table t_driver_shield_log ( id int auto_increment primary key, driver_id varchar(10) default '' not null, shield_time int default 0 not null comment '屏蔽到期时间', shield_reason varchar(500) default '' not null comment '屏蔽原因', operator varchar(100) default '' not null comment '操作人', created datetime not null comment '创建时间' ); create index driver_id on t_driver_shield_log (driver_id);
主要用于存储司机屏蔽记录。
以上就是司机数据库相关设计,和用户数据库一样,司机订单和结算相关存储依然会放在订单数据库和财务数据库中。
标签: golang
如果对你有用打赏一下吧!