ProgramList.php 2.5 KB
<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\expert\model\ProjectRegister;
use app\index\model\ItemDelay;
use think\Exception;

class ProgramList extends Frontend
{

    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = 'default';
    protected $model = null;
    CONST PARAMS_ERROR = '参数错误';
    CONST BAD_REQUEST  = '非法请求';
    CONST NOT_FOUND  = '作品不存在';
    CONST DELAY_APPLY  = '您已申请项目延期';

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new ProjectRegister();
        $this->assign('index','index');
    }

    public function index()
    {
        // 查询学生报名的作品
        $_list = $this->model->alias('r')
            ->field('r.* , pc.container_name , pt.name , pc.midterm_review_starttime, pc.midterm_review_endtime,pc.conclusion_starttime,pc.conclusion_endtime,
            pc.project_starttime,pc.project_endtime,pc.project_double_starttime,pc.project_double_endtime,
            pc.can_apply_mid,pc.can_apply_conclusion,pc.can_apply_approval,count(pd.id) as pd_count')
            ->join('project_container pc','pc.id = r.container_id','left')
            ->join('project_type pt','pt.id=r.project_type','left')
            ->join('project_delay pd','pd.register_id=r.id','left')
            ->where('r.user_id',$this->auth->id)->group('r.id')->paginate(1);

        $_list_count = $this->model
            ->where('user_id',$this->auth->id)->count();
        $this->assign('_list',$_list);
        $this->assign('_list_count',$_list_count);

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

    // 项目延期申请
    public function subject_delay(){
        if (!request()->post()) $this->error(self::BAD_REQUEST);
        $item_id = request()->param('item_id',false);
        $delay_memo = request()->param('delay_memo',null);
        if (!$item_id) $this->error(self::PARAMS_ERROR);
        $item = $this->model->where('id',$item_id)->find();
        if (!$item) $this->error(self::NOT_FOUND);
        $_delay = ItemDelay::get(['register_id'=>$item_id]);
        if ($_delay){
            $this->error(self::DELAY_APPLY);
        }
        $created['register_id'] = $item_id;
        $created['delay_memo']  = $delay_memo;
        try {
            ItemDelay::create($created);
        }catch (Exception $e){
            $this->error($e->getMessage());
        }
        $this->success("申请项目延期成功");
    }

}