VolunteerController.php
12.2 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
<?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 = [];
$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%"];
}
$addr = empty($param['addr']) ? '' : $param['addr'];
if (!empty($addr)) {
$where['addr'] = ['like', "%$addr%"];
}
$list = Db::name('volunteer')
->where('delete_time', 0)
->where($where)
->order('create_time desc')
->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'] : '');
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();
/*更新级别*/
$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%"];
}
$data = Db::name('volunteer')
->where('delete_time', 0)
->where($where)
->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'];
}
$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],
];
$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';
$result=\db('volunteer')->where('id',$id)->update($update);
if ($result>0){
$this->success('编辑成功!');
}else{
$this->error('编辑失败');
}
}
public function unpass(){
$id=input('id');
$update['status']='3';
$result=\db('volunteer')->where('id',$id)->update($update);
if ($result>0){
$this->success('编辑成功!');
}else{
$this->error('编辑失败');
}
}
}