BookingController.php
6.6 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
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use cmf\controller\AdminBaseController;
use think\Db;
/**
* Class UserController
* @package app\admin\controller
* @adminMenuRoot(
* 'name' => '管理组',
* 'action' => 'default',
* 'parent' => 'user/AdminIndex/default',
* 'display'=> true,
* 'order' => 10000,
* 'icon' => '',
* 'remark' => '管理组'
* )
*/
class BookingController extends AdminBaseController
{
public function seting(){
$id = $this->request->param('id');
$pcdata = [];
if($id){
$pcdata = DB::name('user')->where(['id'=>$id])->find();
}
if(!$pcdata){
$pcdata['id'] = '';
$pcdata['user_nickname'] = '请选择';
}
$this->assign('pcdata',$pcdata);
$cdata = DB::name('user')->where(['user_type'=>'3'])->select()->toArray();
$this->assign('cdata',$cdata);
$day = [];
for($i = 0;$i<21;$i++){
$day[] = date('Y-m-d',strtotime("+$i day"));
}
$this->assign('day',$day);
return $this->fetch();
}
public function seting_do(){
$param = $this->request->param();
if(!$param){
return json(['code'=>'0','msg'=>'数据错误']);
}
$datain['teach_id'] = $param['teach_id'];
$datain['yuyue_begin'] = $param['begin'];
$datain['yuyue_end'] = $param['end'];
$datain['yuyue_day'] = $param['day'];
$cdata = DB::name('yuyue')->where($datain)->find();
if($cdata){
if($cdata['uid'] == '0'){
$res = DB::name('yuyue')->where($datain)->delete();
if ($res) {
return json(['code'=>'1','msg'=>'取消成功']);
}else{
return json(['code'=>'0','msg'=>'取消失败']);
}
}else{
return json(['code'=>'0','msg'=>'已被学员预约,无法取消']);
}
}else{
$res = DB::name('yuyue')->insert($datain);
if ($res) {
return json(['code'=>'1','msg'=>'保存成功']);
}else{
return json(['code'=>'0','msg'=>'保存失败']);
}
}
}
public function find_seting(){
$day = $this->request->param('day');
$uid = $this->request->param('uid');
if(!$day){
$day = date('Y-m-d');
}
$res = Db::name('yuyue')->where(['yuyue_day'=>$day,'teach_id'=>$uid])->select()->toArray();
$all_arr = [];
for($t = 6;$t<=18;$t++){
$all_arr[]=$t;
}
$arr = [];
for($i = 0;$i<count($res);$i++){
$begin = $res[$i]["yuyue_begin"];
$end = $res[$i]["yuyue_end"];
for($j= $begin;$j<$end;$j++){
$arr[]=$j;
}
}
$ok_arr = [];
for($q = 0;$q< count($all_arr);$q++){
if(in_array($all_arr[$q],$arr)){
$ok_arr[] = "no";
}else{
$ok_arr[] = "yes";
}
}
$res1 = Db::name('yuyue')->where(['yuyue_day'=>$day,'teach_id'=>$uid,'uid'=>['gt','0']])->select()->toArray();
$all_arr1 = [];
for($t = 6;$t<=18;$t++){
$all_arr1[]=$t;
}
$arr1 = [];
for($i = 0;$i<count($res1);$i++){
$begin = $res1[$i]["yuyue_begin"];
$end = $res1[$i]["yuyue_end"];
for($j= $begin;$j<$end;$j++){
$arr1[]=$j;
}
}
$ok_arr1 = [];
for($q = 0;$q< count($all_arr1);$q++){
if(in_array($all_arr1[$q],$arr1)){
$ok_arr1[] = "no";
}else{
$ok_arr1[] = "yes";
}
}
$dataa[0] = $ok_arr;
$dataa[1] = $ok_arr1;
if ($ok_arr){
return json(['code'=>'1','msg'=>'获取成功','data'=>json_encode($dataa,true)]);
}else{
return json(['code'=>'0','msg'=>'获取失败']);
}
}
// public function find_seting(){
// $param = $this->request->param();
// if(!$param){
// return json(['code'=>'0','msg'=>'数据错误']);
// }
// $datain['teach_id'] = $param['teach_id'];
// $datain['day'] = $param['day'];
//
// $data = array();
// for($i=0;$i<11;$i++){
// $data[$i] = 'ok';
// }
// $res = Db::name('yuyue')
// ->where(['yuyue_day'=>$datain['day'],'teach_id'=>$datain['teach_id']])
// ->field('yuyue_hour')
// ->select()
// ->toArray();
// if($res){
// foreach($res as $v){
// $data[$v['yuyue_hour']] = 'no';
// }
// }
//
// if ($data){
// return json(['code'=>'1','msg'=>'获取成功','data'=>json_encode($data,true)]);
// }else{
// return json(['code'=>'0','msg'=>'获取失败']);
// }
// }
public function listing(){
$param = $this->request->param();
$name = empty($param['name']) ? '' : $param['name'];
if (!empty($name)) {
$where['u.user_nickname'] = $name;
}
$where['yy.create_time'] = array('gt',0);
$where['yy.uid'] = array('gt',0);
$list = DB::name('yuyue')
->alias('yy')
->join('qnb_user u','u.id=yy.teach_id','LEFT')
->field('yy.*,u.user_nickname')
->where($where)
->order('id','desc')
->paginate(15);
$this->assign("list", $list->items());
$this->assign('page', $list->render());
return $this->fetch();
}
public function delete(){
$param = $this->request->param();
if(!$param){
return json(['code'=>'0','msg'=>'数据错误']);
}
$res = Db::name('yuyue')
->where(['id'=>$param['id']])
->delete();
if ($res){
return json(['code'=>'1','msg'=>'删除成功']);
}else{
return json(['code'=>'0','msg'=>'删除失败']);
}
}
}