BuildingEnter.php
10.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
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
<?php
namespace app\school\controller\project_appointment;
use app\common\controller\DoubleBase;
use app\school\model\project_appointment\BuildingEnterLog;
use app\school\controller\basic\User;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use app\school\model\project_appointment\BuildingEnter as BuildingEnterModel;
use app\school\model\project_appointment\RoomOrder;
use app\school\model\project_appointment\Room;
use think\Url;
/**
* 楼栋管理
*/
class BuildingEnter extends DoubleBase
{
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new BuildingEnterModel();
}
public function index()
{
//设置过滤方法
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->field('en.*,u.username,u.mobile,s.name as school_name,c.college_name')
->alias('en')
->join('user u','en.user_id = u.id','left')
->join('manystore_shop s','en.school_id = s.id','left')
->join('college c','en.college_id = c.id','left')
->where(['en.school_id' => SCHOOL_ID])
->order('en.createtime', 'desc')
->paginate($limit);
// dump(collection($list)->toArray());die;
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
public function room_allocation($id='')
{
if(empty($id)){
$id = $this->request->param('id');
}
if ($this->request->isPost()) {
$params = $this->request->post("row/a");
if ($params) {
$roomModel = new Room();
$roomInfo = $roomModel->where(['id'=>$params['room_id']])->find();
if(!$roomInfo) {
$this->error('该房间不存在或已下线');
}
if($roomInfo['is_use'] == Room::IS_USE_Y) {
$this->error('该房间已经被分配,请选择其他房间');
}
$params['school_id'] = SCHOOL_ID;
Db::startTrans();
try {
//修改房间状态被使用
$roomInfo->is_use = Room::IS_USE_Y;
$roomInfo->save();
//修改审核状态为审核通过
$enter = $this->model->where(['id' => $params['enter_id']])->find();
$enter['status'] = Room::IS_USE_Y;
$enter->save();
//添加房间预约记录
$roomOrder = new RoomOrder();
if($params['term_type'] == 1) {
$endTime = strtotime(date('Y-m-d',strtotime('+6 month')));
}else if($params['term_type'] == 2) {
$endTime = strtotime(date('Y-m-d',strtotime('+12 month')));
}else if($params['term_type'] == 3){
$endTime = strtotime(date('Y-m-d',strtotime('+24 month')));
}else {
$endTime = strtotime($params['end_time']);
}
$save = [
'user_id' => $enter['user_id'],
'room_id' => $params['room_id'],
'apply_date' => $params['apply_date'],
'start_time' => strtotime(date('Y-m-d',strtotime('+7 day'))),
'end_time' => $endTime,
'use_count' => $enter['station_num'],
'order_source' => Room::IS_USE_Y,
'enter_id' => $params['enter_id'],
];
$log = [
'enter_id' => $params['enter_id'],
'log_type' => BuildingEnterLog::AGREE,
'createtime'=> time(),
];
$enterLogModel = new BuildingEnterLog();
$enterLogModel->allowField(true)->save($log);
$result = (new RoomOrder())->allowField(true)->save($save);
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('审核成功','project_appointment/building_enter/index');
}
$this->error(__('Parameter %s can not be empty', ''));
}
$timeLimit = BuildingEnterModel::TIME_LIMIT;
// dump($timeLimit);die;
$this->assign('id',$id);
$this->assign('timeLimit',$timeLimit);
return $this->view->fetch();
}
/**
* 入驻申请详情
* @param $id
*/
public function enter_detail($id)
{
$enterId = $this->request->param('id');
$enterInfo = $this->model
->field('en.*,u.*,c.college_name,s.specialty_name,z.clazz_name')
->alias('en')
->join('user u','en.user_id = u.id','left')
->join('college c','u.college = c.id','left')
->join('specialty s','u.specialty = s.id','left')
->join('clazz z','u.clazz = z.id','left')
->where(['en.id' => $enterId])
->find();
$this->assignconfig('enter_id', $enterId);
$this->assign('row', $enterInfo);
return $this->fetch();
}
/**
* //入驻成员列表
*/
public function get_members()
{
if ($this->request->isAjax()) {
$id = $this->request->param('id');
$userIds = $this->model->where(['id' => $id])->value('enter_student_ids');
$rows = (new \app\school\model\basic\User())
->alias('a')
->where(['id' => ['IN', $userIds]])
->select();
$res = [
'total' => count($rows),
'rows' => $rows
];
return $res;
}
}
//入驻指导教师
public function get_teachers()
{
if ($this->request->isAjax()) {
$id = $this->request->param('id');
$teachers = $this->model->where(['id' => $id])->value('enter_teacher_ids');
$rows = (new \app\school\model\basic\Teacher())
->alias('a')
->where(['id' => ['IN', $teachers]])
->select();
$res = [
'total' => count($rows),
'rows' => $rows
];
return $res;
}
}
//审核驳回
public function reject()
{
$id = $this->request->param('id');
$info = $this->model->where(['id' => $id])->find();
$enterLogModel = new BuildingEnterLog();
Db::startTrans();
try{
$info->status = 3;
$info->save();
$log = [
'enter_id' => $id,
'log_type' => BuildingEnterLog::REJECT,
'createtime'=> time(),
];
$enterLogModel->allowField(true)->save($log);
Db::commit();
} catch (\Exception $e) {
// 回滚事务
Db::rollback();
$this->error('驳回失败,稍后请重试');
}
$this->success('成功');
}
public function company_index()
{
$this->request->filter(['strip_tags', 'trim']);
if ($this->request->isAjax()) {
list($where, $sort, $order, $offset, $limit) = $this->buildparams();
$list = $this->model
->alias('en')
->field('en.*,p.end_time,p.createtime,p.start_time,p.room_id,r.room_name,c.college_name,s.name as school_name,u.username,u.mobile,b.building_name,f.floor_name')
// ->field('en.*,u.username,u.mobile,s.name as school_name,c.college_name,p.end_time,p.start_time')
->join('project_room_order p','en.id = p.enter_id','left')
->join('project_room r','p.room_id = r.id','left')
->join('college c','en.college_id = c.id','left')
->join('manystore_shop s','en.school_id = s.id','left')
->join('project_building b','r.building_id = b.id','left')
->join('project_floor f','r.floor_id = f.id','left')
->join('user u','en.user_id = u.id','left')
->where(['en.status' => 2,'en.school_id' => SCHOOL_ID])
->order('en.createtime', 'desc')
->paginate($limit);
if($list) {
foreach ($list as &$value) {
$value['expire_type'] = '未到期';
if(isset($value['end_time'])) {
if(time() > $value['end_time']) {
$value['expire_type'] = '已到期';
}
}else{
$value['expire_type'] = '已到期';
}
}
}
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
//强制到期
public function expire()
{
$id = $this->request->param('id');
$roomOrder = (new RoomOrder())->where(['enter_id'=>$id])->find();
if(!$roomOrder) {
$this->error('该记录不存在');
}
$roomInfo = (new Room())->where(['id' => $roomOrder['room_id']])->find();
Db::startTrans();
try {
$roomOrder->start_time = 0;
$roomOrder->end_time = 0;
$roomOrder->save();
$roomOrder->delete();
$roomInfo->is_use = 1;
$log = [
'enter_id' => $id,
'log_type' => BuildingEnterLog::EXPIRE,
'createtime'=> time(),
];
$enterLogModel = new BuildingEnterLog();
$enterLogModel->allowField(true)->save($log);
$roomInfo->save();
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('成功');
}
}