-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtakeoutassistant.sql
316 lines (263 loc) · 12.1 KB
/
takeoutassistant.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*==============================================================*/
/* DBMS name: MySQL 5.0 */
/* Created on: 2020/7/6 13:22:04 */
/*==============================================================*/
drop table if exists AdminInfo;
drop table if exists CouponInfo;
drop table if exists DeliveryAddr;
drop table if exists FullReductionScheme;
drop table if exists OrderDetail;
drop table if exists OrderForm;
drop table if exists ProductCategory;
drop table if exists ProductDetails;
drop table if exists RiderDeliverOrder;
drop table if exists RiderInfo;
drop table if exists ShopInfo;
drop table if exists UserHoldCoupons;
drop table if exists UserInfo;
drop table if exists UserOrderCount;
drop table if exists evaluate;
/*==============================================================*/
/* Table: AdminInfo */
/*==============================================================*/
create table AdminInfo
(
admin_id int not null auto_increment,
admin_name varchar(20) not null,
admin_pwd varchar(15) not null,
admin_logout_date date,
primary key (admin_id)
);
/*==============================================================*/
/* Table: CouponInfo */
/*==============================================================*/
create table CouponInfo
(
coupon_id int not null auto_increment,
shop_id int,
coupon_amount float(8,2) not null,
coupon_ordered_number_requirement int not null,
coupon_start_date timestamp,
coupon_end_date timestamp,
coupon_delete_time timestamp,
primary key (coupon_id)
);
/*==============================================================*/
/* Table: DeliveryAddr */
/*==============================================================*/
create table DeliveryAddr
(
addr_id int not null auto_increment,
user_id int,
addr_province varchar(30) not null,
addr_city varchar(30) not null,
addr_district varchar(30) not null,
addr_detailed_addr varchar(60) not null,
addr_contact_person varchar(20) not null,
addr_contact_phone varchar(15) not null,
primary key (addr_id)
);
/*==============================================================*/
/* Table: FullReductionScheme */
/*==============================================================*/
create table FullReductionScheme
(
fullreduction_id int not null auto_increment,
shop_id int,
fullreduction_amount float(8,2) not null,
fullreduction_discounted_price float(8,2) not null,
fullreduction_can_superimposed_with_coupons bool not null,
fullreduction_delete_time timestamp,
primary key (fullreduction_id)
);
/*==============================================================*/
/* Table: OrderDetail */
/*==============================================================*/
create table OrderDetail
(
order_id int not null,
product_id int not null,
amount int not null,
price float(8,2) not null,
single_product_discount_amount float(8,2),
primary key (order_id, product_id)
);
/*==============================================================*/
/* Table: OrderForm */
/*==============================================================*/
create table OrderForm
(
order_id int not null auto_increment,
shop_id int,
fullreduction_id int,
addr_id int,
user_id int,
coupon_id int,
order_original_amount float(8,2) not null,
order_actual_amount float(8,2) not null,
order_time timestamp not null,
order_request_delivery_time timestamp not null,
order_status varchar(10) not null,
order_delete_time timestamp,
primary key (order_id)
);
/*==============================================================*/
/* Table: ProductCategory */
/*==============================================================*/
create table ProductCategory
(
productcategory_id int not null auto_increment,
shop_id int,
productcategory_column_name varchar(30) not null,
productcategory_delete_time timestamp,
primary key (productcategory_id)
);
/*==============================================================*/
/* Table: ProductDetails */
/*==============================================================*/
create table ProductDetails
(
product_id int not null auto_increment,
productcategory_id int,
shop_id int,
product_name varchar(30) not null,
product_price float(8,2) not null,
product_discounted_price float(8,2),
product_delete_time timestamp,
primary key (product_id)
);
/*==============================================================*/
/* Table: RiderDeliverOrder */
/*==============================================================*/
create table RiderDeliverOrder
(
order_id int not null,
rider_id int not null,
deliver_time timestamp not null,
deliver_user_rate int,
deliver_single_income float(8,2) not null,
primary key (order_id, rider_id)
);
/*==============================================================*/
/* Table: RiderInfo */
/*==============================================================*/
create table RiderInfo
(
rider_id int not null auto_increment,
rider_name varchar(10) not null,
rider_pwd varchar(15) not null,
rider_entry_date date not null,
rider_identity int not null,
rider_total_income float(8,2),
rider_logout_date date,
primary key (rider_id)
);
/*==============================================================*/
/* Table: ShopInfo */
/*==============================================================*/
create table ShopInfo
(
shop_id int not null auto_increment,
shop_name varchar(30) not null,
shop_pwd varchar(30) not null,
shop_level int not null,
shop_per_capita_consumption float(8,2),
shop_total_sales float(8,2),
shop_logout_time date,
primary key (shop_id)
);
/*==============================================================*/
/* Table: UserHoldCoupons */
/*==============================================================*/
create table UserHoldCoupons
(
user_id int not null,
coupon_id int not null,
amount int not null,
ddl date,
primary key (user_id, coupon_id)
);
/*==============================================================*/
/* Table: UserInfo */
/*==============================================================*/
create table UserInfo
(
user_id int not null auto_increment,
user_name varchar(10) not null,
user_gender bool,
user_pwd varchar(15) not null,
user_phone_number varchar(15) not null,
user_mail varchar(30),
user_city varchar(30),
user_registration_time date not null,
user_is_vip bool not null,
user_vip_ddl date,
user_logout_time date,
primary key (user_id)
);
/*==============================================================*/
/* Table: UserOrderCount */
/*==============================================================*/
create table UserOrderCount
(
user_id int not null,
shop_id int not null,
order_count int,
primary key (user_id, shop_id)
);
/*==============================================================*/
/* Table: evaluate */
/*==============================================================*/
create table evaluate
(
user_id int not null,
order_id int not null,
evaluate_content varchar(500) not null,
evaluate_date timestamp not null,
evaluate_score int not null,
evaluate_photo longblob,
evaluate_rider bool,
primary key (user_id, order_id)
);
alter table CouponInfo add constraint FK_CouponsBelongToShop foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table DeliveryAddr add constraint FK_AddrBelongtoUser foreign key (user_id)
references UserInfo (user_id) on delete restrict on update restrict;
alter table FullReductionScheme add constraint FK_FullReductionSchemeMadebyShop foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table OrderDetail add constraint FK_OrderDetail foreign key (order_id)
references OrderForm (order_id) on delete restrict on update restrict;
alter table OrderDetail add constraint FK_OrderDetail2 foreign key (product_id)
references ProductDetails (product_id) on delete restrict on update restrict;
alter table OrderForm add constraint FK_CouponOnOrder foreign key (coupon_id)
references CouponInfo (coupon_id) on delete restrict on update restrict;
alter table OrderForm add constraint FK_FullreductionOnOrder foreign key (fullreduction_id)
references FullReductionScheme (fullreduction_id) on delete restrict on update restrict;
alter table OrderForm add constraint FK_OrderAddr foreign key (addr_id)
references DeliveryAddr (addr_id) on delete restrict on update restrict;
alter table OrderForm add constraint FK_ShopisOrdered foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table OrderForm add constraint FK_UserOrder foreign key (user_id)
references UserInfo (user_id) on delete restrict on update restrict;
alter table ProductCategory add constraint FK_CategoriesMadebyShop foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table ProductDetails add constraint FK_ProductsBelongToShop foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table ProductDetails add constraint FK_ProductsBelongtoCategory foreign key (productcategory_id)
references ProductCategory (productcategory_id) on delete restrict on update restrict;
alter table RiderDeliverOrder add constraint FK_RiderDeliverOrder foreign key (order_id)
references OrderForm (order_id) on delete restrict on update restrict;
alter table RiderDeliverOrder add constraint FK_RiderDeliverOrder2 foreign key (rider_id)
references RiderInfo (rider_id) on delete restrict on update restrict;
alter table UserHoldCoupons add constraint FK_UserHoldCoupons foreign key (user_id)
references UserInfo (user_id) on delete restrict on update restrict;
alter table UserHoldCoupons add constraint FK_UserHoldCoupons2 foreign key (coupon_id)
references CouponInfo (coupon_id) on delete restrict on update restrict;
alter table UserOrderCount add constraint FK_UserOrderCount foreign key (user_id)
references UserInfo (user_id) on delete restrict on update restrict;
alter table UserOrderCount add constraint FK_UserOrderCount2 foreign key (shop_id)
references ShopInfo (shop_id) on delete restrict on update restrict;
alter table evaluate add constraint FK_evaluate foreign key (user_id)
references UserInfo (user_id) on delete restrict on update restrict;
alter table evaluate add constraint FK_evaluate2 foreign key (order_id)
references OrderForm (order_id) on delete restrict on update restrict;