SxBasement.php
6.4 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
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\school\model\project_appointment\Building as BuildingModel;
use app\school\model\project_appointment\AppointmentRule as AppointmentRuleModel;
use app\school\model\project_appointment\Room as RoomModel;
use app\index\model\BuildingEnter;
use app\school\model\station\Station;
use think\Db;
class SxBasement extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = 'default';
public function _initialize()
{
parent::_initialize(); // TODO: Change the autogenerated stub
$roomTypeList = RoomModel::$room_type;
$buildList = (new BuildingModel)->where("school_id",$this->school_id)->select();
$roomList = (new RoomModel)->getCollegeRoom(["school_id"=>$this->school_id]);
$enterRules = (new AppointmentRuleModel)->where(['school_id'=>$this->school_id])->find();
if($enterRules) {
$enterRules['data_url'] = json_decode($enterRules['data_url'],true);
}
//工位
$stationList = Station::alias('a')
->field('a.id,a.station_name,count(sa.id) as appoint_count')
->join('fa_station_appointment sa','a.id = sa.station_id','LEFT')
// ->where(['a.school_id'=>$this->auth->school_id])
->where(['a.school_id'=>$this->school_id,'a.status' => 1])
->group('a.id')
->select();
//入驻公司
$buildingEnter = BuildingEnter::where(['enter_type' => 2,'status' => 2,'school_id'=>$this->auth->school_id,'user_id' => $this->auth->id])->column('id,enter_project_name');
$this->assign('roomTypeList',$roomTypeList);
$this->assign('stationList',$stationList);
$this->assign('enterRules',$enterRules);
$this->assign('buildList',$buildList);
$this->assign('roomList',$roomList);
$this->assign('buildingEnter',$buildingEnter);
}
public function index()
{
$this->assign('index','index');
return $this->view->fetch();
}
public function downFiles($file_url)
{
$file_url = $this->request->param('file_url');
$file_name = $this->request->param('file_name');
downloadFile($file_url,$file_name);
}
/**
* 工位分配提交
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function stationApply()
{
$userInfo = $this->auth->getUser();
if(!$userInfo) {
$this->success('请登录后再操作','/index/student_login/index');
// $this->success('请登入','/index/student_login/index');
}
$params = $this->request->post();
if(!isset($params['station_id']) || empty($params['station_id'])){
$this->error('请选择工位');
}
if($params['station_type'] == 2 ) {
if(empty($params['enter_id'])) {
$this->error('请选择公司');
}
}
$startTime = strtotime($params['station_date'].$params['station_start_time']);
$endTime = strtotime($params['station_date'].$params['station_end_time']);
if($startTime <= time()) {
$this->error('开始时间必须大于当前时间');
}
if($startTime == $endTime) {
$this->error('预约开始时间不能等于结束时间');
}
if($endTime <= $startTime) {
$this->error('结束时间不能小于开始时间');
}
$stationInfo = Station::alias('a')
->field('a.id,a.station_name,a.capacity,count(sa.id) as appoint_count')
->join('fa_station_appointment sa','a.id = sa.station_id','LEFT')
->where('a.deletetime',NULL)
->where(['a.id' => $params['station_id']])
->find();
if(!$stationInfo) {
$this->error('该工位不存在或已经被下架');
}
if ($stationInfo['appoint_count']){
$this->error('该工位已被预约');
}
if ($stationInfo['capacity'] < $params['station_user_count']){
$this->error("该工位可容纳{$stationInfo['capacity']}人");
}
$res = Db::table('fa_station_appointment')
->whereOr("station_start_time >= {$startTime} AND station_start_time <= {$endTime}")
->whereOr("station_start_time <= {$startTime} AND station_end_time >= {$endTime}")
->whereOr("station_end_time >= {$startTime} AND station_end_time <= {$endTime}")
->having("station_id = {$params['station_id']}")
->select();
if($res) {
$this->error('该时间存在已经被预约,请重新选择');
}
$params['station_start_time'] = $startTime;
$params['station_end_time'] = $endTime;
$params['user_id'] = $userInfo['id'];
$params['school_id'] = $userInfo['school_id'];
$params['createtime'] = time();
$result = Db::table('fa_station_appointment')->insert($params);
if(!$result) {
$this->error('预约失败,请重新尝试');
}
$this->success('预约成功','/index/sx_basement/index');
}
/**
* 工位列表
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function station(){
$params = $this->request->post();
$startTime = strtotime($params['station_date'].$params['station_start_time']);
$endTime = strtotime($params['station_date'].$params['station_end_time']);
//工位
$stationList = Station::alias('a')
->field('a.id,a.station_name,count(sa.id) as appoint_count')
->join('fa_station_appointment sa','a.id = sa.station_id','LEFT')
->whereOr("station_start_time >= {$startTime} AND station_start_time <= {$endTime}")
->whereOr("station_start_time <= {$startTime} AND station_end_time >= {$endTime}")
->whereOr("station_end_time >= {$startTime} AND station_end_time <= {$endTime}")
->where('a.school_id',$this->auth->school_id)
->group('a.id')
->select();
$this->success('查询成功',$stationList);
}
}