ProjectRoomOrder.php
2.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
<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use app\index\model\ProjectRoomOrder as ProjectRoomOrderModel;
use think\Db;
use think\Exception;
class ProjectRoomOrder extends Frontend
{
protected $noNeedLogin = '*';
protected $noNeedRight = '*';
protected $layout = 'default';
protected $roomOrderModel = null;
public function _initialize()
{
$this->roomOrderModel = new ProjectRoomOrderModel();
parent::_initialize(); // TODO: Change the autogenerated stub
}
/**
* @return string
* @throws \think\Exception
* 房间预约
*/
public function index()
{
$user = $this->auth->getUser();
$param = $this->request->param();
$where = ['o.user_id'=>["=",$user['id']]];
$status = !empty($param['status']) ? $param['status'] : 0;
switch ($status){
//查询所有
case 0:
$where['o.status'] = ["between",[1,4]];
break;
default:
$where['o.status'] = ["=", $status];
}
$list = Db::name('project_room_order')
->field('o.*,r.room_name')
->alias('o')
->join('project_room r','o.room_id = r.id','left')
->where($where)
->order('o.createtime','desc')
->paginate(10,false,['query'=>request()->param()]);
$this->assign("list",$list);
$this->assign("status",$status);
$this->assign("page",$list->render());
return $this->view->fetch();
}
public function update(){
$param = $this->request->param();
$info = Db::name("project_room_order")->where('id',$param['id'])->find();
if(!$info) {
$this->error("预约记录不存在");
}
Db::startTrans();
try {
if($param['status'] == 1) {
$status = Db::name('project_room_order')->where(['id'=>$param['id']])->update(['status' => 4]);
}
$result = Db::name("project_room_order")->where('id',$param['id'])->delete();
Db::commit();
} catch (Exception $e) {
Db::rollback();
$this->error("操作失败,请重试");
}
$this->success("操作成功");
}
}