DoubleChoose.php 4.4 KB
<?php

namespace app\index\controller;

use app\common\controller\Frontend;
use app\school\model\project_common\ProjectDoubleApply;
use app\school\model\setting\ProjectType;
use think\Db;

class DoubleChoose extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = 'default';

    public function index()
    {
//        if(!$this->auth->isLogin()){
//            $user = $this->auth->getUserinfo();
//        }else{
//            $user = [];
//        }
        $userId = $this->auth->id;
        $where = [];
        $container_id = $this->request->param('container_id');
        $where['project_container_id'] = $container_id;
        $type_where['container_id'] = $container_id;
        $type = $this->request->param('type');
        $type = isset($type) ? $type :0;
        switch ($type){
            case 1://教师
                $where['captain_type'] = 1;
                break;
            case 2://学生
                $where['captain_type'] = 0;
                break;
        }
        $page = null;
        //TODO 区分学校 $type_where 加 school_id
        $category_list = (new ProjectType())->where($type_where)->select();
        $model = new ProjectDoubleApply();
        $list = Db::name("project_double")->where($where)->paginate(10,false,['query'=>request()->param()]);
        foreach ($list as $k=>$v){
            $v["is_can"]  =0;
            if($v['is_complete'] ==1){
                $v["is_can"]  = 2;
            }else{
                $info_apply = $model->where(["project_double_id" => $v['id'], "proposer_id" => $userId, "proposer_type" => 0])->find();
                if ($info_apply) {
                    $v["is_can"] = 1;
                } else {
                    $v["is_can"] = 0;
                }
            }
            if($type == 0) {
                if($v['is_recruit'] ==0){
                    $v["is_can"]  = -1;
                }
            }

            $list[$k] = $v;
        }
        if(!empty($list)){
            $page = $list->render();
        }
//        dump($type);die;
        $this->assign("count",count($list));
        $this->assign("category_list",$category_list);
        $this->assign("container_id",$container_id);
        $this->assign("page",$page);
        $this->assign("list",$list);
        $this->assign("type",$type);
        return $this->view->fetch();
    }

    public function add_apply(){
        if($this->request->isAjax()){

            if($this->auth->isLogin()){
                $user = $this->auth->getUserinfo();
            }else{
                $this->error("请登录",url('student_login/index'));
            }
            $param = $this->request->param("row/a");
            $data = Db::name('project_double_apply')->where("project_double_id",$param['double_id'])->where("proposer_id",$user['id'])->where("proposer_type",0)->find();
            if(!empty($data)){
                $this->error("请勿重复申报");
            }else{
                if(empty($param['mobile'])) {
                    $this->error("请填写手机号码");
                }
                if(!checkMobile($param['mobile'])) {
                    $this->error("请填写正确的手机号码");
                }
                if(empty($param['proposer_details'])) {
                    $this->error("请填写申请理由和个人简介");
                }
                $sort = Db::name('project_double_apply')->where("project_double_id",$param['double_id'])->where('proposer_type',0)->max("sort");
                if($sort){
                    $sort += 1;
                }else{
                    $sort = 1;
                }
                $insert["project_double_id"] = $param['double_id'];;
                $insert["proposer_id"] = $user['id'];
                $insert["proposer_type"] = 0;
                $insert["proposer_state"] = 0;
                $insert["proposer_details"] = $param['proposer_details'];
                $insert["mobile"] = $param['mobile'];
                $insert["container_id"] = $param['container_id'];
                $insert["sort"] = $sort;
                $insert["createtime"] = time();
                $status = Db::name('project_double_apply')->insert($insert);
                if($status){
                    $this->success("申请成功",url('index',['container_id'=>$param['container_id']]));
                }else{
                    $this->error("申请失败,请联系系统管理员");
                }
            }
        }
    }

}