StationAppointment.php 2.0 KB
<?php

namespace app\school\controller;

use app\common\controller\DoubleBase;
use think\Db;
use app\common\model\StationAppointment as AppointmentModel;

/**
 * 工位审核
 */
class StationAppointment extends DoubleBase
{

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

    /**
     * 预约审核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['station_name'])) {
                $newwhere['s.station_name'] = ['like',"%".$params['station_name']."%"];
            }
            if(isset($params['username']) && !empty($params['username'])) {
                $newwhere['u.username'] = ['like',"%".$params['username']."%"];
            }
            $list = $this->model
                ->alias('a')
                ->field('a.*,s.station_name,u.username')
                ->join('station s','a.station_id = s.id','inner')
                ->join('user u','a.user_id = u.id','left')
                ->where(['s.school_id' => SCHOOL_ID])
                ->where($newwhere)
                ->order('a.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('成功');
    }


}