1.体系结构图
管理端采用B/S架构(浏览器—服务器)架构方式。
2.功能模块图
功能模块分为三个端口:用户端、后台管理端和手机销售商端。
用户端:查询在售手机信息、咨询客服信息、向店铺申请售后、下单等功能。
后台管理端:用户和手机商管理功能、信息管理功能、审核功能。
手机商户端:修改店铺信息,处理售后等功能。
3.E-R图
4.二维表
用户表用来记录已经注册的用户基本信息。
用于查询目标用户和管理员对用户的管理。
售卖手机信息表记录在售手机的所有信息。
管理员表记录了管理员的信息。
订单信息表记录了所有交易有关的信息。
订单编号是唯一的,可以从表中查找到是出售的哪款手机,价格,时间,及售卖的手机店铺。
店铺信息表记录了店铺的基本信息,隶属于哪个手机商。
手机售卖商家信息表记录了商家的基本信息,可以查询该商家售卖了哪些手机,开了哪些店铺。
![在这里插入图片描述](https://img-blog.csdnimg.cn/066e99e68a124f10af3e14bcde8969c4.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBA5Li65pep5pyq6L-f,size_20,color_FFFFFF,t_70,g_se,x_16#pic_center)
手机类型信息表记录了哪款手机属于哪个类型。
5.建表语句
create database phoneselldb;
use phoneselldb;
#1.创建用户信息表及完整性约束
create table user(
uid int(16) not null primary key auto_increment,
uname varchar(32) not null,
uaccount varchar(32) not null,
password varchar(32) not null,
orderid int(32),
adress varchar(32),
utelephone int(16)
);
alter table user
add constraint fk_user_reference_order foreign key(orderid)
references orders(orderid);
#2.创建手机商品信息表及完整性约束
create table phoneinformation(
phoneid int(32) not null primary key auto_increment,
phonename varchar(32) not null,
price float(32) not null,
type int(16) not null,
inventory int(16) not null,
storeid int(16) not null
);
alter table phoneinformation
add constraint fk_phoneinformation_reference_store foreign key(storeid)
references store(storeid);
#3.创建手机商家信息表及完整性约束
create table seller(
sellerid int(16) not null primary key auto_increment,
saccount varchar(32) not null,
password varchar(32) not null,
stelephone int(32) not null,
storeid int(16),
sadress varchar(32)
);
alter table seller
add constraint fk_seller_reference_storeid foreign key(storeid)
references store(storeid);
#4.创建管理员信息表及完整性约束
create table administrator(
adid int(16) not null primary key auto_increment,
adaccount varchar(32) not null,
adpassword varchar(32) not NULL,
adtelephone int(16) not null,
adadress varchar(50) not null,
lasttime datetime not null
);
#5.创建订单信息表及完整性约束
create table orders(
orderid int(16) not null primary key auto_increment,
uid int(16) not null,
storeid int(16) not null,
price float(16) not null,
number int(16) not null,
state boolean not null,
date datetime not null
);
alter table orders
add constraint fk_orders_reference_user foreign key(uid)
references user(uid);
alter table orders
add constraint fk_orders_reference_store foreign key(storeid)
references store(storeid);
#6.创建店铺信息表及完整性约束
create table store(
storeid int(16) not null primary key auto_increment,
phoneid int(32) not null,
orderid int(16) not null,
sellerid int(16) not null
);
alter table store
add constraint fk_store_reference_phoneinformation foreign key(phoneid)
references phoneinformation(phoneid);
alter table store
add constraint fk_store_reference_seller foreign key(sellerid)
references seller(sellerid);
alter table store
add constraint fk_store_reference_orders foreign key(orderid)
references orders(orderid);
#7.创建手机类型信息表及完整性约束
create table type(
typeid int(16) not null primary key auto_increment,
phoneid int(16) not null,
avgprice int(32) not null
);
alter table type
add constraint fk_type_reference_phone foreign key(phoneid)
references phoneinformation(phoneid);
#创建管理员编号,手机商编号,用户编号的唯一非聚集索引
create unique index index_one on administrator(adid);
create unique index index_two on seller(sellerid);
create unique index index_three on user(uid);
#触发器设置
#客户下订单订购手机时,手机表数量自动减少数量。
create trigger trigger_number
after insert on orders for each row
begin
update phoneinformation set number = number-orders.number where phoneid = orders.phoneid;
end