ClockController.php
4.3 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
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2020/10/14
* Time: 20:13
*/
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
class ClockController extends AdminBaseController
{
/**
* @return mixed
*/
public function index(){
$param=$this->request->param();
$map=[];
if(!empty($param['keyword'])){
$map['c.activity_name']=['like',"%$param[keyword]%"];
}
$data= db('clock')->alias('c')
->field('v.name as user_name,v.photo,c.*')
->join('user u','u.id=c.user_id')
->join('volunteer v','v.user_id=c.user_id')
->where($map)
->order('c.id desc')
->paginate();
$data->appends($param);
$list=$data->items();
$this->assign([
'data'=>$list,
'page'=>$data->render(),
'keyword'=>$param['keyword']??''
]);
return $this->fetch();
}
public function addclock(){
$param=input();
$map['j.id']=$param['id'];
$data= db('join')->alias('j')
->field('v.name as user_name,v.photo,v.sex,v.birthday,v.move_phone,v.card_number as id_card,j.*,a.activity_name,a.start_time,a.long,a.lat,a.address_name')
->join('user u','u.id=j.user_id')
->join('volunteer v','v.user_id=j.user_id')
->join('activity a','a.id=j.activity_id')
->where($map)
->find();
$this->assign('data',$data);
return $this->fetch();
}
public function addclocks(){
$param=input();
$map['id']=$param['id'];
$data= db('activity')->where($map)->find();
$this->assign('data',$data);
return $this->fetch();
}
/**
*提交信息
*/
public function addpost(){
$update= $this->request->param();
$result=db('clock')->insert($update);
if ($result){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
/**
*提交信息
*/
public function addPostMul(){
$update= $this->request->param();
$start_time=strtotime(input('start_date'));
$end_time=strtotime(input('end_date'));
$time=$start_time;
while ($time<=$end_time){
$date[]=date('Y-m-d',$time);
$time=$time+3600*24;
}
$user_ids=input('user_id');
$user_array=explode($user_ids,',');
unset($update['start_date']);
unset($update['end_date']);
foreach ($user_array as $k=>$v) {
foreach ($date as $k1=>$v1) {
$update['user_id']=$v;
$update['date'] =$v1;
$result=db('clock')->insert($update);
}
}
if ($result){
$this->success('操作成功!');
}else{
$this->error('操作失败!');
}
}
public function info(){
$param=$this->request->param();
$map=[];
}
/**
* 编辑信息
* @return mixed
*/
public function edit(){
$id = input('id');
$param = $this->request->param();
$map['c.id'] = $id;
$data = db('clock')->alias('c')
->field('v.name as user_name,v.photo,c.*')
->join('user u','u.id=c.user_id')
->join('volunteer v','v.user_id=c.user_id')
->where($map)
->find();
if(empty($data['user_start'])){
$data['user_start']='';
}else{
$data['user_start']=date('Y-m-d H:i:s',$data['user_start']);
}
if(empty($data['user_end'])){
$data['user_end']='';
}else{
$data['user_end']=date('Y-m-d H:i:s',$data['user_end']);
}
$this->assign('data', $data);
return $this->fetch();
}
/**
* 添加信息
* @return mixed
*/
public function add(){
return $this->fetch();
}
public function editPost(){
$id = input('id');
$update= $this->request->param();
$update['user_start']=strtotime($update['user_start']);
$update['user_end']=strtotime($update['user_end']);
$result=db('clock')->where('id',$id)->update($update);
$this->success('操作成功!');
}
}