VolunteerController.php
18.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
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/6/25
* Time: 11:43
*/
namespace app\admin\controller;
use app\admin\model\Excel;
use cmf\controller\AdminBaseController;
use think\Validate;
use think\Db;
use EasyWeChat\Foundation\Application;
use think\Image;
class VolunteerController extends AdminBaseController
{
public function index()
{
$where = [];
$where1 = [];
$param = $this->request->param();
if(!isset($param['stage'])){
$this->redirect('index',['stage'=>0]);
}
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime) && !empty($endTime)) {
$where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['create_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['create_time'] = ['<= time', $endTime];
}
}
$category = empty($param['category']) ? '' : $param['category'];
if (!empty($category)) {
$where['status'] = ['eq', "$category"];
}
if (!empty($param['stage'])|| $param['stage']==0){
switch ($param['stage']){
case 0:
$where['status']=['in','0,1,3'];
$order='id desc';
break;
case 1:
$where['status']=2;
$where['stage']=1;
$order='work_time desc';
$order='id desc';
break;
case 2:
$where['status']=2;
$where['stage']=2;
$order='work_time desc';
$order='id desc';
break;
case 3:
$where['status']=2;
$where['stage']=3;
$order='work_time desc';
$order='id desc';
break;
}
}
$type = empty($param['type']) ? '' : $param['type'];
if (!empty($type)) {
$where['type'] = ['eq', "$type"];
}
$sex = empty($param['sex']) ? '' : $param['sex'];
if (!empty($sex)) {
$where['sex'] = ['eq', "$sex"];
}
$level = empty($param['level']) ? '' : $param['level'];
if (!empty($level)) {
$level_map['level'] = ['eq', "$level"];
$level=\db('level')->where('level',$level)->find();
$where['work_time']=['>=',$level['min']];
$where1['work_time']=['<',$level['max']];
}
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['name|province|city|county|email|move_phone|fixed_phone|card_number|school|postcode|nation|politics|sex|urgency_phone|qq'] = ['like', "%$keyword%"];
}
$addr = empty($param['addr']) ? '' : $param['addr'];
if (!empty($addr)) {
$where['addr'] = ['like', "%$addr%"];
}
$list = Db::name('volunteer')
->where('delete_time', 0)
->where($where)
->where($where1)
->order($order)
->paginate(10);
$list->appends($param);
$data=$list->items();
$year=date('Y');
foreach ($data as $k=>$v){
$data[$k]['age']=$year-date('Y',strtotime($v['birthday']));
$data[$k]['level']=get_level($v['work_time']);
}
$this->assign([
'data' => $data,
'page' => $list ->render(),
]);
$this->assign('start_time', isset($param['start_time']) ? $param['start_time'] : '');
$this->assign('end_time', isset($param['end_time']) ? $param['end_time'] : '');
$this->assign('keyword', isset($param['keyword']) ? $param['keyword'] : '');
$this->assign('addr', isset($param['addr']) ? $param['addr'] : '');
$this->assign('category', isset($param['category']) ? $param['category'] : '');
$this->assign('type', isset($param['type']) ? $param['type'] : '');
$this->assign('sex', isset($param['sex']) ? $param['sex'] : '');
$this->assign('level', isset($param['level']) ? $param['level'] : '');
return $this->fetch();
}
//编辑
public function edit()
{
$id = $this->request->param('id', 0, 'intval');
$volunteer_org=\db('volunteer')->where('id',$id)->find();
if ($this->request->isPost()) {
$param = $this->request->param();
$record=input('record/a');
$param['record']=json_encode($record,true);
/*更新级别*/
$level_map['min'] = ['<=', $param['work_time']];
$level_map['max'] = ['>', $param['work_time']];
$level = db('level')->where($level_map)->value('level');
$param['level'] = $level;
$result= Db::name('volunteer')
->where('id', $id)
->update($param);
/*发送模板消息进行通知*/
if ($result>0 && $volunteer_org['status']!=$param['status']){
$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();
if (!empty($form_id)&& $param['status']!=1){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$data['keyword1']= $volunteer['name'];
$data['keyword2']='志愿者审核';
if ($param['status']==2){
$data['keyword3']='通过';
}
if ($param['status']==3){
$data['keyword3']='未通过 原因:'.$param['refund_reason'];
}
$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('操作成功!');
$this->success('更新成功!');
} else {
$data = Db::name('volunteer')
->where('id', $id)
->find();
$this->assign([
'data' => $data,
]);
return $this->fetch();
}
}
/**
* 模板消息发送
* @param $message
* @return \EasyWeChat\Support\Collection
* @throws \EasyWeChat\Core\Exceptions\InvalidArgumentException
*/
protected function wxappNotice($message){
$appId = 'wx7a3bf4e0796c070a';
$secret = '755478f064e09a8301345e0c427c6cf3';
$config = [
'app_id' => $appId,
'secret' => $secret,
];
$wechat=new Application($config);
$notice=$wechat->mini_program->notice;
$result= $notice->send($message);
return $result;
try{
$wechat=new Application($config);
$notice=$wechat->mini_program->notice;
$result= $notice->send($message);
}catch(Exception $e){
$e->getMessage();
}
return $result;
}
//删除
public function delete()
{
$param = $this->request->param();
if (isset($param['id'])) {
$id = $this->request->param('id', 0, 'intval');
$resultPortal = Db::name('volunteer')
->where(['id' => $id])
->delete();
if ($resultPortal) {
$this->success("删除成功!", '');
} else {
$this->error("删除失败!", '');
}
}
if (isset($param['ids'])) {
$ids = $this->request->param('ids/a');
$result = Db::name('volunteer')
->where(['id' => ['in', $ids]])
->delete();
if ($result) {
$this->success("删除成功!", '');
} else {
$this->error("删除失败!", '');
}
}
}
//发布
public function publish()
{
$param = $this->request->param();
$ids = $this->request->param('ids/a');
if (!empty($ids) && !empty($param['yes'])) {
Db::name('volunteer')->where(['id' => ['in', $ids]])->update(array('status' => 2));
$this->success('操作成功!', '');
} else {
Db::name('volunteer')->where(['id' => ['in', $ids]])->update(array('status' => 3));
$this->success('操作成功!', '');
}
}
public function excels()
{
// $where = [];
// $param = $this->request->param();
// $startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
// $endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
// if (!empty($startTime) && !empty($endTime)) {
// $where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
// } else {
// if (!empty($startTime)) {
// $where['create_time'] = ['>= time', $startTime];
// }
// if (!empty($endTime)) {
// $where['create_time'] = ['<= time', $endTime];
// }
// }
// $category = empty($param['category']) ? '' : $param['category'];
// if (!empty($category)) {
// $where['status'] = ['eq', "$category"];
// }
// $type = empty($param['type']) ? '' : $param['type'];
// if (!empty($type)) {
// $where['type'] = ['eq', "$type"];
// }
// $keyword = empty($param['keyword']) ? '' : $param['keyword'];
// if (!empty($keyword)) {
// $where['name|province|city|county|email|move_phone|fixed_phone|card_number|school|postcode|nation|politics|sex|urgency_phone|qq'] = ['like', "%$keyword%"];
// }
$where = [];
$where1 = [];
$param = $this->request->param();
$startTime = empty($param['start_time']) ? 0 : strtotime($param['start_time']);
$endTime = empty($param['end_time']) ? 0 : strtotime($param['end_time']);
if (!empty($startTime) && !empty($endTime)) {
$where['create_time'] = [['>= time', $startTime], ['<= time', $endTime]];
} else {
if (!empty($startTime)) {
$where['create_time'] = ['>= time', $startTime];
}
if (!empty($endTime)) {
$where['create_time'] = ['<= time', $endTime];
}
}
$category = empty($param['category']) ? '' : $param['category'];
if (!empty($category)) {
$where['status'] = ['eq', "$category"];
}
$type = empty($param['type']) ? '' : $param['type'];
if (!empty($type)) {
$where['type'] = ['eq', "$type"];
}
$sex = empty($param['sex']) ? '' : $param['sex'];
if (!empty($sex)) {
$where['sex'] = ['eq', "$sex"];
}
$level = empty($param['level']) ? '' : $param['level'];
if (!empty($level)) {
$level_map['level'] = ['eq', "$level"];
$level=\db('level')->where('level',$level)->find();
$where['work_time']=['>=',$level['min']];
$where1['work_time']=['<',$level['max']];
}
$keyword = empty($param['keyword']) ? '' : $param['keyword'];
if (!empty($keyword)) {
$where['name|province|city|county|email|move_phone|fixed_phone|card_number|school|postcode|nation|politics|sex|urgency_phone|qq'] = ['like', "%$keyword%"];
}
$addr = empty($param['addr']) ? '' : $param['addr'];
if (!empty($addr)) {
$where['addr'] = ['like', "%$addr%"];
}
$data = Db::name('volunteer')
->where('delete_time', 0)
->where($where)
->where($where1)
->order('create_time asc')
->select()->toArray();
foreach ($data as $k => $v) {
switch ($v['sex']) {
case 1:
$data[$k]['sex'] = '男';
break;
case 2:
$data[$k]['sex'] = '女';
break;
default:
$data[$k]['sex'] = '保密';
}
$data[$k]['card_number'] = '`' . $v['card_number'];
$data[$k]['level'] = get_level_text($v['work_time']);
}
$title = [
['ID', 15, 'id', 1],
['姓名', 15, 'name', 1],
['性别', 15, 'sex', 1],
['生日', 15, 'birthday', 1],
['民族', 15, 'nation', 1],
['政治面貌', 15, 'politics', 1],
['学历', 15, 'education', 1],
['工作单位', 15, 'unit', 1],
['职务', 15, 'duty', 1],
['通讯地址', 15, 'addr', 1],
['邮编', 15, 'postcode', 1],
['毕业院校', 15, 'school', 1],
['身份证号', 25, 'card_number', 1],
['固定电话', 15, 'fixed_phone', 1],
['移动电话', 15, 'move_phone', 1],
['邮箱', 15, 'email', 1],
['紧急联系人电话', 15, 'urgency_phone', 1],
['qq号', 15, 'qq', 1],
['省', 15, 'province', 1],
['市', 15, 'city', 1],
['区县', 15, 'county', 1],
['详细地址', 15, 'address', 1],
['星级', 15, 'level', 1],
];
$Excel = new Excel();
$letter = $Excel->excelAcross(count($title));
$Excel->excel($letter, $title, $data, 'volunteers');
}
public function sendnotice(){
return $this->fetch();
}
public function sendsms(){
$data = Db::name('volunteer')
->where('delete_time', 0)
->order('create_time desc')
->select();
$this->assign([
'list' => $data,
]);
return $this->fetch();
}
public function smsPost(){
$user=input('to_user_id');
$content=input('description');
if (empty($user)||$user==0){
$this->error('请选择用户!');
}
if (empty($content)){
$this->error('内容不能为空!');
}
$users=explode(',',$user);
$result=send_duanxinbao($content,$users);
if ($result==0){
$this->success('发送成功!');
}else{
$this->error('发送失败!');
}
}
public function pass(){
$id=input('id');
$update['status']='2';
$update['stage']='1';
$result=\db('volunteer')->where('id',$id)->update($update);
if ($result>0){
$date=date('Y-m-d H:i');
$volunteer=\db('volunteer')->where('id',$id)->find();
$openId=\db('third_party_user')->where('user_id',$volunteer['user_id'])->value('openid');
$data=[
'phrase1' => ['value' =>'审核通过'], //审核结果
'thing2'=>['value'=>'申请白求恩志愿者审核'], //活动名称
'thing4'=>['value'=>'审核通过'], //备注
'date7'=>['value'=>$date] //审核时间
];
$Info=sendSubMessage($data,$openId);
$this->success('编辑成功!');
}else{
$this->error('编辑失败');
}
}
/**
* 编辑阶段
* @throws \think\Exception
* @throws \think\exception\PDOException
*/
public function stage(){
$id=input('id');
$stage=input('stage');
$update['stage']=$stage;
$result=\db('volunteer')->where('id',$id)->update($update);
if ($result>0){
$this->success('编辑成功!');
}else{
$this->error('编辑失败');
}
}
/**
* 申请不通过
* @throws \think\Exception
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
* @throws \think\exception\PDOException
*/
public function unpass(){
$id=input('id');
$update['status']='3';
$result=\db('volunteer')->where('id',$id)->update($update);
if ($result>0){
$date=date('Y-m-d H:i');
$volunteer=\db('volunteer')->where('id',$id)->find();
$openId=\db('third_party_user')->where('user_id',$volunteer['user_id'])->value('openid');
$data=[
'phrase1' => ['value' =>'审核不通过'], //审核结果
'thing2'=>['value'=>'申请白求恩志愿者审核'], //活动名称
'thing4'=>['value'=>'审核不通过'], //备注
'date7'=>['value'=>$date] //审核时间
];
$Info=sendSubMessage($data,$openId);
$this->success('编辑成功!');
}else{
$this->error('编辑失败');
}
}
}