book
1
create database book
2
use book
3
go
4
5
--1.图书类别分类表 bookClass
6
create table bookClass
7
(
8
class_id int identity primary key,--编号
9
class_name varchar(100) not null, --名称
10
class_parent int default 0--父类
11
)
12
13
--2.图书信息 book
14
create table book
15
(
16
book_id int identity primary key,--书籍编号
17
book_name varchar(200) not null,--图书名称
18
class_id int not null,--图书类别 与bookClass表对应
19
book_come varchar(200),--出版社
20
book_author varchar(200) not null,--作者
21
book_price varchar(10) not null,--定价
22
book_price1 varchar(10) not null,--买出时的价钱
23
book_ISBN varchar(50),--ISBN
24
book_time datetime, --出版日期
25
book_disk varchar(100),--光盘数
26
book_volume varchar(100),--册数
27
book_image varchar(200),--图片路径
28
book_text text, --书籍说明,内容简介
29
book_key varchar(200),--关键字,多个关键字之间用逗号隔开
30
book_date datetime default GETDATE(),--添加日期
31
book_isDel int default 0--图书是否删除,0正常未被删除,1被删除,从BIT型改为INT型,2通过审核还没有生成静态页面
32
)
33
34
--book_name,class_id,book_come,book_author,book_price,book_price1,book_ISBN,book_time,book_disk,book_volume,book_image,book_text,book_key
35
36
--3.图书属性 book_attribute 推荐 热销 关注
37
create table book_attribute
38
(
39
ba_id int identity primary key,--编号
40
ba_name varchar(50) not null,--名称
41
)
42
43
--4.推荐、热销、关注等表图书表
44
create table RS
45
(
46
id int identity primary key,--编号
47
book_id int not null,--书籍编号,与book表中的书籍编号关联
48
rs_date datetime default GETDATE(), --日期
49
ba_id int not null --属性编号,与book_attribute表关联
50
)
51
52
--5.书店讯息 new
53
create table new
54
(
55
new_id int identity primary key,--编号
56
new_title varchar(200) not null,--标题
57
new_content text not null,--内容
58
new_date datetime default getdate() --添加时间
59
)
60
61
--6.用户注册信息 user
62
create table [user]
63
(
64
[user_id] int identity primary key,--编号
65
[user_name] varchar(100) not null,--用户名称
66
user_pass varchar(32) not null,--密码
67
user_mail varchar(100) not null, --邮箱
68
user_quest varchar(200),--问题
69
user_answer varchar(200),--答案
70
user_money float default 0, --存取在本站的金额
71
user_receive int default 0 --积分
72
)
73
74
--7.后台管理员信息 admin
75
create table admin
76
(
77
admin_id int identity primary key,--编号
78
admin_name varchar(100) not null,--管理员名称
79
admin_pass varchar(32) not null, --密码
80
--权限
81
admin_class int default 1 --用户类别,0管理员,1普通管理员
82
)
83
84
--8.操作日志 log
85
create table [log]
86
(
87
log_id int identity primary key,--编号
88
log_date datetime default getdate(),--操作时间
89
[user_id] int not null,--操作人信息
90
log_ip varchar(15) not null, --操作人登录IP ,222.222.222.222
91
log_message varchar(500) not null,--操作事件
92
log_isUser bit default 1 --是否是前台用户,1是前台用户,0后台用户
93
)
94
95
--9.短信类型 message_class mc
96
create table mc
97
(
98
mc_id int identity primary key,
99
mc_name varchar(100) not null,--名称
100
)
101
102
--10.短信,后台管理员、前台用户之间 message
103
create table message
104
(
105
m_id int identity primary key,--编号
106
m_from int not null,--发送人编号 ,0为管理员
107
m_to int not null,--接收人编号,0为管理员,-1为所有的用户
108
m_title varchar(200) not null, --标题
109
m_message text not null,--内容
110
m_date datetime default getdate(),--发送时间
111
m_c bit default 0,--是否查看,0未查看,1查看
112
m_from_id int default 0,--0为首发,其它为回复
113
mc_id int not null --短信类型
114
)
115
116
--m_title,m_date,
117
118
--m_from,m_to,m_title,m_message,m_from_id,mc_id
119
120
--11.送货方式 set
121
create table [set]
122
(
123
set_id int identity primary key,--编号
124
set_title varchar(200) not null,--名称
125
set_explain text, -- 说明
126
set_money varchar(10) not null --钱
127
)
128
129
--12.订单表 send
130
create table send
131
(
132
send_id int identity primary key,--编号
133
send_bookMoney float not null,--书籍的价钱
134
set_id int not null,--邮寄的方式
135
set_money varchar(10) not null,--钱
136
set_com varchar(200) ,--收货人公司
137
send_invoice bit default 0,-- 是否需要发票,0不需要,1需要
138
send_ms int default 0 ,--收货人称谓,0先生,1女土/小姐,2保密
139
send_name varchar(100) not null,--收货人姓名
140
send_photo varchar(100) not null,--收货人电话
141
send_mail varchar(100), --收货人Email
142
send_yb varchar(100),-- 收货人邮编
143
send_add varchar(200) not null,--收货人地址
144
send_text text,--备注
145
146
send_time datetime default getdate(),--订单时间
147
148
send_isGet_num varchar(200),--汇款编号
149
send_isGet bit default 0, --是否收到汇款,0未收到,1收到
150
send_isGet_Date datetime,--收到汇款的时间
151
send_isEnt bit default 0, --是否已经电话确认
152
send_isEnt_Date datetime,--收到汇款后确认的时间
153
send_isSet bit default 0 --是否已经发货
154
send_isSet_Date datetime,--发货时间
155
)
156
157
--13.订单明细表 shop
158
create table shop
159
(
160
shop_id int identity primary key,--编号
161
[user_id] int not null,--用户编号
162
book_id int not null,--书籍编号
163
book_num int not null,--书籍数量
164
book_price varchar(10) not null,--卖出时的单价
165
shop_date datetime default getdate(),--购买时间
166
send_id int not null --邮寄编号,与订单表send 中的 send_id关联
167
)
168
169
--14.购物车 bus
170
create table bus
171
(
172
b_id int identity primary key,
173
[user_id] varchar(100) not null,--购物车ID,登录用户为该用户的编号,匿名用户则创始临时的用户编号
174
book_id int not null,--书籍编号
175
book_num int not null,--书籍数量
176
book_price varchar(10) not null,--书籍卖出时的单价
177
shop_date datetime default getdate() --购买时间
178
)
179
180
--15.销售记录表 bookSaleInfo
181
create table bookSaleInfo
182
(
183
sale_id int identity primary key,
184
book_id int not null,--书籍编号
185
book_num int not null,--书籍数量
186
book_price float not null,--单位价格
187
send_id int not null --订单编号
188
)
189
190
--16.收藏夹 Favorites
191
create table Favorites
192
(
193
f_id int identity primary key,--编号
194
[user_id] int not null,--用户编号
195
book_id int not null,--书籍编号
196
)
197
198
--17.搜索关键字 searchs
199
create table search
200
(
201
s_id int identity primary key,--编号
202
s_name varchar(200) not null,--关键字\
203
s_count int default 1 --查找次数
204
)
205
206
--18.评论表 bbs
207
create table bbs
208
(
209
b_id int identity primary key,--编号
210
b_date datetime default getdate(),
211
b_email varchar(50),
212
book_id int not null
213
)
214
215
--19.蜘蛛抓取到的页面内容 rebot
216
create table rebot
217
(
218
book_id int identity primary key,--书籍编号
219
book_name varchar(200) ,--图书名称
220
class_id int not null,--图书类别 与bookClass表对应
221
book_come varchar(200),--出版社
222
book_author varchar(200) ,--作者
223
book_price varchar(10) ,--定价
224
book_price1 varchar(10),--买出时的价钱
225
book_disk varchar(100),--光盘数
226
book_volume varchar(100),--册数
227
book_image varchar(200),--图片路径
228
book_text text, --书籍说明,内容简介
229
book_date datetime default GETDATE(),--添加日期
230
url varchar(100) ,--页面链接
231
[id] int default 0--图书是否删除,0未被审核,-1未通过审核,其它为该书在book表中的编号
232
)
233
234
--22601-4=22597
235
236
book_name,class_id,book_come,book_author,book_price,book_price1,book_disk,book_volume,book_text,url
237
---------------------------------------------------------------------------------
238
-----------视图------------------------------------------------------------------
239
---------------------------------------------------------------------------------
240
--1.书籍信息视图
241
CREATE VIEW bookInfo
242
as
243
SELECT A.*,B.[class_name] FROM [book] AS A,[bookClass] AS B WHERE A.[class_id]=B.[class_id]
244
245
--2.销售信息记录
246
CREATE VIEW sellStat
247
as
248
SELECT
249
C.[book_id],C.[book_name],C.[book_price] as price1,B.[book_price] as price2,B.[book_num],B.[shop_date],A.[send_isSet_Date]
250
FROM
251
[send] AS A,[shop] AS B,[book] AS C
252
WHERE
253
A.[send_isset]=1 AND
254
A.send_id=B.[send_id] AND
255
B.[book_id]=C.[book_id]
256
257
--3.邮寄记录视图
258
CREATE VIEW setStat0
259
AS
260
SELECT
261
A.[set_id],B.[set_title],A.[set_money],A.[send_isSet_Date]
262
FROM
263
[send] AS A,[set] AS B
264
WHERE
265
A.[set_id]=B.[set_id] AND A.[send_isset]=1
266
267
--4.卖出的书视图
268
CREATE VIEW sellBook
269
AS
270
SELECT
271
B.[book_id],B.[book_name],A.[book_price],A.[book_num] ,A.[send_id]
272
FROM
273
[shop] AS A,[book] AS B
274
WHERE A.[book_id]=B.[book_id]
275
276
--5、未删除书籍
277
create view bookView
278
as
279
select * from book where book_isDel=0
280
281
--6、属性书籍视图 bookRSView
282
create view bookRSView
283
as
284
SELECT A.*,B.[ba_id] FROM book AS A,RS AS B WHERE A.[book_id]=B.book_id AND A.book_isDel=0
285
286
--7、购物车详细内容视图 busView
287
create view busView
288
as
289
SELECT A.*,B.[book_name] FROM [bus] AS A,[book] AS B WHERE A.[book_id]=B.[book_id]
290
291
--8、销售成功记录视图 send_suss_view1
292
create view send_suss_view1
293
as
294
SELECT A.send_id,A.[send_bookMoney],B.[set_title],A.[set_money],A.[send_isSet_Date] as [Date] FROM [send] AS A,[set] AS B WHERE A.[set_id]=B.[set_id] AND A.[send_isSet]=1
295
296
--9、收到汇款但没有发货的记录
297
create view send_suss_view2
298
as
299
SELECT A.send_id,A.[send_bookMoney],B.[set_title],A.[set_money],A.[send_isGet_Date] as [Date] FROM [send] AS A,[set] AS B WHERE A.[set_id]=B.[set_id] AND A.[send_isGet]=1
300
301
--10、发送订单但还没有收到汇款(当然没有交易成功)
302
create view send_suss_view3
303
as
304
SELECT A.send_id,A.[send_bookMoney],B.[set_title],A.[set_money],A.[send_time] as [Date] FROM [send] AS A,[set] AS B WHERE A.[set_id]=B.[set_id] AND A.[send_isGet]=0
305
306
--11、所有订单信息 send_suss_view
307
create view send_suss_view
308
as
309
SELECT
310
A.[send_id],
311
A.[send_bookMoney],
312
[Date]=A.send_time,
313
time2=CASE A.[send_isGet] WHEN 0 THEN '未收到汇款' ELSE CONVERT(CHAR,A.[send_isGet_Date],120) END,
314
time3=CASE A.[send_isset] WHEN 0 THEN '未发送书籍' ELSE CONVERT(CHAR,A.[send_isSet_Date],120) END,
315
A.[set_money],
316
A.[send_time],
317
A.[send_isGet],
318
A.[send_isEnt],
319
A.[send_isset]
320
321
FROM [send]AS A,[set] AS B WHERE A.[set_id]=B.[set_id]
322
323
--12、订单详细信息 showSendView
324
create view showSendView
325
as
326
SELECT
327
A.[send_id],
328
A.[set_com],
329
send_invoice=CASE A.[send_invoice] WHEN 0 THEN '不需要' ELSE '需要' END,
330
A.[send_photo],
331
A.[send_name],
332
sex=CASE A.[send_ms] WHEN 0 THEN '先生' WHEN 1 THEN '女土/小姐' ELSE '保密' END,
333
A.[send_mail],
334
A.[send_add],
335
A.[send_yb],
336
A.[send_isGet_num],
337
A.[send_text],
338
B.[set_title],
339
A.[set_money],
340
A.[send_time],
341
A.[send_isGet],
342
A.[send_bookMoney],
343
A.[send_isEnt],
344
A.[send_isset]
345
FROM [send] AS A,[set] AS B WHERE A.[set_id]=B.[set_id]
346
347
348
--13、行业图书二级栏目 class_two_View
349
create view class_two_View
350
as
351
SELECT [class_id],[class_name],dbo.fun_getPY(class_name) AS PY FROM [bookClass] WHERE [class_parent]=1
352
353
354
--自定义函数,获取首字母
355
CREATE function fun_getPY(@str nvarchar(4000))
356
returns nvarchar(4000)
357
as
358
begin
359
declare @word nchar(1),@PY nvarchar(4000)
360
set @PY=''
361
362
set @word=left(@str,1)
363
--如果非汉字字符,返回原字符
364
set @PY=(case when unicode(@word) between 19968 and 19968+20901
365
then (select top 1 PY from (
366
select 'A' as PY,N'驁' as word
367
union all select 'B',N'簿'
368
union all select 'C',N'錯'
369
union all select 'D',N'鵽'
370
union all select 'E',N'樲'
371
union all select 'F',N'鰒'
372
union all select 'G',N'腂'
373
union all select 'H',N'夻'
374
union all select 'J',N'攈'
375
union all select 'K',N'穒'
376
union all select 'L',N'鱳'
377
union all select 'M',N'旀'
378
union all select 'N',N'桛'
379
union all select 'O',N'漚'
380
union all select 'P',N'曝'
381
union all select 'Q',N'囕'
382
union all select 'R',N'鶸'
383
union all select 'S',N'蜶'
384
union all select 'T',N'籜'
385
union all select 'W',N'鶩'
386
union all select 'X',N'鑂'
387
union all select 'Y',N'韻'
388
union all select 'Z',N'咗'
389
) T
390
where word>=@word collate Chinese_PRC_CS_AS_KS_WS
391
order by PY ASC) else @word end)
392
393
return @PY
394
end
395
396
397
---------------------------------------------------------------------------------
398
-----------四层体系结构----------------------------------------------------------
399
---------------------------------------------------------------------------------
400
--1.表示层 bookshop
401
--2.业务逻辑层 BLL
402
--3.数据访问层 DAL
403
--4.数据库模型 MOD
404
405
--表示层 USL
406
--表示层包括站点的用户界面元素,以及管理访问者和书店之间的交互的所有逻辑。该层使整个站点充满活力,该层的设计对站点的成败是非常重要的。对本系统而言,其表示层是由网页及其组件组成。
407
408
--业务逻辑层 BLL
409
--负责处理表示层的请求,并根据表示层包含的业务逻辑绐表示层一个返回结果。在表示层发生的所有事件都用调用业务逻辑层。例如:如果访问者进行会员登录,表示层就要调用业务逻辑层告诉表示层“该访问者是不是合法用户”。而业务逻辑罢则需要调用数据层,从数据库中获取其中满足表示层请求的信息。
410
411
--数据访问层 DAL
412
--数据访问层提供了访问数据模型层的基本方法,接收业务逻辑层的请求,把数据模型层中的数据发送绐业务逻辑层。对于这个系统来说,需要存储有关书籍资料、会员、购物车等信息,几乎每个访问者请求最终都会通过数据访问层在数据模型层中提取数据。
413
414
--数据模型层 MOD
415
--运用数据集对数据中的相关的表和视图进行封装。
416
417
--对于这四层结构模型,有一个重要的规则:必须按顺序在各层之间进行数据访问,表示层只允许访问业务逻辑层,不能直接访问数据库。业务逻辑层可以与其他两个层进行通信,处理和协调所有的信息流。
418
--数据库
419
420
--C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727
421
422
--d:\windows\system32\inetsrv\data\sDict.txt
423
424
--c:\windows\system32\inetsrv\
425
--data\sDict.txt
426
427
--Cookie
428
--用户编号 book_Cookie_id
429
--用户名称 book_Cookie_name

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

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429
