SecondController.php
44.8 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
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/9/26
* Time: 14:46
*/
namespace api\index\controller;
use api\common\model\ActivityModel;
use api\common\model\ActivityNews;
use api\common\model\AddressModel;
use api\common\model\ClassModel;
use api\common\model\ClassQuestionModel;
use api\common\model\ClockModel;
use api\common\model\GoodsModel;
use api\common\model\LevelModel;
use api\common\model\NewsTypeMode;
use api\common\model\OrderModel;
use api\common\model\TeamModel;
use api\common\model\UserPassModel;
use api\common\model\UserWorkLog;
use api\common\model\VolunteerModel;
use api\index\model\JoinModel;
use api\index\model\ManageModel;
use api\index\model\UserModel;
use cmf\controller\RestBaseController;
use FontLib\Table\Type\name;
use think\console\output\formatter\Style;
use think\Image;
use think\Validate;
/**
* @title 志愿者二开接口
* @description 志愿者二开接口
*/
class SecondController extends RestBaseController
{
/**
* @title 获取排行
* @description 获取排行
* @author SGJ
* @url /index/second/getRank
* @method POST
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:type type:int require:1 other: desc:类型1,志愿者2,团队
* @param name:star type:int require:1 other: desc:类型6,金牌1,一星2,二星
*
* @return list:志愿者@
* @list rank:排名 name:姓名 province:省市 work_time:工作时间
*/
public function getRank(){
$type=input('type');
if ($type==1){
$star=input('star');
$userModel=new VolunteerModel();
$list=$userModel->getListByLevel($star);
$return=[];
foreach ($list as $k=>$v){
$return[$k]['user_id']=$v['user_id'];
$return[$k]['name']=$v['name'];
$return[$k]['province']=$v['province'];
$return[$k]['work_time']=$v['work_time'];
}
}else{
$teamModel=new TeamModel();
$list=$teamModel->getTeamList('work_total_time desc','');
if(!empty($list)){
foreach ($list as $k=>$v){
$return[$k]['team_id']=$v['id'];
$return[$k]['name']=$v['name'];
$return[$k]['work_time']=$v['work_total_time'];
}
}else{
$this->success('');
}
}
$this->success('',$return);
}
/**
* @title 志愿动态栏目类型
* @description 志愿动态栏目类型
* @author sgj
* @url /index/second/getNewsType
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
*
* @return id:栏目id
* @return name:名称
* @throws
*/
public function getNewsType(){
$newType=new NewsTypeMode();
$list=$newType->getNewsType();
foreach ($list as $k=>$v){
$return[$k]['id']=$v['id'];
$return[$k]['name']=$v['type_name'];
}
$this->success('',$return);
}
/**
* @title 获取志愿动态列表
* @description 获取志愿动态列表
* @author sgj
* @url /index/second/getNewsList
* @method GET
*
* @param name:type_id type:int require:1 other: desc:类型id
* @param name:page type:int require:1 other: desc:页数
*
* @return id:栏目type_id
* @return name:名称
* @return create_time:创建时间
* @return thumbnail:封面图
* @throws
*/
public function getNewsList(){
$type_id=input('type_id',1);
$news=new ActivityNews();
$map['activity_type']=$type_id;
$map['delete_time']=0;
$list=$news
->where($map)
->field('id,activity_name,thumbnail,create_time')
->order('weight desc')
->paginate(10,true);
// $data=$list->item();
foreach ($list as $k=>$v) {
$list[$k]['create_time']=date('Y-m-d',$v['create_time']);
$list[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
}
$this->success('',$list);
}
/**
* @title 获取志愿动态详情
* @description 获取志愿动态详情
* @author sgj
* @url /index/second/getNewsInfo
* @method GET
*
* @param name:id type:int require:1 other: desc:文章id
*
* @return id:文章id
* @return activity_name:文章名称
* @return abstract:简介
* @return thumbnail:头图
* @return content:内容
* @return create_time:发布时间
* @return author:作者
* @throws
*/
public function getNewsInfo(){
$news_id=input('id');
$news= new ActivityNews();
$info=$news->getInfo($news_id);
$this->success('',$info);
}
/**
* @title 在线培训列表
* @description 在线培训列表
* @author sgj
* @url /index/second/tranOnlineList
* @method GET
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @return id:文章id
* @return pic:图片
* @return num:题目数量
* @return author:作者
* @return content:内容
* @return user_status:用户状态0,未完成1,已完成
* @return author:作者
*
* @throws
*/
public function tranOnlineList(){
$userId=$this->getUserId();
$map1['user_id']=$userId;
$pass_array=db('user_pass')->where($map1)->column('class_id');
if (empty($pass_array)){
$pass_array=[];
}
$Class=new ClassModel();
$map['status']=1;
$list=$Class->where($map)->order('weight desc')->paginate('10');
$data=$list->items();
foreach ($data as $k=>$v) {
if (in_array($v['id'],$pass_array)){
$data[$k]['user_status']=1;
}else{
$data[$k]['user_status']=0;
}
$data[$k]['pic']=cmf_get_image_url($v['pic']);
}
$this->success('',$list);
}
/**
* @title 我的培训列表(new)
* @description 我的培训列表
* @author sgj
* @url /index/second/myTrain
* @method GET
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @return id:文章id
* @return pic:图片
* @return num:题目数量
* @return author:作者
* @return content:内容
* @return user_status:用户状态0,未完成1,已完成
* @return author:作者
*
* @throws
*/
public function myTrain(){
$userId=$this->getUserId();
$map1['user_id']=$userId;
$pass_array=db('user_pass')->where($map1)->column('class_id');
if (empty($pass_array)){
$pass_array=[];
}
$Class=new ClassModel();
$map['status']=1;
$list=$Class->where($map)->order('weight desc')->paginate('10');
$data=$list->items();
foreach ($data as $k=>$v) {
if (in_array($v['id'],$pass_array)){
$data[$k]['user_status']=1;
}else{
$data[$k]['user_status']=0;
}
$data[$k]['pic']=cmf_get_image_url($v['pic']);
}
$this->success('',$list);
}
/**
* @title 检查志愿者状态
* @description 检查志愿者状态
* @author sgj
* @url /index/second/checkTranStatus
* @method GET
*
*@header name:XX-Token require:1 default: desc:token
*
* @throws
*/
public function checkTranStatus(){
$userId=$this->getUserId();
if (!$this->isVolunteer($userId)){
$this->error('申请成为志愿者后才能答题');
}else{
$this->success();
}
}
/**
* @title 获取班级详情信息
* @description 获取班级详情信息
* @author sgj
* @url /index/second/getClassInfo
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:id type:int require:1 other: desc:课程id
*@return user_status:0,未答题1,已答过
*
* @throws
*/
public function getClassInfo(){
$userId=$this->getUserId();
$id=input('id');
if (!$this->isVolunteer($userId)){
$this->error('申请成为志愿者后才能答题');
}
$Class=new ClassModel();
$map['id']=$id;
$classInfo=$Class->where($map)->find();
$classInfo['pic']=cmf_get_image_url($classInfo['pic']);
$classInfo['content']= cmf_replace_content_file_url(htmlspecialchars_decode($classInfo['content']));
$map1['class_id']=$id;
$map1['user_id'] =$userId;
$is_set=db('user_pass')->where($map1)->find();
if ($is_set){
$classInfo['user_status']='1';
}else{
$classInfo['user_status']='0';
}
$this->success('',$classInfo);
}
/**
* @title 获取班级问题
* @description 获取班级详情信息
* @author sgj
* @url /index/second/getClassQuestion
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:class_id type:int require:1 other: desc:课程id
*
*
* @throws
*/
public function getClassQuestion(){
$class_id=input('class_id');
$ClassQuesion=new ClassQuestionModel();
$question=$ClassQuesion->getClassQuesion($class_id);
$this->success('',$question);
}
/**
* @title 提交答案
* @description 提交答案
* @author sgj
* @url /index/second/commitAnswer
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:class_id type:int require:1 other: desc:课程id
*@param name:answer_info type:int require:1 other: desc:回答详情{"1":"0","2":"1","id"=>'答案索引'}
*
*
* @throws
*/
public function commitAnswer(){
$user_id=$this->getUserId();
$class_id=input('class_id');
$answer_info=input('answer_info');
$answer_info1= htmlspecialchars_decode($answer_info);
$answer_array=json_decode($answer_info1,true);
$ClassQuesion=new ClassQuestionModel();
$class=db('class')->where('id',$class_id)->find();
$question=$ClassQuesion->getClassQuesion($class_id);
foreach ($question as $k=>$v){
$answer[$v['id']]=$v['answer'];
}
if (!empty($answer_array)){
foreach ($answer_array as $k=>$v){
if ($answer[$k]==$v){
unset($answer[$k]);
}
}
}
if (empty($answer)){
/*添加信息*/
/*添加用户时长*/
$volunteer=new VolunteerModel();
$volunteer->where('user_id',$user_id)->setInc('work_time',$class['work_time']);
$volunteer->addWorkTime($user_id,$class['work_time']);
$volunteer->addStudyTime($user_id,$class['work_time']);
/*添加到完成*/
$UserPassModel=new UserPassModel();
$UserPassModel->pass($user_id,$class_id);
$return['time']=$class['work_time'];
$this->success('回答成功',$return);
}else{
$info['answer']=$ClassQuesion->getClassQuesion($class_id);
$this->error('问题回答错误',$info);
}
}
/**
* @title 团队列表
* @description 团队列表
* @author sgj
* @url /index/second/teamList
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:city type:int require:1 other: desc:城市名称
*
* @throws
*/
public function teamList(){
$city=input('city');
if(!empty($city)){
$map['city']=$city;
}
$Team=new TeamModel();
$map['status']=2;
$team=$Team->where($map)->order('weight desc')->select()->toArray();
if (!empty($team)){
/*foreach ($team as $k=>$v) {
$return['id']=$v['id'];
$return['city']=$v['city'];
$return['name']=$v['name'];
$return['create_time']=date('Y-m-d',$v['create_time']);
$return['work_total_time']=$v['work_total_time'];
$return['people_num']=$v['people_num'];
$return['pic']=cmf_get_image_url($v['pic']);
}*/
foreach ($team as $k=>$v){
$team[$k]['create_time']=date('Y-m-d',$v['create_time']);
}
}else{
$this->error('暂无数据');
}
$this->success('',$team);
}
/**
* @title 团队详情
* @description 团队详情
* @author sgj
* @url /index/second/teamInfo
* @method GET
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:id type:int require:1 other: desc:团队id
* @return name:团队名称
* @return work_total_time:累计工作时间
* @return city:所在城市
* @return people_num:人数
* @return content:内容
* @return user_status:用户状态0,未审核1,审核通过-1,审核不通过3,未申请
* @return author:作者
* @throws
*/
public function teamInfo(){
$userId=$this->getUserId();
$id=input('id');
$Team=new TeamModel();
$info= $Team->getTeamInfo($id);
$map['user_id']=$userId;
$map['team_id']=$id;
$apply_info=db('team_apply')->where($map)->order('id','DESC')->find();
if (empty($apply_info)){
$info['user_status']=3;
}else{
$info['user_status']=$apply_info['status'];
}
$map1['a.status']=1;
$map1['a.team_id']=$id;
$join=db('team_apply')->alias('a')
->field('v.name,v.photo')
->where($map1)
->join('volunteer v','a.user_id=v.user_id')
->select()->toArray();
if (!empty($join)){
foreach ($join as $k=>$v){
// $info['join'][$k]['photo']=cmf_get_image_url($v['photo']);
$join[$k]['photo']=cmf_get_image_url($v['photo']);
}
}
$info['join']=$join;
$this->success('',$info);
}
/**
* @title 申请加入团队
* @description 申请加入团队
* @author sgj
* @url /index/second/applyTeam
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
*@param name:team_id type:int require:1 other: desc:团队id
*@param name:wx_id type:int require:1 other: desc:微信号
*@param name:mobile type:int require:1 other: desc:手机号
*@param name:join_reason type:int require:1 other: desc:加入原因
* @throws
*/
public function applyTeam(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'wx_id' => 'require',
'team_id' => 'require',
'mobile' => 'require',
'join_reason' => 'require',
]);
$validate->message([
'wx_id' => '微信号不能为空',
'team_id' =>'团队id不能为空',
'mobile' => '手机号不能为空',
'join_reason' => '加入原因不能为空',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$param['create_time']=time();
$param['user_id']=$user_id;
$result=db('team_apply')->insert($param);
if ($result>0){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 我的团队
* @description 我的团队
* @author sgj
* @url /index/second/myTeam
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
* @return name:团队名称
* @return pic:图片
* @return my_time:我的时间
* @return work_total_time:总时长
* @return people_num:人数
* @return city:城市
* @throws
*/
public function myTeam(){
$user_id = $this->getUserId();
/*查询到已经申请的团队*/
$map['ta.status']=1;
$map['ta.user_id']=$user_id;
$Team= new TeamModel();
$info=db('team_apply')->alias('ta')
->field('t.*')
->join('team t','t.id=ta.team_id')
->where($map)->select();
foreach ($info as $k=>$v) {
$return[$k]['pic']=cmf_get_image_url($v['pic']);
$return[$k]['name']=$v['name'];
$return[$k]['id']=$v['id'];
$return[$k]['city']=$v['city'];
$return[$k]['people_num']=$v['people_num'];
$return[$k]['work_total_time']=$v['work_total_time'];
$return[$k]['my_time']=$Team->myTime($user_id,$v['id']);
}
if (!empty($return)){
$this->success('',$return);
}else{
$this->error('暂无信息' );
}
}
//
// private function myTime($user_id,$team_id){
// $map['user_id']=$user_id;
// $map['team_id']=$team_id;
// $time=db('team_work_log')->where($map)->sum('work_time');
// return $time;
// }
/**
* @title 志愿反馈
* @description 志愿反馈
* @author sgj
* @url /index/second/feedback
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
* @return user:用户信息@
* @user avatar:头像 name:姓名 level:星级 work_time:总工时 use_time:消耗工时 level_time:剩余工时 status:状态
*
* @throws
*/
public function feedBack(){
$userId=$this->getUserId();
$userModel=new VolunteerModel();
$return['user']=$userModel->getUserInfo($userId);
$this->success('',$return);
}
/**
* @title 商品列表
* @description 商品列表
* @author sgj
* @url /index/second/goodsList
* @method POST
*
*
*@param name:page type:int require:1 other: desc:页数
*
*@header name:XX-Token require:1 default: desc:token
*
* @return data:商品信息@
* @data id pic:缩略图 work_time:消耗工时 good_name:名称 real_good:是否为实物 seal_num:销售量 num:库存量
*
* @throws
*/
public function goodsList(){
$goodModel=new GoodsModel();
$map['is_online']=1;
$map['delete_time']=null;
$goods=$goodModel->where($map)->order('id desc')->paginate(10,true);
$list=$goods->items();
foreach ($list as $k=>$v){
$list[$k]['pic']=cmf_get_image_url($v['pic']);
$list[$k]['content']='';
}
$this->success('',$goods);
}
/**
* @title 商品详情
* @description 商品详情
* @author sgj
* @url /index/second/goodInfo
* @method POST
*
*
*@param name:id type:int require:1 other: desc:商品id
*
*@header name:XX-Token require:1 default: desc:token
*
* @return data:商品信息@
* @data content:内容详情 pic:缩略图 work_time:消耗工时 good_name:名称 real_good:是否为实物 seal_num:销售量 num:库存量
*
* @throws
*/
public function goodInfo(){
$id=input('id');
$goodModel=new GoodsModel();
$goodInfo=$goodModel->getGoods($id);
if (empty($goodInfo)){
$this->error('没有找到相应商品');
}
$this->success('',$goodInfo);
}
/**
* @title 地址列表
* @description 地址列表
* @author sgj
* @url /index/second/addressList
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*
* @return data:地址列表@
* @data name:姓名 province:省 city:市 district:区 address:地址 tel:电话 is_default:是否默认地址
*
* @throws
*/
public function addressList(){
$userId=$this->getUserId();
$Address=new AddressModel();
$map['user_id']=$userId;
$list=$Address->where($map)->select();
$this->success('',$list);
}
/**
* @title 添加地址
* @description 添加地址
* @author sgj
* @url /index/second/addAddress
* @method POST
*
*
*@param name:name type:int require:1 other: desc:姓名
*@param name:province type:int require:1 other: desc:省
*@param name:city type:int require:1 other: desc:市
*@param name:district type:int require:1 other: desc:区
*@param name:address type:int require:1 other: desc:地址
*@param name:is_default type:int require:1 other: desc:是否为默认地址1,是0,否
*@param name:tel type:int require:1 other: desc:电话
*@param name:wx_id type:int require:1 other: desc:微信号
*@param name:mail type:int require:1 other: desc:邮箱
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function addAddress(){
$userId=$this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'name' => 'require',
'tel' => 'require',
'province' => 'require',
'city' => 'require',
'district' => 'require',
'address' => 'require',
]);
$validate->message([
'name' => '姓名不能为空',
'tel' => '电话不能为空',
'province' => '省市区不能为空',
'city' => '省市区不能为空',
'district' => '省市区不能为空',
'address' => '省市区不能为空',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$Address=new AddressModel();
if ($param['is_default']==1){
$Address->setDefaultBefore($userId);
}
$param['user_id']=$userId;
$result=$Address->insert($param);
if ($result>0){
$this->success('添加成功');
}else{
$this->error('添加失败');
}
}
/**
* @title 删除地址
* @description 删除地址
* @author sgj
* @url /index/second/deleteAddress
* @method POST
*
*
*@param name:address_id type:int require:1 other: desc:地址id
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function deleteAddress(){
$userId=$this->getUserId();
$id=input('address_id');
$AddressModel=new AddressModel();
$info=$AddressModel->where('id',$id)->where('user_id',$userId)->delete();
$this->success('操作成功');
}
/**
* @title 设置默认地址
* @description 设置默认地址
* @author sgj
* @url /index/second/defaultAddress
* @method POST
*
*
*@param name:address_id type:int require:1 other: desc:地址id
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function setDefault(){
$id=input('id');
$Address=new AddressModel();
$update['is_default']=1;
$result=$Address->where('id',$id)->update($update);
if ($result==1){
$this->success('操作成功');
}else{
$this->error('操作失败');
}
}
/**
* @title 获取单一地址
* @description 获取单一地址
* @author sgj
* @url /index/second/getAddress
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*@param name:address_id type:int require:1 other: desc:地址id
*
* @return data:地址列表@
* @data name:姓名 province:省 city:市 district:区 address:地址 tel:电话 is_default:是否默认地址
*
* @throws
*/
public function getAddress(){
$id=input('id');
$Address=new AddressModel();
$return=$Address->where('id',$id)->find();
$this->success('',$return);
}
/**
* @title 获取默认地址
* @description 获取默认地址
* @author sgj
* @url /index/second/getDefaultAddress
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*@param name:address_id type:int require:1 other: desc:地址id
*
* @return data:地址列表@
* @data name:姓名 province:省 city:市 district:区 address:地址 tel:电话 is_default:是否默认地址
*
* @throws
*/
public function getDefaultAddress(){
$userId=$this->getUserId();
$map['user_id']=$userId;
$map['is_default']=1;
$Address=new AddressModel();
$address=$Address->where($map)->find();
$this->success('',$address);
}
/**
* @title 修改地址
* @description 修改地址
* @author sgj
* @url /index/second/editAddress
* @method POST
*
*
*@param name:id type:int require:1 other: desc:id
*@param name:name type:int require:1 other: desc:姓名
*@param name:province type:int require:1 other: desc:省
*@param name:city type:int require:1 other: desc:市
*@param name:district type:int require:1 other: desc:区
*@param name:address type:int require:1 other: desc:地址
*@param name:is_default type:int require:1 other: desc:是否为默认地址1,是0,否
*@param name:tel type:int require:1 other: desc:电话
*@param name:wx_id type:int require:1 other: desc:微信号
*@param name:mail type:int require:1 other: desc:邮箱
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function editAddress(){
$id=input('id');
$userId=$this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'id'=>'require',
'name' => 'require',
'tel' => 'require',
'province' => 'require',
'city' => 'require',
'district' => 'require',
'address' => 'require',
]);
$validate->message([
'id'=>'id不能为空',
'name' => '姓名不能为空',
'tel' => '电话不能为空',
'province' => '省市区不能为空',
'city' => '省市区不能为空',
'district' => '省市区不能为空',
'address' => '省市区不能为空',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$Address=new AddressModel();
if ($param['is_default']==1){
$Address->setDefaultBefore($userId);
}
$param['user_id']=$userId;
$result=$Address->where('id',$id)->update($param);
if ($result>0){
$this->success('修改成功');
}else{
$this->error('修改失败');
}
}
/**
* @title 提交订单
* @description 提交订单
* @author sgj
* @url /index/second/commitOrder
* @method POST
*
*
*@param name:good_id type:int require:1 other: desc:商品id
*@param name:num type:int require:1 other: desc:数量
*@param name:address_id type:int require:1 other: desc:地址id
*@param name:remark type:string require:0 other: desc:备注
*
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function commitOrder(){
$userId=$this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'address_id'=>'require',
'num'=>'require',
'good_id'=>'require',
]);
$validate->message([
'address_id'=>'地址id不能为空',
'num'=>'数量不能为空',
'good_id'=>'商品id不能为空',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$goodModel=new GoodsModel();
$good=$goodModel->where('id',$param['good_id'])->find();
if (empty($good)||$good['is_online']!=1){
$this->error('商品错误');
}
if ($good['num']<$param['num']){
$this->error('商品库存不足');
}
/*检查是否有足够工时*/
$Volunter=new VolunteerModel();
$user=$Volunter->where('user_id',$userId)->find();
$user_time=$user['work_time']-$user['use_time'];
$good_time=$good['work_time']*$param['num'];
if ($user_time<$good_time){
$this->error('用户工时不足');
}
/*扣除库存和添加销量*/
$goodModel->where('id',$param['good_id'])->setInc('seal_num',$param['num']);
$goodModel->where('id',$param['good_id'])->setDec('num',$param['num']);
/*开始扣除*/
$Volunter->where('user_id',$userId)->setInc('use_time',$good_time);
$Log= new UserWorkLog();
$Log->addLog($userId,1,$good_time);
/*生成订单*/
$Order=new OrderModel();
$remark=$this->request->param('remark');
$order_sn=$Order->setOrder($userId,$param['good_id'],$param['num'],$param['address_id'],$remark);
$return['order_sn']=$order_sn;
$return['datetime']=date('Y-m-d H:i');
$this->success('下单成功',$return);
}
/**
* @title 获取证件照信息(new)
* @description 获取证件照信息(new)
* @author sgj
* @url /index/second/zhengJianInfo
* @method POST
*
* @return avatar:头像信息
* @return name:姓名
* @return status:状态
* @return user_num:编号
* @return work_time:工作时长
*
*@header name:XX-Token require:1 default: desc:token
*
* @throws
*/
public function zhengJianInfo(){
$userId=$this->getUserId();
$User=new VolunteerModel();
$info=$User->getUserInfo($userId);
$this->success('',$info);
}
/**
* @title 生成电子证件
* @description 生成电子证件
* @author sgj
* @url /index/second/zhengJianPic
* @method POST
*
*
*@header name:XX-Token require:1 default: desc:token
*@param name:type type:int require:1 other: desc:1正面2背面
*
* @throws
*/
public function zhengJianPic(){
$userId=$this->getUserId();
$type=input('type');
if ($type==1){
$User=new VolunteerModel();
$user=$User->where('user_id',$userId)->find()->toArray();
//dump($user);
$userInfo=$User->getUserInfo($userId);
$path='../upload/zhengjian/';
$info['photo']=explode('/upload',$user['photo']);
$path1=ROOT_PATH.'public/imgs/font.png';
$path2=ROOT_PATH.'public/upload'.DS.$info['photo'][1];
$image1 =\think\Image::open($path1);
$image2 =\think\Image::open($path2)
->thumb('225',310,\think\Image::THUMB_CENTER)->save(ROOT_PATH.'public/upload/user/'.$userId.'.png');
$photo='';
$photo_local[]=430;
$photo_local[]=62;
$font='../static/font-awesome/fonts/PingFang Medium.ttf';
$text1='姓名 '.$userInfo['name'];
$text2='身份 '.$userInfo['status'];
$text3='编号 '.$userInfo['serial'];
$text4='当前学时 '.$userInfo['work_time'].'小时';
$locate1[]='35';
$locate1[]='100';
$locate2[]='35';
$locate2[]='165';
$locate3[]='35';
$locate3[]='235';
$locate4[]='35';
$locate4[]='300';
$image1
->water(ROOT_PATH.'public/upload/user/'.$userId.'.png',$photo_local)
->text($text1,$font,20,'#FFFFFF',$locate1)
->text($text2,$font,20,'#FFFFFF',$locate2)
->text($text3,$font,20,'#FFFFFF',$locate3)
->text($text4,$font,20,'#FFFFFF',$locate4)
->save($path.$userId.'.png');
//$image2->thumb(430,62);
$return['url']=cmf_get_image_url('/upload/zhengjian/'.$userId.'.png');
$this->success('',$return);
}else{
$return['url']=cmf_get_image_url('/imgs/back.png');
$this->success('',$return);
}
}
/**
* @title 他人主页
* @description 他人主页
* @author sgj
* @url /index/second/otherHome
* @method POST
*
*
*
*@header name:XX-Token require:1 default: desc:token
*@param name:user_id type:int require:1 other: desc:用户id
*
* @throws
*/
public function otherHome(){
$user_id=input('user_id');
$volunteer=new VolunteerModel();
$Join=new JoinModel();
$return['userInfo']=$volunteer->getUserInfo($user_id);
$Activity=new ActivityModel();
$return['userJoin']=$Join->getUserJoin($user_id);
$Team=new TeamModel();
$return['team']=$Team->joinTeamList($user_id);
$this->success('',$return);
}
/**
* @title 订单列表
* @description 订单列表
* @author sgj
* @url /index/second/orderList
* @method POST
*
*
*@param name:type type:int require:1 other: desc:类型-1,已拒绝0,待审核1,已发放
*@header name:XX-Token require:1 default: desc:token
*
*
* @throws
*/
public function orderList(){
$userId=$this->getUserId();
$map['o.user_id']=$userId;
$map['o.status']=input('type');
if($map['o.status']==2){
$map['o.status']='-1';
}
$Order=new OrderModel();
$data=$Order->alias('o')->field('g.pic,g.good_name,o.*')->join('goods g','g.id=o.good_id')
->where($map)
->order('id','DESC')
->paginate('10',true);
$list=$data->items();
if (!empty($list)){
foreach ($list as $k=>$v){
$list[$k]['pic']=cmf_get_image_url($v['pic']);
}
}
$this->success('',$data);
}
/**
* @title 订单详情
* @description 订单详情
* @author sgj
* @url /index/second/orderInfo
* @method POST
*
*
*@param name:id type:int require:1 other: desc:订单id
*@header name:XX-Token require:1 default: desc:token
*
*@return order_sn:订单号
*@return content_info:虚拟订单信息
*@return remark:备注信息
*@return reason:拒绝原因
*@return content_info:虚拟订单信息
*@return is_real:是否为虚拟订单
*@return expend:消耗工时
*@return good:商品信息
*
*@throws
*/
public function orderInfo(){
$userId=$this->getUserId();
$id=input('id');
$Order=new OrderModel();
$order=$Order->orderInfo($id);
$this->success('',$order);
}
/**
* @title 活动列表
* @description 活动列表
* @author sgj
* @url /index/second/activityList
* @method POST
*
*
*@param name:status type:int require:1 other: desc:1,进行中2,已完成
*@header name:XX-Token require:1 default: desc:token
*
*@return activity_name:活动名称
*@return date:日期
*@return start_clock_time:开始时间
*@return end_clock_time:结束时间
*@return activity.thumbnail:缩略图
*
*@throws
*/
public function activityList(){
$type=input('type',1);
if ($type==1){
$map['status']=['in','0,1'];
}else{
$map['status']=2;
}
$userId=$this->getUserId();
$Clock=new ClockModel();
$map['user_id']=$userId;
$info=$Clock->where($map)->with(['activity'])->select();
$this->success('',$info);
}
/**
* @title 待提交报告或已完成活动(new)
* @description 待提交报告
* @author sgj
* @url /index/second/commitList
* @method POST
*
*@header name:XX-Token require:1 default: desc:token
*@param name:status type:int require:1 other: desc:1,待提交报告2,已完成
*
*@throws
*/
public function commitList(){
$user_id=$this->getUserId();
$map['user_id']=$user_id;
$map['status']=input('status');
$list=db('join')->where($map)->column('activity_id');
if(empty($list)){
$this->success('');
}
$activity_id=implode(',',$list);
$Clock=new ActivityModel();
$map1['id']=['in',$activity_id];
$info=$Clock->where($map1)->select();
foreach ($info as $k=>$v){
$info[$k]['start_time']=date('Y-m-d',$v['start_time']);
$info[$k]['end_time']=date('Y-m-d',$v['end_time']);
$info[$k]['work_time']=db('join')->where(['activity_id'=>$v['id'],'user_id'=>$user_id])->value('work_time');
}
$this->success('',$info);
}
/**
* @title 开始打卡
* @description 开始打卡
* @author sgj
* @url /index/second/startClock
* @method POST
*
*
*@param name:id type:int require:1 other: desc:活动id
*@param name:long type:int require:1 other: desc:经度
*@param name:lat type:int require:1 other: desc:纬度
*@header name:XX-Token require:1 default: desc:token
*
*
*@throws
*/
public function startClock(){
$data=input();
$activityModel=new ClockModel();
$activity=$activityModel->where('id',$data['id'])->find();
/*检查时间*/
$date=date('Y-m-d');
if ($date!=$activity['date']){
$this->error('当前日期无法打卡');
}
$config=cmf_get_option('site_info');
$adminStartTime=strtotime("$date $activity[start_clock_time]");
$now=time();
if (($adminStartTime-$config['before_start_time']*60)>$now || ($adminStartTime+$config['after_start_time']*60)<$now){
$this->error('当前时间无法打卡');
}
/*检查地点*/
$distance=getDistance($activity['lat'],$activity['long'],$data['lat'],$data['long']);
if ($distance*1000>$config['distance']){
$this->error('不在打卡范围内');
}
$update['status']=1;
$update['user_start']=time();
$result=db('clock')->where('id',$data['id'])->update(['user_start'=>$now,'status'=>'1']);
$this->success('打卡成功!');
}
/**
* @title 结束打卡
* @description 结束打卡
* @author sgj
* @url /index/second/endClock
* @method POST
*
*@header name:XX-Token require:1 default: desc:token
*@param name:id type:int require:1 other: desc:订单id
*@param name:lat type:int require:1 other: desc:纬度
*@param name:long type:int require:1 other: desc:经度
*@header name:XX-Token require:1 default: desc:token
*
*
*@throws
*/
public function endClock(){
$data=input();
$user_id=$this->getUserId();
$activityModel=new ClockModel();
$activity=$activityModel->where('id',$data['id'])->find();
/*检查时间*/
$date=date('Y-m-d');
if ($date!=$activity['date']){
$this->error('当前日期无法打卡');
}
$config=cmf_get_option('site_info');
$adminEndTime=strtotime("$date $activity[end_clock_time]");
$now=time();
if (($adminEndTime-$config['before_end_time']*60)>$now || ($adminEndTime+$config['after_end_time']*60)<$now){
$this->error('当前时间无法打卡');
}
/*检查地点*/
$distance=getDistance($activity['lat'],$activity['long'],$data['lat'],$data['long']);
if ($distance*1000>$config['distance']){
$this->error('不在打卡范围内');
}
$update['status']=2;
$update['user_end']=time();
$result=db('clock')->where('id',$data['id'])->update(['user_end'=>$now,'status'=>'2']);
if ($result==1){
/*添加对应工时*/
$info=db('clock')->where('id',$data['id'])->find();
$user=new VolunteerModel();
$user->where('user_id',$user_id)->setInc('work_time',$info['work_time']);
}
$this->success('打卡成功!');
}
/**
* @title 打卡详情
* @description 打卡详情
* @author sgj
* @url /index/second/clockInfo
* @method POST
*
*
*@param name:id type:int require:1 other: desc:id
*@header name:XX-Token require:1 default: desc:token
*
*@return activity_name:活动名称
*@return address:地址
*@return status:状态状态0,未打卡1,已开始2,完成打开3,未完成
*@return address:地址
*@return start_clock_time:后台设定开始时间
*@return end_clock_time:后台设定结束时间
*
*@throws
*/
public function clockInfo(){
$id=input('id');
$Clock=new ClockModel();
$info=$Clock->where('id',$id)->with(['Activity'])->find();
$config=cmf_get_option('site_info');
if (empty($config['distinct'])){
$config['distinct']=500;
}
$info['distance']=$config['distinct'];
if (!empty($info['user_start'])){
$info['start_status']='已打卡';
}else{
$info['start_status']='未打卡';
}
if (!empty($info['user_end'])){
$info['end_status']='已打卡';
}else{
$info['end_status']='未打卡';
}
$this->success('',$info);
}
/**
* @title 管理条例
* @description 管理条例
* @author sgj
* @url /index/second/manage
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function manage(){
$aboutModel = new ManageModel();
$data = $aboutModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 用户状态
* @description 管理条例
* @author sgj
* @url /index/second/getMyStatus
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
* @return code:状态值-1,审核不通过0,待提交信息1,审核中
*
*@throws
*
*/
public function getMyStatus(){
$user_id=$this->getUserId();
$map['user_id']=$user_id;
$Volunteer=new VolunteerModel();
$info=$Volunteer->getUserStatus($user_id);
$this->success('',$info);
}
/**
* @title 获取地址位置
* @description 获取地址位置
* @author sgj
* @url /index/second/getAddressInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
* @return code:状态值-1,审核不通过0,待提交信息1,审核中
* @param name:lat type:int require:1 other: desc:纬度
* @param name:lng type:int require:1 other: desc:经度
*@throws
*
*/
public function getAddressInfo(){
$lat=input('lat');
$lng=input('lng');
$key='Y4PBZ-MBQ3Q-XSV5A-GWLXE-HXV4E-JNB3P';
$url='https://apis.map.qq.com/ws/geocoder/v1/?location='.$lat.','.$lng.'&key='.$key;
$info=file_get_contents($url);
$result=json_decode($info,true);
if ($result['status']==0){
$return['address']=$result['result']['address'];
// return $result['result']['address'];
} else{
$return['address']='';
}
$this->success('',$return);
}
/**
* @title 获取用户状态
* @description 获取用户状态
* @author sgj
* @url /index/second/getUserStatus
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
* @return code:0,未提交1,审核中2,志愿者(待学习)3.志愿者(待实习)4.正式志愿者
*@throws
*
*/
public function getUserStatus(){
$userId=$this->getUserId();
$Volunteer=new VolunteerModel();
$result=$Volunteer->getUserStatus($userId);
$this->success('',$result);
}
/**
* @title 更改打卡状态(crontab)
* @description 更改打卡状态
* @author sgj
* @url /index/second/changeClockMission
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
* @return code:0,未提交1,审核中2,志愿者(待学习)3.志愿者(待实习)4.正式志愿者
*@throws
*
*/
public function changeClockMission(){
$yesterday=date("Y-m-d", strtotime("-1 day"));
// dump($yesterday);
$map['date']=['<=',$yesterday];
$map['status']=['in','0,1'];
$update['status']=3;
$result=db('clock')->where($map)->update($update);
$this->success('操作完成');
}
public function test(){
$openId='o-_vH5TbLrdztwa7nzj5Ocei-hdY';
$data=[
'phrase1' => ['value' =>$missoin->mission_name], //审核结果
'thing2'=>['value'=>$missoin->start_times], //活动名称
'thing4'=>['value'=>$address], //备注
'date7'=>['value'=>$address] //审核时间
];
$Info=sendSubMessage($data,$openId);
dump($Info);
}
}