-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
547 lines (511 loc) · 17.2 KB
/
Copy pathserver.js
File metadata and controls
547 lines (511 loc) · 17.2 KB
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
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
app.use(express.static('public'));
var urlencodedParser = bodyParser.urlencoded({ extended: false })
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Content-Type,Content-Length, Authorization, Accept,X-Requested-With");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
res.header("X-Powered-By",' 3.2.1');
req.setEncoding('utf8');// need fix
if(req.method=="OPTIONS") res.send(200);/*让options请求快速返回*/
else next();
});
app.get('/index.html', function (req, res) {
res.send(__dirname + "/" + "index.html");
})
app.get('/incoming.html', function (req, res) {
res.send(__dirname + "/" + "incoming.html");
})
app.post('/incoming.html', function (req, res) {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query('SELECT * FROM film_info ORDER BY f_date ASC', function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/cinema.html', function (req, res) {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query('SELECT * FROM cinema_info', function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.get('/process_get', function (req, res) {
var response = {
"first_name":req.query.first_name,
"last_name":req.query.last_name
};
console.log(response);
res.end(JSON.stringify(response));
})
app.post('/login', function (req, res) {
var response = {
"user_name":req.query.user_name,
"user_login":false
};
console.log(response);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query('SELECT * FROM user_info', function (error, results, fields) {
if (error) throw error;
for(var i=0;i<results.length;i++){
if(results[i].user_id == req.query.user_name)
if(results[i].pwd == req.query.user_pwd){
response.user_login = true;
}
}
res.end(JSON.stringify(response));
});
})
app.post('/', function (req, res) {
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query('SELECT * FROM film_info ORDER BY f_date ASC', function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchactors', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT actor_name,role_name FROM actor_film WHERE f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchactors_detail', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT actors_info.actor_name as actor_name,role_name,actor_photo FROM actor_film,actors_info WHERE f_title='"+film_name+"' and actor_film.actor_name=actors_info.actor_name", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchdirectors', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT director_name FROM directors WHERE f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/incoming.html/searchactors', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT actor_name,role_name FROM actor_film WHERE f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/incoming.html/searchdirectors', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT director_name FROM directors WHERE f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchfilm', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("SELECT * FROM film_info WHERE f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchcinema', urlencodedParser,function (req, res) {
var c_name = req.query.c_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var response = [];
connection.query("select distinct f_title from film_play,cinema_info where film_play.c_id=cinema_info.c_id and c_name='"+c_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchfilm_and_cinema', urlencodedParser,function (req, res) {
var film_name = req.query.film_name;
var film_date = req.query.film_date;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select distinct c_name,c_loc from film_play,cinema_info where f_title='"+film_name+"' and film_play.c_id=cinema_info.c_id and f_date='"+film_date+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchfilm_from_cinema', urlencodedParser,function (req, res) {
var c_name = req.query.c_name;
var film_date = req.query.film_date;
var film_name = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select distinct f_title,f_time,f_date,price from film_play,cinema_info where c_name='"+c_name+"' and film_play.c_id=cinema_info.c_id and f_date='"+film_date+"' and f_title='"+film_name+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchusername', urlencodedParser,function (req, res) {
var u_id = req.query.user_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select * from user_info where user_id='"+u_id+"'", function (error, results, fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/create_user', urlencodedParser,function (req, res) {
var u_id = req.query.user_name;
var nick_name = req.query.nick_name;
var pwd = req.query.pwd;
console.log(u_id + " " + nick_name + " " + pwd);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var addSqlParams = [u_id,nick_name,"img/photo/root.jpg",pwd];
connection.query("Insert into user_info(user_id,nickname,user_photo,pwd) values(?,?,?,?)",addSqlParams,function (error,results) {
if (error) throw error;
res.end(JSON.stringify("yes"));
});
})
app.post('/create_order', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var f_title = req.query.film_name;
var c_name = req.query.c_name;
var f_date = req.query.f_date;
var f_time = req.query.f_time;
var order_price = req.query.order_price;
var seat_info = req.query.seat_info;
var order_id = "";
for(var i=0;i<f_date.length;i++)
if('0' <= f_date[i] && f_date[i] <= '9')
order_id += f_date[i];
for(var i=0;i<f_time.length;i++)
if('0' <= f_time[i] && f_time[i] <= '9')
order_id += f_time[i];
var tmp = 0;
for(var i=0;i<u_id.length;i++)
tmp = (tmp * 23 + u_id[i].charCodeAt()) % 1000000;
for(var i=0;i<c_name.length;i++)
tmp = (tmp * 23 + c_name[i].charCodeAt()) % 1000000;
for(var i=0;i<f_title.length;i++)
tmp = (tmp * 23 + f_title[i].charCodeAt()) % 1000000;
var tmp2 = 0;
for(var i=0;i<seat_info.length;i++)
tmp2 = (tmp2 * 128 + seat_info[i].charCodeAt() ) % 10000;
order_id += "" + tmp + "" + tmp2;
console.log(order_id);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
res.end(JSON.stringify(order_id));
connection.connect();
var addSqlParams=[order_id,u_id,f_title,f_date,f_time,c_name,order_price];
connection.query("Insert into order_table(order_id,user_id,f_title,f_date,f_time,c_name,order_price) values(?,?,?,?,?,?,?)",addSqlParams,function (error,results) {
if (error) throw error;
});
seat_info = seat_info.split('-');
for(var i=0;i<seat_info.length;i++) {
connection.query("Insert into order_seat(order_id,seats_id) values(?,?)",[order_id,parseInt(seat_info[i])],function (error,results) {
if (error) throw error;
});
}
})
app.post('/checkseats', urlencodedParser,function (req, res) {
var f_title = req.query.film_name;
var c_name = req.query.c_name;
var f_date = req.query.f_date;
var f_time = req.query.f_time;
console.log([f_time,f_title,c_name,f_date]);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select seats_id from order_table,order_seat where order_table.order_id=order_seat.order_id and f_title='"+f_title+"' and f_date='"+f_date+"' and f_time='"+f_time+"' and c_name='"+c_name+"'",function (error,results,fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/search_order_user', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select order_id,user_id,left(order_table.f_date,100) as f_date,order_table.f_time as f_time,order_table.f_title as f_title,c_name,file_poster,order_price from order_table,film_info where order_table.f_title=film_info.f_title and user_id='"+u_id+"' order by order_table.f_date desc",function (error,results,fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/searchactors_want_to_see', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var f_title = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select * from user_want where user_id='"+u_id+"' and f_title='"+f_title+"'",function (error,results,fields) {
if (error) throw error;
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/update_want_to_see', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var f_title = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var addSqlParams=[u_id,f_title];
connection.query("insert into user_want(user_id,f_title) values(?,?)",addSqlParams,function (error,results) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/delete_want_to_see', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var f_title = req.query.film_name;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var addSqlParams=[u_id,f_title];
connection.query("delete from user_want where user_id='"+u_id+"' and f_title='"+f_title+"'",function (error,results) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/search_user_want', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select film_info.* from user_want,film_info where user_id='"+u_id+"' and user_want.f_title=film_info.f_title",function (error,results,fields) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/update_comment', urlencodedParser,function (req, res) {
var u_id = req.query.user_id;
var f_title = req.query.f_title;
var text = req.query.comment;
var stars = req.query.stars;
var c_date = req.query.c_date;
var c_time = req.query.c_time;
console.log(req.query);
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
var addSqlParam=[u_id,f_title,text,stars,c_date,c_time];
connection.query("insert into user_comment_film(user_id,f_title,user_comment,stars,c_date,c_time) values(?,?,?,?,?,?)",addSqlParam,function (error,results) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/search_comment', urlencodedParser,function (req, res) {
var f_title = req.query.f_title;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select * from user_comment_film where f_title='"+f_title+"' order by c_date desc,c_time desc",function (error,results,fields) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/search_order_seat', urlencodedParser,function (req, res) {
var order_id = req.query.order_id;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select * from order_seat where order_id='"+order_id+"'",function (error,results,fields) {
console.log(results);
res.end(JSON.stringify(results));
});
})
app.post('/search_movie', urlencodedParser,function (req, res) {
var f_title = req.query.f_title;
var mysql = require('mysql');
var connection = mysql.createConnection({
host : 'localhost',
user : 'root',
password : 'root',
database : 'html5work'
});
connection.connect();
connection.query("select * from film_movie where f_title='"+f_title+"'",function (error,results,fields) {
console.log(results);
res.end(JSON.stringify(results));
});
})
var server = app.listen(8081, function () {
var host = server.address().address;
var port = server.address().port;
console.log("应用实例,访问地址为 http://%s:%s", host, port);
})