RoomOrder.php 2.3 KB
<?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\Building as BuildingModel;
use app\school\model\project_appointment\Floor as FloorModel;
use app\school\model\project_appointment\Room as RoomModel;
use app\school\model\project_appointment\RoomOrder as RoomOrderModel;

/**
 * 房间管理
 */
class RoomOrder extends DoubleBase
{

    protected $noNeedRight = ['*'];
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize();
        $this->model = new RoomOrderModel();
    }

    /**
     * 预约审核index
     * @return array|\think\response\Json
     * @author cdd
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams(null,true);
            $params = json_decode($this->request->get('filter'),true);
            $newwhere = [];
            if(isset($params['room_name'])) {
                $newwhere['r.room_name'] = ['like',"%".$params['room_name']."%"];
            }
            if(isset($params['username']) && !empty($params['username'])) {
                $newwhere['u.username'] = ['like',"%".$params['username']."%"];
            }
            $list = $this->model
                ->field('o.*,r.room_name,u.username')
                ->alias('o')
                ->join('project_room r','o.room_id = r.id','inner')
                ->join('user u','o.user_id = u.id','left')
                ->where(['r.school_id' => SCHOOL_ID])
                ->where($newwhere)
                ->order('o.createtime', $order)
                ->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }

    public function verify()
    {
        $params = $this->request->param();
        $info = $this->model->find($params['id']);
        $info->status = $params['status'];
        if(!$info->save()) {
            $this->error('审核失败');
        }
        $this->success('成功');
    }


}