MemberCenterController.php
41.1 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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 15:35
*/
namespace api\index\controller;
use api\common\model\ActivityModel;
use api\common\model\TeamModel;
use api\index\model\AboutModel;
use api\index\model\ContactModel;
use api\index\model\JoinModel;
use api\index\model\VolunteerModel;
use api\index\model\UserModel;
use cmf\controller\RestBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
use think\Validate;
/**
* @title 个人中心
* @description 个人中心
*/
class MemberCenterController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$userModel = new UserModel();
$user = $userModel->where(array('id'=>$user_id))->find();
if($user['user_status'] == 0){
$this->error(['code'=>40005,'msg'=>'您已被列入黑名单,请联系管理员!']);
}
}
/**
* @title 个人中心
* @description 个人中心
* @author XiaoGang Wang
* @url /index/member_center/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return level:用户星级
* @return work_time:工作时长
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return status:志愿类型
* @return is_submit:0为未提交过,1为已提交过
* @return activity_num:活动数量
* @return group_num:团队数量
*/
public function index(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
// dump($result->toArray());
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if(empty($result)){
$is_submit = 0;
}else {
$user['avatar']=cmf_get_image_url($result['photo']);
$user['user_nickname']=$result['name'];
$is_submit = 1;
}
$Volunteer=new \api\common\model\VolunteerModel();
$user_info=$Volunteer->getUserInfo($user_id);
if (empty($result['level'])){
$result['level']=0;
}
if (empty($result['work_time'])){
$result['work_time']=0;
}
$Join=new JoinModel();
$user_join=$Join->getUserJoin($user_id);
$Team=new TeamModel();
$Team->joinTeamList($user_id);
$user_team=$Team->joinTeamList($user_id);
if(empty($user_join)){
$user['activity_num']=0;
}else{
$user['activity_num']=count($user_join);
}
if (empty($user_team)){
$user['group_num']=0;
}else{
$user['group_num']=count($user_team);
}
$user['status']=$user_info['status'];
$user['level']=$result['level'];
$user['work_time']=$result['work_time'];
$user['study_time']=$result['study_time'];
$user['is_submit'] = $is_submit;
$user['area'] = $user_info['area'];
$user['nickname'] = $user_info['nickname'];
$this->success('获取成功!',$user);
}
/**
* @title 判断是否为管理员是否提交过申请
* @description 判断是否为管理员是否提交过申请
* @author XiaoGang Wang
* @url /index/member_center/is_submit_admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return is_submit:0为未提交过,1为已提交过
*/
public function is_submit_admin(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
if(empty($result)){
$is_submit = 0;
}else{
$is_submit = 1;
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$is_admin = 0;
}else{
$is_admin = 1;
}
$data['is_submit'] = $is_submit;
$data['is_admin'] = $is_admin;
$this->success('获取成功!',$data);
}
/**
* @title 提交审核
* @description 提交审核
* @author XiaoGang Wang
* @url /index/member_center/submit_form
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:form_id type:str require:1 other: desc:表单id
* @param name:name type:str require:1 other: desc:姓名
* @param name:sex type:str require:1 other: desc:性别(1男,2女)
* @param name:birthday type:str require:1 other: desc:生日
* @param name:nation type:str require:1 other: desc:民族
* @param name:politics type:str require:1 other: desc:政治面貌
* @param name:education type:str require:1 other: desc:学历
* @param name:unit type:str require:1 other: desc:工作单位
* @param name:duty type:str require:1 other: desc:职务
* @param name:addr type:str require:1 other: desc:通讯地址
* @param name:postcode type:str require:1 other: desc:邮编
* @param name:school type:str require:1 other: desc:毕业院校
* @param name:card_number type:str require:1 other: desc:身份证号码
* @param name:fixed_phone type:str require:1 other: desc:固定电话
* @param name:move_phone type:str require:1 other: desc:移动电话
* @param name:email type:str require:1 other: desc:email
* @param name:urgency_phone type:str require:1 other: desc:紧急联系人电话
* @param name:qq type:str require:1 other: desc:qq
* @param name:province type:str require:1 other: desc:省
* @param name:city type:str require:1 other: desc:市
* @param name:county type:str require:1 other: desc:区/县
* @param name:address type:str require:1 other: desc:详细地址
* @param name:type type:int require:1 other: desc:1医院志愿者,2社会志愿者,3办事处志愿者
* @param name:record_start_time type:str require:1 other: desc:开始时间
* @param name:record_end_time type:str require:1 other: desc:结束时间
* @param name:record_unit type:str require:1 other: desc:单位
* @param name:record_duty type:str require:1 other: desc:职务
* @param name:record_name type:str require:1 other: desc:证明人
* @param name:record_phone type:str require:1 other: desc:证明人电话
* @param name:front_card type:str require:1 other: desc:身份证正面照
* @param name:reverse_card type:str require:1 other: desc:身份证背面照
* @param name:photo type:str require:1 other: desc:照片
* @param name:nickname type:str require:1 other: desc:昵称
*/
public function submit_form(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'name' => 'require',
'sex' => 'require',
'birthday' => 'require',
'nation' => 'require',
'politics' => 'require',
'education' => 'require',
'unit' => 'require',
'duty' => 'require',
'addr' => 'require',
'postcode' => 'require',
'school' => 'require',
'card_number' => 'require',
// 'fixed_phone' => 'require',
'move_phone' => 'require',
'email' => 'require',
'urgency_phone' => 'require',
'qq' => 'require',
// 'province' => 'require',
// 'city' => 'require',
// 'county' => 'require',
'address' => 'require',
'record_start_time' => 'require',
'record_end_time' => 'require',
'record_unit' => 'require',
'record_duty' => 'require',
'record_name' => 'require',
'record_phone' => 'require',
'front_card' => 'require',
'reverse_card' => 'require',
'photo' => 'require',
'nickname' => 'require',
]);
$validate->message([
'name' => '缺少参数name',
'sex' => '缺少参数sex',
'birthday' => '缺少参数birthday',
'nation' => '缺少参数nation',
'politics' => '缺少参数politics',
'education' => '缺少参数education',
'unit' => '缺少参数unit',
'duty' => '缺少参数duty',
'addr' => '缺少参数addr',
'postcode' => '缺少参数postcode',
'school' => '缺少参数school',
'card_number' => '缺少参数card_number',
// 'fixed_phone' => '缺少参数fixed_phone',
'move_phone' => '缺少参数move_phone',
'email' => '缺少参数email',
'urgency_phone' => '缺少参数urgency_phone',
'qq' => '缺少参数qq',
// 'province' => '缺少参数province',
// 'city' => '缺少参数city',
// 'county' => '缺少参数county',
'address' => '缺少参数address',
'record_start_time' => '缺少参数record_start_time',
'record_end_time' => '缺少参数record_end_time',
'record_unit' => '缺少参数record_unit',
'record_duty' => '缺少参数record_duty',
'record_name' => '缺少参数record_name',
'record_phone' => '缺少参数record_phone',
'front_card' => '缺少参数front_card',
'reverse_card' => '缺少参数reverse_card',
'photo' => '缺少参数photo',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$record_start_time = explode(',',$param['record_start_time']);
$record_end_time = explode(',',$param['record_end_time']);
$record_unit = explode(',',$param['record_unit']);
$record_duty = explode(',',$param['record_duty']);
$record_name = explode(',',$param['record_name']);
$record_phone = explode(',',$param['record_phone']);
$record = [];
foreach($record_start_time as $key => $r_s_t){
$record[$key]['record_start_time'] = !empty($r_s_t) ? $r_s_t : '';
$record[$key]['record_end_time'] = !empty($record_end_time[$key]) ? $record_end_time[$key] : '';
$record[$key]['record_unit'] = !empty($record_unit[$key]) ? $record_unit[$key] :'';
$record[$key]['record_duty'] = !empty($record_duty[$key]) ? $record_duty[$key] :'';
$record[$key]['record_name'] = !empty($record_name[$key]) ? $record_name[$key] :'';
$record[$key]['record_phone'] = !empty($record_phone[$key]) ? $record_phone[$key] :'';
}
if(!empty($record)){
$record = json_encode($record);
}else{
$record = null;
}
$data = [
'name' => $param['name'],
'sex' => $param['sex'],
'birthday' => $param['birthday'],
'nation' => $param['nation'],
'politics' => $param['politics'],
'education' => $param['education'],
'unit' => $param['unit'],
'duty' => $param['duty'],
'addr' => $param['addr'],
'postcode' => $param['postcode'],
'school' => $param['school'],
'card_number' => $param['card_number'],
'fixed_phone' => $param['fixed_phone'],
'move_phone' => $param['move_phone'],
'email' => $param['email'],
'urgency_phone' => $param['urgency_phone'],
'qq' => $param['qq'],
'province' => $param['province'],
'city' => $param['city'],
'county' => !empty($param['county'])?$param['county']:null,
'address' => $param['address'],
/* 'type' => $param['type'],*/
'record' => $record,
'front_card' => $param['front_card'],
'reverse_card' => $param['reverse_card'],
'photo' => $param['photo'],
'status' => 1,
'user_id' => $user_id,
'nickname' => $param['nickname'],
];
$form_id=input('form_id');
if (!empty($form_id)){
$this->saveFormId($user_id,$form_id);
}
$volunteerModel = new VolunteerModel();
$result1 = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
//判断该用户是否提交过
if(!empty($result1)){
$data['update_time'] = time();
$volunteerModel->updateData(array('id'=>$result1['id']),$data);
}else{
$data['create_time'] = time();
$volunteerModel->insertData($data);
}
$this->success('提交成功!');
}
/**
* @title 进入修改页面
* @description 进入修改页面
* @author XiaoGang Wang
* @url /index/member_center/edit
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return name:姓名
* @return sex:性别(1男,2女)
* @return birthday:生日
* @return nation:民族
* @return politics:政治面貌
* @return education:学历
* @return unit:工作单位
* @return duty:职务
* @return addr:通讯地址
* @return postcode:邮编
* @return school: desc:毕业院校
* @return card_number :身份证号码
* @return fixed_phone:固定电话
* @return move_phone:移动电话
* @return email:email
* @return urgency_phone:紧急联系人电话
* @return qq:qq
* @return province:省
* @return city:市
* @return county:区/县
* @return address:详细地址
* @return type:1医院志愿者,2社会志愿者,3办事处志愿者
* @return record_start_time:开始时间
* @return record_end_time:结束时间
* @return record_unit:单位
* @return record_duty:职务
* @return record_name:证明人
* @return record_phone:证明人电话
* @return front_card type:str require:1 other: desc:身份证正面照
* @return reverse_card:身份证背面照
* @return photo:照片
* @return status:状态(1审核中,2审核成功,3审核失败)
*/
public function edit(){
// $user_id = $this->getUserId();
$user_id = $this->request->param('id');
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
$result['photo']=cmf_get_image_url($result['photo']);
$result['front_card']=cmf_get_image_url($result['front_card']);
$result['reverse_card']=cmf_get_image_url($result['reverse_card']);
$this->success('获取成功!',$result);
}
/**
* @title 查看审核状态
* @description 查看审核状态
* @author XiaoGang Wang
* @url /index/member_center/status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return status:状态(1审核中,2审核成功,3审核失败)
*/
public function status(){
$user_id = $this->getUserId();
$volunteerModel = new VolunteerModel();
$data = $volunteerModel->findData(array('user_id'=>$user_id));
if(empty($data)){
$this->success(['code'=>40001,'msg'=>'您还没有提交过申请!']);
}
$this->success('获取成功!',$data);
}
/**
* @title 管理员审核
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*/
public function admin(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'1'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 工时管理列表(new)
* @description
* @author XiaoGang Wang
* @url /index/member_center/addTimeList
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*
*/
public function addTimeList(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'2'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 管理员添加时间(new)
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/addTime
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:join_id type:int require:0 other: desc:参加id
*
*/
public function addTime(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['id']=input('join_id');
$time=input('add_time');
$user_id1=input('user_id');
if (empty($user_id1)){
$join=\db('join')->where($map)->find();
if (empty($join)){
$this->error('参数错误');
}
$joinUpdate['work_time']=$time;
\db('join')->where($map)->update($joinUpdate);
if ($time>$join['work_time']){
$add_time=$time-$join['work_time'];
$volunteerUpdate['work_time']=$add_time;
\db('volunteer')->where('user_id',$join['user_id'])->setInc('work_time',$add_time);
}else{
$add_time=$join['work_time']-$time;
\db('volunteer')->where('user_id',$join['user_id'])->setDec('work_time',$add_time);
}
}else{
\db('volunteer')->where('user_id',$user_id1)->setInc('work_time',$time);
}
$result=1;
/* // $data['add_time']=['exp','work_time'+$time];
$result=db('volunteer')->where($map)->setInc('work_time',$time);
// echo db('volunteer')->getLastSql();*/
if ($result>0){
$this->success('修改成功!');
}else{
$this->error('此人不是审核通过的志愿者!');
}
}
/**
* @title 管理员查看活动申请详情
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/adminGetApplyInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:join_id type:int require:0 other: desc:报名id
*
*/
public function adminGetApplyInfo(){
$map['id']=input('join_id');
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
/*获取*/
if (!empty($return['time'])){
$return['time']= array_reverse($return['time']);
}
$info=db('join')->field('card_number,sgin_time,id,type,user_id,activity_id,select_time,apply_stay,apply_food,work_content')->where($map)->find();
$user=db('volunteer')->field('card_number,sex,name,birthday,move_phone')->where('user_id',$info['user_id'])->find();
if (!empty($user)){
$return['name']=$user['name'];
$return['birthday']=$user['birthday'];
$return['sex']=$user['sex']==1?'男':'女';
$return['tel']=$user['move_phone'];
}
if (!empty($info)){
$return['work_content']=db('work')->where('id',$info['work_content'])->value('name');
$return['work_content']=$info['work_content'];
$return['select_time']=json_decode($info['select_time'],true);
$return['apply_stay']=json_decode($info['apply_stay'],true);
$return['apply_food']=json_decode($info['apply_food'],true);
$return['id']=$info['id'];
$return['work_type']=$info['type'];
$return['card_number']=$user['card_number'];
$return['is_complete']=$info['sgin_time']==0?'0':'1';
/* switch ($info['type']){
case 1:
$return['work_type']='线上';
break;
case 2:
$return['work_type']='线下';
break;
case 3:
$return['work_type']='线上及线下';
break;
}*/
}
$this->success('',$return);
}
/**
* @title 管理员更新状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/update_status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:志愿者id
* @param name:status type:int require:1 other: desc:状态(点击审核通过传2,点击审核失败传3)
* @param name:refund_reason type:int require:1 other: desc:审核不通过原因
*/
public function update_status(){
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少参数id');
}
$data['refund_reason']=input('refund_reason')??'';
$status = $this->request->param('status');
if(empty($status)){
$this->error('缺少参数status');
}
if($status != 2 && $status != 3){
$this->error('status参数错误!');
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//获取志愿者
$volunteerModel = new VolunteerModel();
$data['status']=input('status');
if ($data['status']==2){
$keyword='审核通过';
}else{
$keyword="审核未通过 原因:$data[refund_reason]";
}
$result = $volunteerModel->updateData(array('id'=>$id),$data);
if(empty($result)){
$this->success(['code'=>40002,'msg'=>'当前申请可能已被其他管理员审核,请刷新页面!']);
}
$volunteer=db('volunteer')->where('id',$id)->find();
$userMap['user_id']=$volunteer['user_id'];
$openid=db('third_party_user')->where($userMap)->value('openid');
$formMap['user_id']=$volunteer['user_id'];
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
$now=time();
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>$now]);
if (!empty($form_id)){
$data['keyword1']= $volunteer['name'];
$data['keyword2']='志愿者审核';
$data['keyword3']=$keyword;
$data['keyword4']='志愿者审核';
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3']='状态',
];
$this->wxappNotice($message);
}
$this->success(['code'=>20000,'msg'=>'更新成功!']);
}
/**
* @title 获取人员参与状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/getJoinPerson
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return photo:摄影(设备自带)
* @return camera:摄像(设备自带)
* @return motorcade:爱心车队
* @return service:现场服务(签到、指引、礼仪等)
* @return question:线上答疑
* @return ill:门诊服务
* @return name:status0,未审核1,已通过2,未通过3,已填写工作汇报(已通过)
*/
public function getJoinPerson(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//活动id
$id=input('id');
$map['activity_id']=$id;
$map['j.delete_time']=0;
/* $info=db('join')->alias('j')
->group('j.user_id')
->field('v.*,j.*,j.id as join_id,j.status as status')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->order('j.id','asc')
->select()
->toArray();*/
/* $subQuery = db('join')->alias('j')
->field('j.user_id,v.name,v.photo,j.id as join_id,j.status as status,j.delete_time,j.activity_id,j.work_content')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->order('j.id','desc')
->buildSql();
dump($subQuery);
$info= Db::table($subQuery.'a')
->group('a.user_id')
->select()
->toArray();*/
$new_map=[];
$subQuery = db('join')->alias('j')
->field('max(j.id)')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->group('j.user_id')
->select()
->toArray();
if (!empty($subQuery)){
foreach ($subQuery as $k=>$v){
$new_map[]=$v["max(j.id)"];
}
}
$map1['j.id']=['in',implode(',',$new_map)];
$info=db('join')->alias('j')
->group('j.user_id')
->field('v.*,j.*,j.id as join_id,j.status as status')
->join('volunteer v','v.user_id=j.user_id')
->where($map1)
->order('j.id','asc')
->select()
->toArray();
/*$info=db('join_view')
->group('user_id')
->where($map)
->select()
->toArray();*/
// echo db('join')->getLastSql();
$return=[];
$i0=0;
$i1=0;
$i2=0;
$i3=0;
$i4=0;
$i5=0;
foreach($info as $k=>$v){
switch ($v['work_content']){
case 1:
$return[0]['title']='摄影(设备自带)';
$return[0]['arr'][$i0]['id']=$v['join_id'];
$return[0]['arr'][$i0]['photo']=$v['photo'];
$return[0]['arr'][$i0]['name']=$v['name'];
$return[0]['arr'][$i0]['user_id']=$v['user_id'];
$return[0]['arr'][$i0]['status']=$this->switchStatus($v['status']);
$i0++;
break;
case 2:
$return[1]['title']='摄像(设备自带)';
$return[1]['arr'][$i1]['id']=$v['join_id'];
$return[1]['arr'][$i1]['photo']=$v['photo'];
$return[1]['arr'][$i1]['name']=$v['name'];
$return[1]['arr'][$i1]['user_id']=$v['user_id'];
$return[1]['arr'][$i1]['status']=$this->switchStatus($v['status']);
$i1++;
break;
case 3:
$return[2]['title']='爱心车队';
$return[2]['arr'][$i2]['id']=$v['join_id'];
$return[2]['arr'][$i2]['photo']=$v['photo'];
$return[2]['arr'][$i2]['name']=$v['name'];
$return[2]['arr'][$i2]['user_id']=$v['user_id'];
$return[2]['arr'][$i2]['status']=$this->switchStatus($v['status']);
$i2++;
break;
case 4:
$return[3]['title']='现场服务(签到、指引、礼仪等)';
$return[3]['arr'][$i3]['id']=$v['join_id'];
$return[3]['arr'][$i3]['photo']=$v['photo'];
$return[3]['arr'][$i3]['name']=$v['name'];
$return[3]['arr'][$i3]['user_id']=$v['user_id'];
$return[3]['arr'][$i3]['status']=$this->switchStatus($v['status']);
$i3++;
break;
case 5:
$return[4]['title']='线上答疑';
$return[4]['arr'][$i4]['id']=$v['join_id'];
$return[4]['arr'][$i4]['photo']=$v['photo'];
$return[4]['arr'][$i4]['name']=$v['name'];
$return[4]['arr'][$i4]['user_id']=$v['user_id'];
$return[4]['arr'][$i4]['status']=$this->switchStatus($v['status']);
$i4++;
break;
case 6:
$return[5]['title']='门诊服务';
/*判断是否有user_id*/
$return[5]['arr'][$i5]['id']=$v['join_id'];
$return[5]['arr'][$i5]['photo']=$v['photo'];
$return[5]['arr'][$i5]['name']=$v['name'];
$return[5]['arr'][$i5]['user_id']=$v['user_id'];
$return[5]['arr'][$i5]['status']=$this->switchStatus($v['status']);
$i5++;
break;
}
}
foreach ($return as $k=>$v){
foreach($return[$k] as $k1=>$v1){
}
}
$this->success('',$return);
}
/**
* @title 管理员审核活动申请是否通过(new)
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/adminApprove
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:参加id
* @param name:status type:int require:1 other: desc:1通过2.拒绝
* @param name:refund_reason type:int require:1 other: desc:拒绝理由
*
*
*/
public function adminApprove(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['id']=input('id');
$data['status']=input('status');
$refund_reason=input('refund_reason');
if (!empty($refund_reason)){
$data['refund_reason']=input('refund_reason');
}
$result=db('join')->where($map)->update($data);
if ($result>0){
$join=\db('join')->where($map)->find();
$activity=\db('activity')->where('id',$join['activity_id'])->find();
$userMap['user_id']=$join['user_id'];
$openid=db('third_party_user')->where($userMap)->value('openid');
$volunteer=\db('volunteer')->where('user_id',$join['user_id'])->find();
$formMap['user_id']=$join['user_id'];
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
$now=time();
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>$now]);
if ($data['status']==1){
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$date=date('Y-m-d H:i');
$data=[
'phrase1' => ['value' =>"$volunteer[name]审核通过"], //审核结果
'thing2'=>['value'=>$activity['activity_name']], //活动名称
'thing4'=>['value'=>'通过'], //备注
'date7'=>['value'=>$date] //审核时间
];
$Info=sendSubMessage($data,$openid);
}
}else{
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$date=date('Y-m-d H:i');
$data=[
'phrase1' => ['value' =>"$volunteer[name]审核通过"], //审核结果
'thing2'=>['value'=>$activity['activity_name']], //活动名称
'thing4'=>['value'=>'通过'], //备注
'date7'=>['value'=>$date] //审核时间
];
$Info=sendSubMessage($data,$openid);
}
}
$this->success('更新成功!');
}else{
$this->error('操作失败!');
}
}
protected function wxappNotice($message){
$appId = 'wx7a3bf4e0796c070a';
$secret = '755478f064e09a8301345e0c427c6cf3';
$config = [
'app_id' => $appId,
'secret' => $secret,
];
$wechat=new Application($config);
$notice=$wechat->mini_program->notice;
try{
$result= $notice->send($message);
}catch(Exception $e){
// $e->getMessage();
}
return $result;
}
protected function switchStatus($status){
switch ($status){
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
}
}
/**
* @title 关于我们
* @description 关于我们
* @author XiaoGang Wang
* @url /index/member_center/about
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function about(){
$aboutModel = new AboutModel();
$data = $aboutModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 联系我们
* @description 联系我们
* @author XiaoGang Wang
* @url /index/member_center/contact
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function contact(){
$contactModel = new ContactModel();
$data = $contactModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 我参加的活动
* @description 参加过的活动
* @author XiaoGang Wang
* @url /index/member_center/joined
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function joined(){
$userId=$this->getUserId();
$Join=new JoinModel();
$join=$Join->getUserJoin($userId);
foreach ($join as $k=>$v){
$join[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
$join[$k]['create_time']=date('Y-m-d',$v['create_time']);
}
$this->success('',$join);
}
protected function saveFormId($userId,$formId){
if ($formId=='undefined'){
return;
}
$data['user_id']=$userId;
$data['add_time']=time();
$data['value']=$formId;
$data['expire_time']=time()+604800;
db('form_id')->insert($data);
}
/**
* @title 编辑用户昵称
* @description 编辑用户昵称
* @author XiaoGang Wang
* @url /index/member_center/editUserNickname
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function editUserNickname(){
$name=input('name');
if (empty($name)){
$this->error('编辑失败');
}
$userId=$this->getUserId();
$Volunteer=new VolunteerModel();
$update['nickname']=$name;
$result=$Volunteer->where('user_id',$userId)->update($update);
if (empty($result)){
$this->error('编辑失败');
}else{
$this->success('编辑成功');
}
}
}