-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp1.js
1482 lines (1479 loc) · 54.8 KB
/
app1.js
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
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
const express = require('express');
const fs = require('fs');
const path = require('path');
const bodyParser = require('body-parser');
const app = express();
const async = require('async');
const MD5 = require('md5');
const mysqli = require('./mysql.js');
const static = require('./staticDataPool');
const shoppingCar = require('./shoppingCar');
const area = require('./public/area');
const session = require('express-session');
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
const server = require('http').Server(app);
const io = require('socket.io')(server);
app.use(express.static('./public'));
app.use(session({
secret: '12345',
cookie : {
maxAge: 3600 * 1000,
secure: true
},
name: 'app1',
cookie:{maxAge:60000},
resave:false,
saveUninitialized: true
}))
static.transmission();
let user_FriendList = [];
app.all('*',function(req,res,next){
//设置请求头
//允许所有来源访问
res.header('Access-Control-Allow-Origin', '*')
//用于判断request来自ajax还是传统请求
res.header('Access-Control-Allow-Headers', 'X-Requested-With')
//允许访问的方式
res.header('Access-Control-Allow-Methods', 'PUT,POST,GET,DELETE,OPTIONS')
//修改程序信息与版本
res.header('X-Powered-By', ' 3.2.1')
//内容类型:如果是post请求必须指定这个属性
res.header('Content-Type', 'application/json;charset=utf-8')
res.header("Access-Control-Allow-Headers", "Content-Type,XFILENAME,XFILECATEGORY,XFILESIZE")
next()
})
app.get('/home', (req,res)=>{
const sql = 'select * from v_Advertisement';
const menuList = [{
"id": "0001",
"title": "雕塑手办",
"chlidren": [{
"id":"0001",
"title": "大型雕塑"
}, {
"id":"0001",
"title": "中型雕塑"
}, {
"id":"0003",
"title": "限定手办"
}, {
"id":"0004",
"title": "迷你手办"
}, {
"id":"0005",
"title": "手办"
}]
}, {
"id": "0002",
"title": "毛绒玩偶",
"chlidren":[{
"id":"0001",
"title": "帽子"
}, {
"id":"0002",
"title": "玩偶"
}]
}, {
"id": "0003",
"title": "男女服饰",
"chlidren":[{
"id":"0001",
"title": "卫衣&夹克"
}, {
"id":"0002",
"title": "T恤"
}, {
"id":"0003",
"title": "其他"
}]
}, {
"id": "0004",
"title": "赛事周边",
"chlidren":[{
"id":"0001",
"title": "LPL X NIKE"
}, {
"id":"0002",
"title": "LPL其他"
}]
}, {
"id": "0005",
"title": "珠宝首饰",
"chlidren":[{
"id":"0001",
"title": "项链"
}, {
"id":"0002",
"title": "幸运珠"
}, {
"id":"0003",
"title": "手链"
}, {
"id":"0004",
"title": "配件"
}]
}, {
"id": "0006",
"title": "其他",
"chlidren":[{
"id":"0001",
"title": "手机壳"
}, {
"id":"0002",
"title": "鼠标垫"
}, {
"id":"0003",
"title": "艺术海报"
}, {
"id":"0004",
"title": "其他"
}]
}]
// "user_Img": 用户头像图片,
// "user_Id": 请求的用户的ID,
// "user_Name": 请求的用户的名字,
// "user_Sex": 请求的用户的性别,
// "user_Age": 请求的用户的年龄,
// "user_Address": 请求的用户的地址,
// "user_Telephone": 请求的用户的电话号码,
//先看下查出来的是什么东西然后再进行导入,上面的是导入的格式
// userFriendList = result. //好友列
mysqli.exec({
sql: sql,
success: resulte => {
if (resulte.length != 0) {
res.json({
ret: true,
data: resulte,
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
menuList,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
app.get('/homeCommodity', (req,res) => {
console.log(req.query)
const sql = 'select id, commodity_Name, commodity_Img, commodity_Per, commodity_State from v_commodity_data where id > ? and id < ?'
mysqli.exec({
sql: sql,
params: [req.query.numberOne, req.query.numberTwo],
success: resulte => {
if (resulte.length != 0) {
res.json({
code: 202,
data: resulte
})
} else {
console.log(resulte)
res.json({
code: 204
})
}
},
error: err => {
console.log(err)
}
})
})
//注册
app.post('/postUserInformation', (req, res) => {
console.log(req.body);
let request = '',
actionState = true, //注册动作是否合格状态
//判断是登录还是注册
//如果是注册则从数据池中对比注册的电话号码是否已存在
sql = `insert into t_user_data(user_id,user_name,user_sex,user_age,user_address,user_telephone,user_password,user_perpassword,user_img,user_FriendList) values (null,?,'男',0,'北京市 北京市 朝阳区',?,?,?,'userHeader/defalut.jpg',9)`;
JSON.parse(static.interface_replace_Data_User).forEach(element => {
if (req.body.telephone == element.user_telephone) {
return actionState = false;
}
})
if (actionState) {
let resiter_id = 0
mysqli.exec({
sql: sql,
params: [req.body.name, req.body.telephone, req.body.password, req.body.passwordPer],
success: resulte => {
resiter_id = resulte.insertId
request = 'success';
res.json({
ret: true,
data: request,
code: 200
});
const staticFile = '{"userId": []}'
existsSync = () => {
console.log('创建')
const exists = fs.existsSync(path.join(__dirname, 'public', resiter_id + '.json'));
if (!exists) {
const Establish = fs.writeFile(path.join(__dirname, 'public', resiter_id + '.json'), staticFile, (err) => {
if (err) {
console.log(err)
}
})
}
}
existsSync();
sql = 'select user_FriendList from t_user_data where user_telephone = 0'
mysqli.exec({
sql: sql,
success: resulte => {
let user_FriendListId = resulte[0].user_FriendList.split(',');
user_FriendListId.push(resiter_id)
user_FriendListId = user_FriendListId.join(',')
sql = 'update t_user_data set user_FriendList = ? where user_telephone = 0'
mysqli.exec({
sql: sql,
params: [user_FriendListId],
success: resulte => {
},
error: err => {
console.log('err:', err);
}
});
},
error: err => {
console.log('err:', err);
}
});
},
error: err => {
console.log('err:', err);
}
});
} else {
request = 'fail';
res.json({
ret: true,
data: request,
code: 200
});
}
})
// 登录
app.post('/getUserInformation', (req, res) => {
console.log(req.query.account);
const sql = 'select user_Id,user_Name,user_Sex,user_Age,user_Address,user_Telephone,user_Img from t_user_data where user_telephone = ? and user_password = ?';
// "user_Img": 用户头像图片,
// "user_Id": 请求的用户的ID,
// "user_Name": 请求的用户的名字,
// "user_Sex": 请求的用户的性别,
// "user_Age": 请求的用户的年龄,
// "user_Address": 请求的用户的地址,
// "user_Telephone": 请求的用户的电话号码,
//先看下查出来的是什么东西然后再进行导入,上面的是导入的格式
// userFriendList = result. //好友列
mysqli.exec({
sql: sql,
params: [req.body.account, req.body.password],
success: resulte => {
if (resulte.length != 0) {
if (!req.session.userInformation) {
req.session.userInformation = {}
}
mysqli.exec({
sql: 'update t_user_data set user_implementation = now() where user_id = ?',
params: [resulte[0].user_Id]
})
const currUserId = JSON.stringify(resulte[0].user_Id)
console.log(currUserId)
req.session.userInformation[currUserId] = MD5(currUserId);
req.session.save
console.log(req.session)
res.json({
ret: true,
data: resulte,
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
// //用户头像采用路径
app.post('/postChangePirvateInformation', (req, res) => {
const sql = 'update t_user_data set user_Name = ? , user_Sex = ?, user_Age = ?, user_Address = ?, user_Telephone = ?, user_img = ? where user_Id = ?';
const base64 = req.body.user_Img.replace(/^data:image\/\w+;base64,/, ""); //去掉图片base64码前面部分data:image/png;base64
const dataBuffer = new Buffer(base64, 'base64'); //把base64码转成buffer对象
fs.writeFile(path.join(__dirname, 'public', 'userHeader', req.body.user_Id+'.jpg'), dataBuffer, function (err) {//用fs写入文件
if (err) {
console.log(err);
} else {
console.log('写入成功!');
}
});
mysqli.exec({
sql: sql,
params: [req.body.user_Name, req.body.user_Sex, req.body.user_Age, req.body.user_Address, req.body.user_Telephone,`userHeader/` + req.body.user_Id + `.jpg` ,req.body.user_Id],
success: resulte => {
if (resulte.length != 0) {
res.json({
ret: true,
data: {
"user_Img": req.body.user_Img,
"user_Id": req.body.user_Id,
"user_Name": req.body.user_Name,
"user_Sex": req.body.user_Sex,
"user_Age": req.body.user_Age,
"user_Address": req.body.user_Address,
"user_Telephone": req.body.user_Telephone
},
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
app.get('/getFriend', (req,res)=>{
console.log(req.query.selectAccountNumber,11111);
const sql = 'select user_Id,user_Name,user_Sex,user_Age,user_Address,user_Telephone,user_Img from t_user_data where user_Telephone = ?';
// "user_Img": 用户头像图片,
// "user_Id": 请求的用户的ID,
// "user_Name": 请求的用户的名字,
// "user_Sex": 请求的用户的性别,
// "user_Age": 请求的用户的年龄,
// "user_Address": 请求的用户的地址,
// "user_Telephone": 请求的用户的电话号码,
//先看下查出来的是什么东西然后再进行导入,上面的是导入的格式
// userFriendList = result. //好友列
mysqli.exec({
sql: sql,
params: [req.query.selectAccountNumber],
success: resulte => {
console.log(resulte)
if (resulte.length != 0) {
res.json({
ret: true,
data: resulte,
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
app.post('/postFriend', (req,res)=>{
let sql = 'select * from t_user_data where user_Id = ?';
// "user_Img": 用户头像图片,
// "user_Id": 请求的用户的ID,
// "user_Name": 请求的用户的名字,
// "user_Sex": 请求的用户的性别,
// "user_Age": 请求的用户的年龄,
// "user_Address": 请求的用户的地址,
// "user_Telephone": 请求的用户的电话号码,
//先看下查出来的是什么东西然后再进行导入,上面的是导入的格式
// userFriendList = result. //好友列
mysqli.exec({
sql: sql,
params: [req.body.userId],
success: resulte => {
console.log(resulte[0].user_FriendList.split(','))
console.log(resulte)
let friendList = resulte[0].user_FriendList.split(',')
friendList.push(req.body.firendId)
friendList = friendList.join(',')
console.log(friendList)
sql = `update t_user_data set user_FriendList = ? where user_id = ?`
mysqli.exec({
sql: sql,
params: [friendList,req.body.userId],
success: resulte => {
res.json({
ret: true,
code: 200
});
},
error: err => {
console.log('err:', err);
}
});
},
error: err => {
console.log('err:', err);
}
});
})
// //根据id查询
app.get('/getUserColloection', (req, res) => {
console.log(req.query);
const colloectionImg = [
{
"id": "0001",
"class": "雕塑手办",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201909/20190918215352_85132.big.jpg"
}, {
"id": "0002",
"class": "毛绒玩偶",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201907/20190723090952_54659.big.jpg"
}, {
"id": "0003",
"class": "男女服饰",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201909/20190927232417_15783.big.jpg"
}, {
"id": "0004",
"class": "周边赛事",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201910/20191010171219_30038.big.jpg"
}, {
"id": "0005",
"class": "珠宝首饰",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201911/20191110140102_88888.big.jpg"
}, {
"id": "0006",
"class": "其他",
"imgUrl": "https://game.gtimg.cn/images/zb/x5/uploadImg/goods/201909/20190918190738_29365.big.jpg"
}]
const sql = `select id , commodity_img as 'imgUrl', commodity_per as 'price', commodity_name as 'title', commodity_Class as commodity_Class from v_collocetion where colloection_userid = ?`;
mysqli.exec({
sql: sql,
params: [req.query.userId],
success: resulte => {
if (resulte.length != 0) {
res.json({
ret: true,
data: resulte,
code: 200,
colloectionImg: colloectionImg
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
app.post('/postUserColloection', (req, res) => {
console.log(req.body);
if (req.body.actionStyle == 'del') {
sql = 'delete from t_user_colloection where colloection_userid = ? and colloection_commodity = ?';
req.body.colloectionList.forEach((e, i) => {
mysqli.exec({
sql: sql,
params: [req.body.userId, e.id],
success: resulte => {
if (i == req.body.colloectionList.length - 1) {
res.json({
ret: true,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
} else {
const sql = `select * from t_user_colloection where colloection_userid = ? and colloection_commodity = ?`;
mysqli.exec({
sql: sql,
params: [req.body.userId, req.body.commodity],
success: resulte => {
if (resulte.length != 0) {
const sql = `delete from t_user_colloection where colloection_userid = ? and colloection_commodity = ?`;
mysqli.exec({
sql: sql,
params: [req.body.userId, req.body.commodity],
success: resulte => {
res.json({
ret: true,
code: 200
});
},
error: err => {
console.log('err:', err);
}
});
} else {
const sql = `insert into t_user_colloection(colloection_id,colloection_userid,colloection_commodity,colloection_generateTime) values (null,?,?,now)`;
mysqli.exec({
sql: sql,
params: [req.body.userId, req.body.commodity],
success: resulte => {
res.json({
ret: true,
code: 200
});
},
error: err => {
console.log('err:', err);
}
});
}
},
error: err => {
console.log('err:', err);
}
});
}
})
// //根据ID查询,查收藏栏
app.get('/getUserShoppingCar', (req, res) => {
const sql = 'select id, shoppingCar_id, commodity_Img as imgUrl, commodity_Name as title, shoppingCar_Size as size, commodity_Per as price, shoppingCar_Number as number from v_shoppingCar where shoppingCar_UserId = ?';
// "id": "0001", 商品id
// "imgUrl": "https://game.gtimg.cn/images/daojushop/zb/ad/201910/20191011101011_968962.jpg", 商品图片
// "title": "LPL x NIKE联名新品", 商品名字
// "size": "常规", 商品的型号
// "price": "400", 商品价格
// "number": 1, 商品数量
mysqli.exec({
sql: sql,
params: [req.query.userId],
success: resulte => {
console.log(resulte)
if (resulte.length != 0) {
res.json({
ret: true,
data: resulte,
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
// // 根据id修改,只修改用户表,先查后改
app.post('/postUserShoppingCar', (req, res) => {
// {
// userId: 0,
// data: [
// {
// id: '0003',
// imgUrl: 'https://game.gtimg.cn/images/daojushop/zb/ad/201910/20191030093036_590932.jpg',
// title: '万圣节迷你套装',
// commodity_Class: '雕塑手办',
// price: '400',
// number: 1,
// state: true
// }
// ],
// actionStyle: 'check'
// }
let sql = '';
console.log(req.body)
let orderIdlist = []
if (req.body.actionStyle == 'check') {
sql = 'insert into t_order_data(order_Id,order_Commodity,order_Number,order_Size,order_State,order_UserId,order_generateTime) values (null,?,?,?,?,?,now())';
req.body.data.forEach((e, i) => {
mysqli.exec({
sql: sql,
params: [e.id, e.number, e.size, '未支付', req.body.userId],
success: resulte => {
console.log(orderIdlist)
orderIdlist.push(resulte.insertId)
if (i == req.body.data.length - 1) {
res.json({
ret: true,
code: 200,
orderIdlist: orderIdlist
})
}
},
error: err => {
console.log('err:', err);
}
});
});
} else {
if (req.body.actionStyle == 'del') {
sql = 'delete from t_shopping_cart where shoppingCar_userid = ? and shoppingCar_Commodity = ?';
req.body.data.forEach((e) => {
mysqli.exec({
sql: sql,
params: [req.body.userId, e.id],
success: resulte => {
},
error: err => {
console.log('err:', err);
}
});
})
} else {
sql = `select shoppingCar_Number from v_shoppingcar where shoppingCar_Size = ? and shoppingCar_UserId = ? and id = ?`;
mysqli.exec({
sql: sql,
params: [req.body.informationCommodityData.size, req.body.userId, req.body.informationCommodityData.commodityId],
success: resulte => {
console.log(resulte)
if (resulte.length != 0) {
const newNumber = resulte[0].shoppingCar_Number + parseInt(req.body.informationCommodityData.number)
sql = `update t_shopping_cart set shoppingCar_Number = ? where shoppingCar_Commodity = ? and shoppingCar_Size = ? and shoppingCar_UserId = ?`;
mysqli.exec({
sql: sql,
params: [newNumber, req.body.informationCommodityData.commodityId, req.body.informationCommodityData.size, req.body.userId],
success: resulte => {
res.json({
ret: true,
code: 200
})
},
error: err => {
console.log('err:', err);
}
});
} else {
sql = `insert into t_shopping_cart(shoppingCar_id,shoppingCar_Commodity,shoppingCar_Number,shoppingCar_size,shoppingCar_UserId,shoppingCar_GennerateTime) values (null,?,?,?,?,now())`;
mysqli.exec({
sql: sql,
params: [req.body.informationCommodityData.commodityId, req.body.informationCommodityData.number, req.body.informationCommodityData.size, req.body.userId],
success: resulte => {
res.json({
ret: true,
code: 200
})
},
error: err => {
console.log('err:', err);
}
});
}
},
error: err => {
console.log('err:', err);
}
});
}
}
})
// //根据id查询,根据不同的返回数据调用不同的sql语句
app.get('/getUserOrderColumn', (req, res) => {
console.log(req.query);
let sql = ``
const userOrderColumnInformation = {};
if (req.query.action == 'pay') {
sql = `select order_id as id ,commodity_img as imgUrl ,commodity_name as title , commodity_per as price , order_number as number from v_order where order_userid = ? and order_state = '未支付'`;
} else if (req.query.action == 'Receiv') {
sql = `select order_id as id ,commodity_img as imgUrl ,commodity_name as title , commodity_per as price , order_number as number from v_order where order_userid = ? and order_state = '待收货'`;
} else {
sql = `select order_id as id ,commodity_img as imgUrl ,commodity_name as title , commodity_per as price , order_number as number from v_order where order_userid = ? and order_state = '待评论'`;
}
mysqli.exec({
sql: sql,
params: [req.query.userId],
success: resulte => {
if (resulte.length != 0) {
res.json({
ret: true,
data: resulte,
code: 200
});
} else {
res.json({
ret: false,
data: resulte,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
// //根据id修改,根据不同的返回数据调用不同的sql语句
app.post('/postUserOrderColumn', (req, res) => {
let sql = '',
params = [],
returnVal = '';
if (req.body.action == 'delpay') {
sql = 'delete from t_order_data where order_userid = ? and order_Id= ?';
params = [req.body.userId, req.body.orderId];
returnVal = req.body.orderId
mysqli.exec({
sql: sql,
params: params,
success: resulte => {
res.json({
ret: true,
code: 200,
orderNumber: returnVal
})
},
error: err => {
console.log('err:', err);
}
});
} else {
sql = `insert into t_order_data(order_Id,order_Commodity,order_Number,order_Size,order_State,order_UserId) values (null,?,?,?,'未支付', ?)`
params = [req.body.commodity.commodityId, req.body.commodity.number, req.body.commodity.size, req.body.userId]
mysqli.exec({
sql: sql,
params: params,
success: resulte => {
res.json({
ret: true,
code: 200,
orderNumber: resulte.insertId
})
},
error: err => {
console.log('err:', err);
}
});
}
})
app.get('/getOrderDetalis', (req, res) =>{
console.log(req.query)
const sql = `select telephonNumber,addressDetalis,contacts,orderDetalisNumber,orderDetalisSize,orderDetalistTitle,orderDetalistImg,orderDetalisPrice from v_orderDetallis where user_id = ? and order_id = ?`
mysqli.exec({
sql: sql,
params: [req.query.userId,req.query.payId],
success: resulte => {
console.log(resulte)
const orderDetaillsInformation = {
orderDetalisNumber: resulte[0].orderDetalisNumber,
orderDetalistImg: resulte[0].orderDetalistImg,
orderDetalistTitle: resulte[0].orderDetalistTitle,
orderDetalisPrice: resulte[0].orderDetalisPrice,
orderDetalisSize: resulte[0].orderDetalisSize,
orderDetalisPriceSum: resulte[0].orderDetalisNumber * resulte[0].orderDetalisPrice,
orderDetalisAddress: `[{"addressDetalis": ${'"'+ resulte[0].addressDetalis+ '"'},"contacts": ${'"' + resulte[0].contacts + '"'},"telephonNumber": ${resulte[0].telephonNumber}}]`
}
res.json({
ret: true,
code: 200,
orderDetaillsInformation
})
},
error: err => {
console.log('err:', err);
}
});
})
app.post('/postOrderDetalis', (req, res) =>{
console.log(req.body)
sql = `update t_order_data set order_Number = ? , order_Size = ? where order_userid = ? and order_id = ?;`
mysqli.exec({
sql: sql,
params: [req.body.orderInformation.orderDetalisNumber,req.body.orderInformation.orderDetalisSize,req.body.userId,req.body.orderId],
error: err => {
console.log('err:', err);
}
});
res.json({
ret: true
})
})
app.get('/getEmitAddress', (req,res)=>{
console.log(req.query)
const sql = `select telephone, addressReceiv, addressReceivDetallis, receiveName from v_address where user_id = ? and order_id = ?`
mysqli.exec({
sql: sql,
params: [req.query.userId,req.query.payId],
success: resulte => {
let areaCode = '',country = '',city = '',county = '';
if (resulte[0].addressReceiv !== ''){
for(let i in area.county_list) {
if (area.county_list[i] == resulte[0].addressReceiv.split(' ')[2]){
areaCode = i
}
}
country = resulte[0].addressReceiv.split(' ')[1]
city = resulte[0].addressReceiv.split(' ')[1]
county = resulte[0].addressReceiv.split(' ')[1]
}
console.log(areaCode)
res.json({
ret: true,
EmitAddressData: {
addressDetail: resulte[0].addressReceivDetallis,
areaCode,
city,
country,
county,
name: resulte[0].receiveName,
province: resulte[0].addressReceiv.split(' ')[0],
tel: resulte[0].telephone,
}
});
},
error: err => {
console.log('err:', err);
}
});
});
app.post('/postEmitAddress' ,(req, res) =>{
console.log(req.body)
let sql = `update address set receiveName = ?, telephone = ? , addressReceiv = ? , addressReceivDetallis = ? where user_id = ? and order_id = ?;`
const addressReceivInformation = req.body.emitAddressInformation.province + ' ' + req.body.emitAddressInformation.city + ' ' + req.body.emitAddressInformation.county
mysqli.exec({
sql: sql,
params: [req.body.emitAddressInformation.name, req.body.emitAddressInformation.tel, addressReceivInformation, req.body.emitAddressInformation.addressDetail, req.body.userId, req.body.payId],
error: err => {
console.log('err:', err);
}
});
res.json({
ret:true
})
})
// //下面这个是将用户传输过来的支付密码进行判定
app.post('/postUserBillPay', (req, res) => {
console.log(req.body);
let sql = 'select user_perpassword from t_user_data where user_id = ?'
mysqli.exec({
sql: sql,
params: [req.body.UserId],
success: resulte => {
console.log(resulte[0].user_perpassword)
if (resulte[0].user_perpassword == req.body.value) {
if (req.body.action == 'ShoppingCar' || req.body.action == 'pay') {
sql = `update t_order_data set order_State = '待收货' where order_id = ? and order_UserId = ?`;
} else {
sql = `update t_order_data set order_State = '待评论' where order_id = ? and order_UserId = ?`;
}
if (typeof(req.body.orderId) == Array) {
req.body.orderId.forEach((e, i) => {
mysqli.exec({
sql: sql,
params: [e, req.body.UserId],
success: resulte => {
if (i == req.body.orderId.length - 1) {
res.json({
ret: true,
code: 200
})
}
},
error: err => {
console.log('err:', err);
}
});
})
} else {
mysqli.exec({
sql: sql,
params: [req.body.orderId, req.body.UserId],
success: resulte => {
res.json({
ret: true,
code: 200
})
},
error: err => {
console.log('err:', err);
}
});
}
} else {
res.json({
ret: false,
code: 200
})
}
},
error: err => {
console.log('err:', err);
}
});
})
app.get('/getCommodity', (req, res) => {
const sql = 'select id, commodity_img as imgUrl , commodity_name as title , commodity_per as price , commodity_img_hover as imgUrl1, commodity_Presonality, commodity_State as commodityState from v_commodity_data where id = ?';
// "id": "0001", 商品id
// "imgUrl": "https://game.gtimg.cn/images/daojushop/zb/ad/201910/20191011101011_968962.jpg", 商品图片
// "title": "LPL x NIKE联名新品", 商品名字
// "size": "常规", 商品的型号
// "price": "400", 商品价格
// "number": 1, 商品数量
mysqli.exec({
sql: sql,
params: [req.query.commodityId],
success: resulte => {
console.log(resulte)
let commodityInformation = resulte
if (req.query.userId) {
console.log(1)
const sql = `select * from t_user_colloection where colloection_userid = ? and colloection_commodity = ?`;
mysqli.exec({
sql: sql,
params: [req.query.userId,commodityInformation.id],
success: resulte => {
commodityInformation[0].newParam = 'conllectionState'
if (resulte.length != 0) {
commodityInformation[0].conllectionState = true
} else {
commodityInformation[0].conllectionState = false
}
console.log(commodityInformation)
res.json({
ret: true,
data: commodityInformation,
code: 200
});
},
error: err => {
console.log('err:', err);
}
});
} else {
res.json({
ret: true,
data: commodityInformation,
code: 200
});
}
},
error: err => {
console.log('err:', err);
}
});
})
app.get('/getUserDialogues', (req, res) => {
user_FriendListObject = [];
let = sql = 'select user_FriendList from t_user_data where user_id = ?'
mysqli.exec({
sql: sql,
params: [req.query.userId],
success: resulte => {
const user_FriendListId = resulte[0].user_FriendList.split(',');
user_FriendListId.forEach(e => {
user_FriendList.push({
id: e,
socket: ''
})
user_FriendListObject.push({
id: e
})
})
sql = 'select user_Id as id,user_Name as userName,user_Img as userRelationHeadImg from t_user_data where user_id = ?';
let dialogueContentAll = []
if (user_FriendListObject.length != 0) {
user_FriendListObject.forEach((e, i) => {
// "user_Img": 用户头像图片,
// "user_Id": 请求的用户的ID,
// "user_Name": 请求的用户的名字,
// "user_Sex": 请求的用户的性别,
// "user_Age": 请求的用户的年龄,
// "user_Address": 请求的用户的地址,
// "user_Telephone": 请求的用户的电话号码,
//先看下查出来的是什么东西然后再进行导入,上面的是导入的格式