Double.php 4.2 KB
<?php

namespace app\school\controller\project_approval;

use app\common\controller\DoubleBase;
use app\school\model\project_approval\ProjectRegister;
use app\school\model\project_common\ProjectDouble;
use app\school\model\project_common\ProjectDoubleApply;
use think\Db;

class Double extends DoubleBase
{
    protected $containerId = null;
    protected $model = null;

    protected $shopIdAutoCondition = false;

    public function _initialize()
    {
        parent::_initialize();
        $this->containerId = $_COOKIE['container_id'];
        $this->model = new ProjectDouble();
    }

    public function index()
    {

        return $this->view->fetch();
    }

    /**
     * 查看成员信息
     * @return array|mixed
     */
    public function membersView()
    {
        if ($this->request->isAjax()) {
            $doubleId = $this->request->param('project_double_id');
            $dataWhere = ['a.project_double_id' => $doubleId, 'a.proposer_state' => 1, 'a.proposer_type' => 0];
            $rows = (new ProjectDoubleApply())
                ->alias('a')
                ->field('a.*, b.username, b.student_no')
                ->join('fa_user b', 'a.proposer_id = b.id', 'left')
                ->where($dataWhere)
                ->select();
            $total = count($rows);

            $res = [
                'total' => $total,
                'rows' => $rows
            ];

            return $res;
        }

        return $this->fetch();
    }

    /**
     * 查看指导教师信息
     * @return array|mixed
     */
    public function teachersView()
    {
        if ($this->request->isAjax()) {
            $doubleId = $this->request->param('project_double_id');
            $dataWhere = ['a.project_double_id' => $doubleId, 'a.proposer_state' => 1, 'a.proposer_type' => 1];
            $rows = (new ProjectDoubleApply())
                ->alias('a')
                ->field('a.*, b.username, b.job_num')
                ->join('fa_teacher b', 'a.proposer_id = b.id', 'left')
                ->where($dataWhere)
                ->select();
            $total = count($rows);

            $res = [
                'total' => $total,
                'rows' => $rows
            ];

            return $res;
        }

        return $this->fetch();
    }

    /**
     * 教师申请的双选项目
     */
    public function teacherProjects()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $dataWhere = ['a.project_container_id' => $this->containerId, 'a.captain_type' => 1];

            $total = $this->model->alias('a')->where($dataWhere)->where($where)->count();
            $rows = $this->model->alias('a')
                ->field('a.*, b.username, b.job_num')
                ->join('fa_teacher b', 'a.captain_id = b.id', 'left')
                ->where($dataWhere)
                ->where($where)
                ->limit($offset, $limit)
                ->select();
            foreach ($rows as $k=>$v){
                $teacher = Db::name("teacher")->where("id",$v['user_id'])->find();
                $v['username'] = $teacher["username"];
                $v['job_num'] = $teacher["job_num"];
                $rows[$k] = $v;
            }
            $res = [
                'total' => $total,
                'rows'  => $rows
            ];

            return $res;
        }
    }

    /**
     * 学生申请的双选项目
     */
    public function studentProjects()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $dataWhere = ['a.project_container_id' => $this->containerId, 'a.captain_type' => 0];

            $total = $this->model->alias('a')->where($dataWhere)->where($where)->count();
            $rows = $this->model->alias('a')
                ->field('a.*, b.username, b.student_no')
                ->join('fa_user b', 'a.captain_id = b.id', 'left')
                ->where($dataWhere)
                ->where($where)
                ->limit($offset, $limit)
                ->select();

            $res = [
                'total' => $total,
                'rows'  => $rows
            ];

            return $res;
        }
    }


}