AdminSignController.php
8.5 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
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author:kane < chengjin005@163.com>
// +----------------------------------------------------------------------
namespace app\portal\controller;
use cmf\controller\AdminBaseController;
use think\Db;
/**
* Class AdminSignController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'打卡管理',
* 'action' =>'default',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 30,
* 'icon' =>'th',
* 'remark' =>'打卡管理'
* )
*/
class AdminSignController extends AdminBaseController
{
/**
* 打卡列表
* @adminMenu(
* 'name' => '打卡列表',
* 'parent' => 'portal/AdminSign/default',
* 'display'=> true,
* 'hasView'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '打卡列表',
* 'param' => ''
* )
*/
public function index()
{
$where = ['user_type'=>2];
$request = input('request.');
if (!empty($request['user_nickname'])) {
$nickname=$request['user_nickname'];
$where['user_nickname'] = ['like', "%$nickname%"];
}
if (!empty($request['mobile'])) {
$keyword = $request['mobile'];
$where['mobile'] = ['like', "%$keyword%"];
}
$usersQuery = Db::name('user');
$list = $usersQuery->where($where)->order("create_time DESC")->paginate(10);
// 获取分页显示
$page = $list->render();
$this->assign('list', $list);
$this->assign('page', $page);
// 渲染模板输出
return $this->fetch();
}
public function signTime(){
$data=Db::name('config')->where('id',1)->find();
$this->assign('list',$data);
return $this->fetch();
}
public function signTimePost(){
$param=$this->request->param();
$param['morning_sign_time']=strtotime($param['morning_sign_time']);
$param['morning_sign_end_time']=strtotime($param['morning_sign_end_time']);
$param['noon_sign_time']=strtotime($param['noon_sign_time']);
$param['noon_sign_end_time']=strtotime($param['noon_sign_end_time']);
$param['night_sign_time']=strtotime($param['night_sign_time']);
$param['night_sign_end_time']=strtotime($param['night_sign_end_time']);
$param['sleep_sign_time']=strtotime($param['sleep_sign_time']);
$param['sleep_sign_end_time']=strtotime($param['sleep_sign_end_time']);
Db::name('config')->where('id',1)->update($param);
$this->success('编辑成功');
}
public function sLogan(){
$data=Db::name('config')->where('id',1)->find();
$this->assign('list',$data);
return $this->fetch();
}
public function sLoganPost(){
$param=$this->request->param();
Db::name('config')->where('id',1)->update($param);
$this->success('编辑成功');
}
public function score(){
$data=Db::name('config')->where('id',1)->find();
$this->assign('list',$data);
return $this->fetch();
}
public function scorePost(){
$param=$this->request->param();
Db::name('config')->where('id',1)->update($param);
$this->success('编辑成功');
}
public function signImage(){
$param=$this->request->param();
if (empty($param)){
$param['id']=1;
}
$data=Db::name('sign_image')->where('id',$param['id'])->find();
$data['music']=json_decode($data['music'],true);
$this->assign('list',$data);
return $this->fetch();
}
public function signImagePost(){
$param=$this->request->param();
// var_dump($param);
// $param['music']=\GuzzleHttp\json_encode()
if (!empty($param['video_names']) && !empty($param['video_urls'])) {
$param['music'] = [];
foreach ($param['video_urls'] as $key => $url) {
$fileUrl = cmf_asset_relative_url($url);
array_push( $param['music'] , ["url" => $fileUrl, "name" => $param['video_names'][$key]]);
}
$param['music']=json_encode($param['music']);
}
unset($param['video_names']);
unset($param['video_urls']);
Db::name('sign_image')->where('id',$param['id'])->update($param);
$this->success('编辑成功');
}
public function daySign(){
$param=$this->request->param();
$where['us.user_id']=$param['id'];
if (!empty($param['user_nickname'])) {
$nickname=$param['user_nickname'];
$where['u.user_nickname'] = ['like', "%$nickname%"];
}
if (!empty($param['mobile'])) {
$keyword = $param['mobile'];
$where['u.mobile'] = ['like', "%$keyword%"];
}
if (!empty($param['status'])) {
$status = $param['status'];
$where['us.status'] = $status;
}
$data=Db::name('user_sign')->alias('us')->join('user u','us.user_id=u.id')->where($where)->order('us.create_time','desc')->field('*,us.id as usid')->paginate(10);
$this->assign('list',$data);
$this->assign('id',$param['id']);
$this->assign('keyword', isset($keyword) ? $keyword : '');
$this->assign('nickname', isset($nickname) ? $nickname : '');
$this->assign('status', isset($status) ? $status : '');
return $this->fetch();
}
public function daySignDelete(){
$param=$this->request->param();
if (!empty($param['ids'])){
Db::name('user_sign')->where(['id' => ['in', $param['ids']]])->delete();
$this->success('删除成功');
}
Db::name('user_sign')->where('id', $param['id'])->delete();
$this->success('删除成功');
}
public function weekSign(){
$param=$this->request->param();
$where['uw.user_id']=$param['id'];
if (!empty($param['user_nickname'])) {
$nickname=$param['user_nickname'];
$where['u.user_nickname'] = ['like', "%$nickname%"];
}
if (!empty($param['mobile'])) {
$keyword = $param['mobile'];
$where['u.mobile'] = ['like', "%$keyword%"];
}
$data=Db::name('user_week_sign')->alias('uw')->join('user u','uw.user_id=u.id')->where($where)->order('uw.create_time','desc')->field('*,uw.id as uwid')->paginate(10);
$this->assign('list',$data);
$this->assign('id',$param['id']);
$this->assign('keyword', isset($keyword) ? $keyword : '');
$this->assign('nickname', isset($nickname) ? $nickname : '');
return $this->fetch();
}
public function weekSignDelete(){
$param=$this->request->param();
if (!empty($param['ids'])){
Db::name('user_week_sign')->where(['id' => ['in', $param['ids']]])->delete();
$this->success('删除成功');
}
Db::name('user_week_sign')->where('id', $param['id'])->delete();
$this->success('删除成功');
}
/**
* 删除打卡记录
* @adminMenu(
* 'name' => '删除打卡记录',
* 'parent' => 'index',
* 'display'=> false,
* 'hasView'=> false,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '删除打卡记录',
* 'param' => ''
* )
*/
public function delete()
{
$param=$this->request->param();
if (!empty($param['ids'])){
Db::name('user_sign')->where(['user_id' => ['in', $param['ids']]])->delete();
Db::name('user_week_sign')->where(['user_id' => ['in', $param['ids']]])->delete();
Db::name('user')->where(['user_id' => ['in', $param['ids']]])->update(['all_sign_day'=>0,'stay_sign_day'=>0,'longest_sign_day'=>0]);
$this->success('删除成功');
}
Db::name('user_sign')->where('user_id', $param['id'])->delete();
Db::name('user_week_sign')->where('user_id', $param['id'])->delete();
Db::name('user')->where('user_id', $param['id'])->update(['all_sign_day'=>0,'stay_sign_day'=>0,'longest_sign_day'=>0]);
$this->success('删除成功');
}
}