BuildingEnterVerify.php
6.8 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
<?php
namespace app\school\controller\project_appointment;
use app\common\controller\DoubleBase;
use think\Db;
use think\Exception;
use think\exception\PDOException;
use think\exception\ValidateException;
use app\school\model\project_appointment\BuildingEnter;
use app\school\model\project_appointment\BuildingEnterVerify as BuildingEnterVerifyM;
use app\school\model\project_appointment\RoomOrder;
use app\school\model\project_appointment\Room;
use think\Url;
/**
* 续租退孵
*/
class BuildingEnterVerify extends DoubleBase
{
protected $noNeedRight = ['*'];
protected $model = null;
public function _initialize()
{
parent::_initialize();
$this->model = new BuildingEnterVerifyM();
}
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('v.*,v.createtime as v_createtime,en.*,s.name,c.college_name,u.username,u.mobile')
->alias('v')
->join('project_building_enter en','v.enter_id = en.id')
->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,'en.status' => 2])
->order('en.createtime', 'desc')
->paginate($limit);
$result = array("total" => $list->total(), "rows" => $list->items());
return json($result);
}
return $this->view->fetch();
}
//退孵 续租审核同意
public function agree()
{
$id = $this->request->param('id');
if(empty($id)) {
$this->error('参数错误');
}
$info = $this->model->where(['id' => $id])->find();
if(!$info) {
$this->error('该记录不存在');
}
$roomOrder = (new RoomOrder())->where(['enter_id'=>$info['enter_id']])->find();
if(!$roomOrder) {
$this->error('入驻场地不存在或已下线');
}
Db::startTrans();
try {
//退孵
if($info['verify_type'] == BuildingEnterVerifyM::BUILD_EXIT) {
$enterInfo = (new BuildingEnter())->where(['id' => $info['enter_id']])->find();
if(!$enterInfo) {
$this->error('入驻信息不存在');
}
$room = (new Room())->where(['id' => $roomOrder['room_id']])->find();
if(!$room) {
$this->error('房间不存在或已下线');
}
$room->is_use = 1;
$room->save();
$roomOrder->start_time = 0;
$roomOrder->end_time = 0;
$roomOrder->save();
$roomOrder->delete();$roomOrder->delete();
}else{
//续租
if($info['time_limit'] == 4) {
//自定义时间
if($info['renewal_time'] <= $roomOrder['end_time']) {
$this->error('续租日期不能小于当前预约结束日期');
}
$endTime = $info['renewal_time'];
}else if ($info['time_limit'] == 1){
$endTime = strtotime("+6month",$roomOrder['end_time']);
}else if ($info['time_limit'] == 2) {
$endTime = strtotime("+1year",$roomOrder['end_time']);
}else {
$endTime =strtotime("+2year",$roomOrder['end_time']);
}
$roomOrder->end_time = $endTime;
$roomOrder->save();
}
$info->verify_status = 2;
$info->save();
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('审核成功');
}
//审核驳回
public function reject()
{
$id = $this->request->param('id');
$info = $this->model->where(['id' => $id])->find();
$info->verify_status = 3;
if(!$info->save()) {
$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
->field('en.*,u.username,u.mobile,s.name as school_name,c.college_name,p.start_time,p.end_time,b.building_name,f.floor_name,r.room_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')
->join('project_room_order p','en.id = p.enter_id','inner')
->join('project_room r','p.room_id = r.id','left')
->join('project_building b','r.building_id = b.id','left')
->join('project_floor f','r.floor_id = f.id','left')
->where(['en.school_id' => SCHOOL_ID,'en.status' => 2])
->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();
$roomInfo->is_use = 1;
$roomInfo->save();
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error($e->getMessage());
}
$this->success('成功');
}
}