Lists.php
39.5 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
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Cookie;
use app\common\library\Auth;
use think\Db;
use fast\Random;
use think\Session;
use think\Cache;
use think\Validate;
/**
* 各种列表以及详情接口
*/
class Lists extends Api
{
protected $noNeedLogin = ['get_list','type_title','type_list','ke_list','index','sou','policy','download','index_info','policy_info','download_info','video_list','video_detail','study','password_login','find_pwd','ke_list_detail','getcode','verify'];
protected $noNeedRight = ['*'];
/**
* @ApiTitle (通知公告列表)
* @ApiSummary (通知公告列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/index)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
* @ApiParams (name="keyword", type="string", required=false, description="搜索关键字")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"title"://标题
"is_up"://是否上架0否1是
"file_name"://附件名称
"createtime"://创建时间
"desc"://简介
]
}
})
*/
public function index()
{
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$where = true;
}else{
$where['title'] = ['like',"%$keyword%"];
}
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data['total_num'] = Db::name('information')
->where($where)
->count();
$data['info'] = Db::name('information')
->field('id,title,is_up,desc,createtime')
->where($where)
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (搜索)
* @ApiSummary (搜索)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/sou)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
* @ApiParams (name="keyword", type="string", required=false, description="搜索关键字")
* @ApiParams (name="type", type="inter", required=false, description="类型1通知公告2优选课程3培训课程4政策动态5下载专区")
* @ApiParams (name="id", type="inter", required=false, description="学习系统id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
]
}
})
*/
public function sou()
{
$user_id = $this->auth->id;
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$type = $this->request->param('type');
if(empty($type)){
$this->error('缺少必要参数');
}
$keyword = $this->request->param('keyword');
if(empty($keyword)){
$this->error('请输入关键字');
}
if($type == 1){
$data['total_num'] = Db::name('information')
->where('title','like',"%$keyword%")
->count();
$data['info'] = Db::name('information')
->field('id,title,is_up,desc,createtime')
->where('title','like',"%$keyword%")
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}elseif ($type == 2){
$data['total_num'] = Db::name('optimization')
->where('title','like',"%$keyword%")
->count();
$data['info'] = Db::name('optimization')
->where('title','like',"%$keyword%")
->order('createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
// 获取视频时长
$video_avinfo = json_decode(file_get_contents(cdnurl($v['video_file'], true) . '?avinfo'), true); // 获取视频元信息
$duration = ceil($video_avinfo['format']['duration']);
$v['duration'] = gmdate('H:i:s',$duration);
$v['image'] = cdnurl($v['image'],true);
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}elseif ($type == 3){
if(!$this->auth->isLogin()){
$this->error(__('Please login first'), null, 401);
}
$id = $this->request->param('id');
if(empty($id)){
$this->error('学习系统id不能为空');
}
$data['total_num'] = Db::name('classes')
->where('name','like',"%$keyword%")
->count();
$data['info'] = Db::name('classes')
->field('createtime,updatetime',true)
->where('name','like',"%$keyword%")
->page($page,$pageNum)
->order('id desc')
->select();
foreach ($data['info'] as &$v){
$v['video_file'] = cdnurl($v['video_file'],true);
$video_info = json_decode(file_get_contents($v['video_file'] . '?avinfo'), true);
$v['video_image'] = $this->get_video_first_image( $v['video_file'], $video_info);
}
$this->success('success',$data);
}elseif ($type == 4){
$data['total_num'] = Db::name('policy')
->where('title','like',"%$keyword%")
->count();
$data['info'] = Db::name('policy')
->field('id,title,is_up,desc,createtime')
->where('title','like',"%$keyword%")
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}elseif ($type == 5){
$data['total_num'] = Db::name('download')
->where('title','like',"%$keyword%")
->count();
$data['info'] = Db::name('download')
->field('id,title,is_up,desc,createtime')
->where('title','like',"%$keyword%")
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}else{
$this->error('类型错误');
}
}
public function get_video_first_image($video_url,$video_info){
if(empty($video_info['streams'][0]['width'])) {
$width = $video_info['streams'][1]['width'];
$height = $video_info['streams'][1]['height'];
} else {
$width = $video_info['streams'][0]['width'];
$height = $video_info['streams'][0]['height'];
}
return $video_url.'?vframe/jpg/offset/1/w/'.$width.'/h/'.$height;
}
/**
* @ApiTitle (政策动态列表)
* @ApiSummary (政策动态列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/policy)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"file_name"://附件名称
"title"://标题
"is_up"://是否上架0否1是
"createtime"://创建时间
]
}
})
*/
public function policy()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data['total_num'] = Db::name('policy')
->count();
$data['info'] = Db::name('policy')
->field('id,title,is_up,desc,createtime')
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (下载专区列表)
* @ApiSummary (下载专区列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/download)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"file_name"://附件名称
"title"://标题
"is_up"://是否上架0否1是
"createtime"://创建时间
]
}
})
*/
public function download()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data['total_num'] = Db::name('download')
->count();
$data['info'] = Db::name('download')
->field('id,title,is_up,desc,createtime')
->order('is_up desc,createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (通知公告详情)
* @ApiSummary (通知公告详情)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/index_info)
*
* @ApiParams (name="id", type="int", required=true, description="公告ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://ID
"title"://标题
"from"://转载于
"content"://内容详情
"file_name"://附件名称
"file"://附件
"is_up"://是否上架0否1是
"createtime"://创建时间
}
})
*/
public function index_info()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('information')
->where('id',$id)
->field('updatetime',true)
->find();
// if(!empty($data['file'])){
// $base_url = $data['file'];
// $qiniu_url = $qiniu.$data['file'];
// $a = file_get_contents($qiniu_url);
// $path = './uploads/'.explode('/',$base_url)[2].'/';
// if(!file_exists($path)) {
// mkdir($path,0777,true);
// }
// file_put_contents('.'.$base_url,$a);
// $data['file'] = request()->domain().$base_url;
// }else{
// $data['file'] = '';
// }
$file_list = Db::name('information_file')
->where('information_id',$id)
->field('file_name,file')
->select();
foreach ($file_list as &$v){
if(!empty($v['file'])){
$base_url = $v['file'];
$qiniu_url = cdnurl($v['file'],true);
$a = file_get_contents($qiniu_url);
$path = './uploads/'.explode('/',$base_url)[2].'/';
if(!file_exists($path)) {
mkdir($path,0777,true);
}
file_put_contents('.'.$base_url,$a);
$v['file'] = request()->domain().$base_url;
}else{
$v['file'] = '';
}
}
$data['file_list'] = $file_list;
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
$this->success('success',$data);
}
/**
* @ApiTitle (政策动态详情)
* @ApiSummary (政策动态详情)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/policy_info)
*
* @ApiParams (name="id", type="int", required=true, description="政策动态ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://ID
"title"://标题
"from"://转载于
"content"://内容详情
"file_name"://附件名称
"file"://附件
"is_up"://是否上架0否1是
"createtime"://创建时间
}
})
*/
public function policy_info()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('policy')
->where('id',$id)
->field('updatetime',true)
->find();
// if(!empty($data['file'])){
// $base_url = $data['file'];
// $qiniu_url = $qiniu.$data['file'];
// $a = file_get_contents($qiniu_url);
// $path = './uploads/'.explode('/',$base_url)[2].'/';
// if(!file_exists($path)) {
// mkdir($path,0777,true);
// }
// file_put_contents('.'.$base_url,$a);
// $data['file'] = request()->domain().$base_url;
// }else{
// $data['file'] = '';
// }
$file_list = Db::name('policy_file')
->where('policy_id',$id)
->field('file_name,file')
->select();
foreach ($file_list as &$v){
if(!empty($v['file'])){
$base_url = $v['file'];
$qiniu_url = cdnurl($v['file'],true);
$a = file_get_contents($qiniu_url);
$path = './uploads/'.explode('/',$base_url)[2].'/';
if(!file_exists($path)) {
mkdir($path,0777,true);
}
file_put_contents('.'.$base_url,$a);
$v['file'] = request()->domain().$base_url;
}else{
$v['file'] = '';
}
}
$data['file_list'] = $file_list;
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
$this->success('success',$data);
}
/**
* @ApiTitle (下载专区详情)
* @ApiSummary (下载专区详情)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/download_info)
*
* @ApiParams (name="id", type="int", required=true, description="下载专区ID")
*
* @ApiReturn({
"code": 1,
"msg": "success",
"time": "1611814489",
"data": {
"id"://ID
"title"://标题
"from": //转载于
"desc": //简介
"content": //内容详情
"is_up"://是否上架0否1是
"createtime"://创建时间
"file_list": [{ //附件
"file_name"://附件名称
"file"://附件地址
}]
}
})
*/
public function download_info()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('download')
->where('id',$id)
->field('updatetime',true)
->find();
$file_list = Db::name('download_file')
->where('download_id',$id)
->field('file_name,file')
->select();
foreach ($file_list as &$v){
if(!empty($v['file'])){
$base_url = $v['file'];
$qiniu_url = cdnurl($v['file'],true);
$a = file_get_contents($qiniu_url);
$path = './uploads/'.explode('/',$base_url)[2].'/';
if(!file_exists($path)) {
mkdir($path,0777,true);
}
file_put_contents('.'.$base_url,$a);
$v['file'] = request()->domain().$base_url;
}else{
$v['file'] = '';
}
}
$data['file_list'] = $file_list;
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
$this->success('success',$data);
}
/**
* @ApiTitle (优选课程列表)
* @ApiSummary (优选课程列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/video_list)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"title"://标题
"desc"://简介
"content"://内容详情
"image"://图片
"createtime"://创建时间
]
}
})
*/
public function video_list()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data['total_num'] = Db::name('optimization')
->count();
$data['info'] = Db::name('optimization')
->field('id,title,image,desc,createtime,video_file')
->order('createtime desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
// 获取视频时长
$video_avinfo = json_decode(file_get_contents(cdnurl($v['video_file'], true) . '?avinfo'), true); // 获取视频元信息
$duration = ceil($video_avinfo['format']['duration']);
$v['duration'] = gmdate('H:i:s',$duration);
$v['image'] = cdnurl($v['image'],true);
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (优选课程详情)
* @ApiSummary (优选课程详情)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/video_detail)
*
* @ApiParams (name="id", type="int", required=true, description="优选课程ID")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"id"://ID
"title"://标题
"desc"://简介
"content"://内容详情
"video_file"://视频信息
"image"://图片
"createtime"://创建时间
}
})
*/
public function video_detail()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('optimization')
->where('id',$id)
->find();
$data['image'] = cdnurl($data['image'],true);
$data['video_file'] = cdnurl($data['video_file'],true);
// 获取视频时长
$video_avinfo = json_decode(file_get_contents(cdnurl($data['video_file'], true) . '?avinfo'), true); // 获取视频元信息
$duration = ceil($video_avinfo['format']['duration']);
$data['duration'] = gmdate('H:i:s',$duration);
$data['createtime'] = date('Y-m-d H:i:s',$data['createtime']);
$this->success('success',$data);
}
/**
* @ApiTitle (我自己的学习列表)
* @ApiSummary (我自己的学习列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/study_list)
*
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"examname"://考试名称
"class_hour"://所需课时
"finish_hour"://完成课时
"image"://图片
"expirationtime"://截止日期
]
}
})
*/
public function study_list()
{
$erzi = Db::name('type')->field('id,pid')->select();
if(!empty($erzi)){
$erzi_id = array_column($erzi,"id");
$sunzi = Db::name('type')->where(['pid'=>['in',$erzi_id]])->field("id")->select();
$sunzi_id = array_column($sunzi,"id");
$son = array_merge($sunzi_id,$erzi_id);
$where['type_id'] = ['in',$son];
}
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
// $user_id = Session::get('user_id');
$user_id = $this->auth->id;
$where['expirationtime'] = ['>',time()];
$data['total_num'] = Db::name('study')
->where($where)
->count();
$data['info'] = Db::name('study')
->field('updatetime,createtime',true)
->where($where)
->order('id desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
if(empty($user_id)){
$v['finish_hour'] = 0;
}else{
$finish_hour = Db::name('study_class')
->alias('a')
->join('classes b','a.class_id = b.id')
->where('a.third_id',$user_id)
->where('a.study_id',$v['id'])
->where('a.status',2)
->field('sum(b.class_hour) as finsh_hour')
->find();
if(empty($finish_hour['finsh_hour'])){
$v['finish_hour'] = 0;
}else{
$v['finish_hour'] = $finish_hour['finsh_hour'];
}
}
$v['image'] = cdnurl($v['image'],true);
$v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (学习系统)
* @ApiSummary (学习系统)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/study)
*
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
* @ApiParams (name="type_id", type="inter", required=false, description="分类id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"examname"://考试名称
"class_hour"://所需课时
"finish_hour"://完成课时
"image"://图片
"expirationtime"://截止日期
]
}
})
*/
public function study()
{
$type_id = $this->request->param('type_id');
$erzi = Db::name('type')->where('id',$type_id)->field('id,pid')->select();
if(!empty($erzi)){
$erzi_id = array_column($erzi,"id");
$sunzi = Db::name('type')->where(['pid'=>['in',$erzi_id]])->field("id")->select();
$sunzi_id = array_column($sunzi,"id");
$son = array_merge($sunzi_id,$erzi_id);
array_push($son,$type_id);
$where['type_id'] = ['in',$son];
}else{
$where['type_id'] = ['eq',$type_id];
}
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 12, 'intval');
// $user_id = Session::get('user_id');
$user_id = $this->auth->id;
$where['expirationtime'] = ['>',time()];
$data['total_num'] = Db::name('study')
->where($where)
->count();
$data['info'] = Db::name('study')
->field('updatetime,createtime',true)
->where($where)
->order('id desc')
->page($page,$pageNum)
->select();
foreach ($data['info'] as &$v){
if(empty($user_id)){
$v['finish_hour'] = 0;
// 截止日期
$v['expirationtime'] = date('Y-m-d H:i:s',$v['expirationtime']);
}else{
$finish_hour = Db::name('study_class')
->alias('a')
->join('classes b','a.class_id = b.id')
->where('a.third_id',$user_id)
->where('a.study_id',$v['id'])
->where('a.status',2)
->field('sum(b.class_hour) as finsh_hour')
->find();
if(empty($finish_hour['finsh_hour'])){
$v['finish_hour'] = 0;
}else{
$v['finish_hour'] = $finish_hour['finsh_hour'];
}
// 截止日期
$third_study = Db::name('third_study')->where('third_id',$user_id)->where('study_id',$v['id'])->field('periodtime')->find();
$v['expirationtime'] = !empty($third_study) ? date('Y-m-d H:i:s',$third_study['periodtime']) : date('Y-m-d H:i:s',$v['expirationtime']);
}
$v['image'] = cdnurl($v['image'],true);
}
$this->success('success',$data);
}
/**
* @ApiTitle (查看用户是否有权限)
* @ApiSummary (查看用户是否有权限)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/study_detail)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
* @ApiParams (name="id", type="int", required=true, description="学习系统id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
}
})
*/
public function study_detail()
{
$user_id = $this->auth->id;
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$third_study = Db::name('third_study')->where('third_id',$user_id)->where('study_id',$id)->find();
if(empty($third_study)){
$this->error('您没有该场考试的权限');
}else{
$third_study['periodtime'] < time() && $this->error('学习期限已过');
$this->success('success');
}
}
/**
* @ApiTitle (账号密码登录)
* @ApiSummary (账号密码登录)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/password_login)
*
* @ApiParams (name="username", type="string", required=true, description="用户名")
* @ApiParams (name="password", type="string", required=true, description="密码")
* @ApiParams (name="type", type="inter", required=false, description="是否记住账号密码 为空或者1否2是")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
]
}
})
*/
public function password_login(){
$type = $this->request->param('type');
$username = $this->request->param('username');
$password = $this->request->param('password');
if(empty($username) || empty($password)){
$this->error('缺少必要参数');
}
$result = Db::name('user')->where('username',$username)->find();
if(empty($result)){
$this->error('账号错误');
}
if($result['password'] != $password){
$this->error('密码错误');
}
$user = Db::name('user')->where(['id'=>$result['id']])->find();
// if($user['expirationtime'] < time()){
// $this->error('抱歉,有效期已过');
// }
if(!empty($user['image'])){
$user['image'] = cdnurl($user['image'],true);
}else{
$user['image'] = '';
}
if(empty($user['nickname'])){
$user['nickname'] = '';
}
// 统计网站登录情况
$statistic = Db::name('statistic')->where('today',date('Y-m-d'))->find();
if($statistic){
$token = Db::name('user_token')->where('user_id',$user['id'])->whereTime('createtime','today')->find();
if(!$token){
Db::name('statistic')->where('id',$statistic['id'])->setInc('login_people');
}
Db::name('statistic')->where('id',$statistic['id'])->setInc('login_times');
}else{
Db::name('statistic')->insert([
'login_people' => 1,
'login_times' => 1,
'today' => date('Y-m-d')
]);
}
$auth = Auth::instance();
$this->auth->direct($user['id']);
$userInfo = $auth->getUserinfo();
$userInfo['image'] = $user['image'];
unset($userInfo['avatar']);
unset($userInfo['score']);
unset($userInfo['mobile']);
$this->success('登录成功',$userInfo);
}
/**
* @ApiTitle (找回密码)
* @ApiSummary (找回密码)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/find_pwd)
*
* @ApiParams (name="phone", type="string", required=true, description="手机号")
* @ApiParams (name="code", type="string", required=true, description="验证码")
* @ApiParams (name="new_password", type="string", required=true, description="新密码")
* @ApiParams (name="re_pwd", type="string", required=true, description="确认密码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
]
}
})
*/
public function find_pwd()
{
$phone = $this->request->param('phone');
$code = $this->request->param('code');
$new_password = $this->request->param('new_password');
$re_pwd = $this->request->param('re_pwd');
if(empty($phone) || empty($code) || empty($new_password) || empty($re_pwd)){
$this->error('缺少必要参数');
}
if($new_password != $re_pwd){
$this->error('两次密码不一致,请重新输入');
}
$result1 = Db::name('user')->where('mobile',$phone)->find();
if(empty($result1)){
$this->error('该手机号暂无绑定账号');
}
//验证手机号验证码是否正确
$yuancode = Cache::get($phone);
if($code != $yuancode){
$this->error('验证码错误或者失效,请重新发送');
}
$data = Db::name('user')->where('id',$result1['id'])->update(['password'=>$new_password]);
if(empty($data)){
$this->error('修改失败');
}else{
$this->success('success');
}
}
/**
* @ApiTitle (修改密码)
* @ApiSummary (修改密码)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/edit_pwd)
*
* @ApiHeaders (name=token, type=string, required=true, description="请求的Token")
*
* @ApiParams (name="pwd", type="string", required=true, description="密码")
* @ApiParams (name="new_password", type="string", required=true, description="新密码")
* @ApiParams (name="re_pwd", type="string", required=true, description="确认密码")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
]
}
})
*/
public function edit_pwd()
{
$user_id = $this->auth->id;
$username = $this->request->param('username');
$pwd = $this->request->param('pwd');
$new_password = $this->request->param('new_password');
$re_pwd = $this->request->param('re_pwd');
if(empty($username) || empty($pwd) || empty($new_password) || empty($re_pwd)){
$this->error('缺少必要参数');
}
$userinfo = Db::name('user')->where('id',$user_id)->find();
if($userinfo['password'] != $pwd){
$this->error('您的密码不正确');
}
if($new_password != $re_pwd){
$this->error('两次密码不一致');
}
$data = Db::name('user')->where('id',$user_id)->update(['password'=>$new_password]);
if(empty($data)){
$this->error('修改失败');
}else{
$this->success('修改成功');
}
}
/**
* @ApiTitle (获取验证码)
* @ApiSummary (获取验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/getcode)
*
* @ApiParams (name="mobile", type="string", required=false, description="手机号")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function getcode()
{
$phone = $this->request->param('mobile');
if (empty($phone)) {
$this->error(['code' => 40005, 'msg' => '手机号不能为空']);
}
if (!preg_match('/^1[0-9]{10}$/', $phone)) {
$this->error(['code' => 40005, 'msg' => "请输入正确的手机格式!"]);
}
//生成验证码
$number = generateCode();
//发送验证码
$data = array(
'content' => "【金建培训】提醒您,您的验证码是:" .$number.",十分钟之内有效,请勿向他人泄漏您的验证码",//短信内容
'mobile' => $phone,//手机号码
'productid' => '676767',//产品id
'xh' => ''//小号
);
$result = send_sms($data);
if (substr($result, 0, strpos($result, ',')) != "1") {
$this->error(['code' => 42001, 'msg' => $result]);
}
Cache::set($phone,$number,600);
$this->success('SUCCESS');
}
/**
* @ApiTitle (验证验证码)
* @ApiSummary (验证验证码)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/verify)
*
* @ApiParams (name="mobile", type="string", required=true, description="手机号")
* @ApiParams (name="code", type="string", required=true, description="验证码")
*
* @ApiReturn({
"code": 1,
"msg": "SUCCESS",
"time": "1553839125",
"data": {
}
})
*/
public function verify()
{
$param = $this->request->param();
$validate = new Validate([
'mobile' => 'require|max:11',
'code'=>'require'
]);
if (!$validate->check($param)) {
$this->error(['code'=>40005,'msg'=>$validate->getError()]);
}
$code = Cache::get($param['mobile']);
//暂不验证验证码
$this->success('SUCCESS');
if($param['code'] == $code){
$this->success('SUCCESS');
}else{
$this->error('验证码错误或者失效,请重新发送');
}
}
/**
* @ApiTitle (客服列表)
* @ApiSummary (客服列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/ke_list)
*
* @ApiParams (name="page", type="inter", required=false, description="当前页(默认1)")
* @ApiParams (name="pageNum", type="inter", required=false, description="每页显示数据个数(默认10)")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"phone2"://手机号2
"phone1"://手机号1
"image"://二维码
"createtime"://创建时间
]
}
})
*/
public function ke_list()
{
$page = $this->request->param('page', 1, 'intval');
$pageNum = $this->request->param('pageNum', 10, 'intval');
$data['total_num'] = Db::name('kelist')->count();
$data['info'] = Db::name('kelist')->order('id desc')->field('updatetime',true)->page($page,$pageNum)->select();
foreach ($data['info'] as &$v){
$v['image'] = cdnurl($v['image'],true);
$v['createtime'] = date('Y-m-d H:i:s',$v['createtime']);
}
$this->success('success',$data);
}
/**
* @ApiTitle (客服详情)
* @ApiSummary (客服详情)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/ke_list_detail)
*
* @ApiParams (name="id", type="inter", required=false, description="客服id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"total_num"://总条数
"info":[
"id"://ID
"phone2"://手机号2
"phone1"://手机号1
"image"://二维码
"createtime"://创建时间
]
}
})
*/
public function ke_list_detail()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('kelist')->where('id',$id)->find();
$data['image'] = cdnurl($data['image'],true);
$this->success('success',$data);
}
/**
* @ApiTitle (分类列表)
* @ApiSummary (分类列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/type_list)
*
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"one": [
{
"id": 1,
"name": "学习类型",
"pid": 0,
"level": 1,
"createtime": 1597834718,
"updatetime": 1597834718
}
],
"two": [
{
"id": 2,
"name": "理科类型",
"pid": 1,
"level": 2,
"createtime": 1597834738,
"updatetime": 1597834738
}
],
"three": [
{
"id": 3,
"name": "测试",
"pid": 2,
"level": 3,
"createtime": 1597835130,
"updatetime": 1597835130
}
]
}
})
*/
public function type_list()
{
$data = Db::name('type')->select();
$info['one'] = [];
$info['two'] = [];
$info['three'] = [];
foreach ($data as $k=>$v){
if($v['level'] == 1){
array_push($info['one'],$data[$k]);
}elseif ($v['level'] == 2){
array_push($info['two'],$data[$k]);
}else{
array_push($info['three'],$data[$k]);
}
}
$this->success('success',$info);
}
/**
* @ApiTitle (通过id获取分类列表)
* @ApiSummary (通过id获取分类列表)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/get_list)
*
* @ApiParams (name="id", type="inter", required=false, description="分类id")
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
}
})
*/
public function get_list()
{
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少必要参数');
}
$data = Db::name('type')->where('pid',$id)->select();
$this->success('success',$data);
}
/**
* @ApiTitle (获取分类标题)
* @ApiSummary (获取分类标题)
* @ApiMethod (POST)
* @ApiRoute (/api/lists/type_title)
*
* @ApiReturn({
"code": 1,
"msg": "成功",
"time": "1571492001",
"data": {
"title_one"://标题1
"title_two"://标题2
"title_three"://标题3
}
})
*/
public function type_title()
{
$data = Db::name('type_title')
->where('id',1)
->field('title_one,title_two,title_three')
->find();
$this->success('success',$data);
}
}