ProjectAchievements.php 10.9 KB
<?php


namespace app\index\controller;


use app\common\controller\Frontend;
use think\Db;

class ProjectAchievements extends Frontend
{
    protected $noNeedLogin = [];
    protected $noNeedRight = '*';
    protected $layout = 'default';
    protected $model = null;
    public function _initialize()
    {
        parent::_initialize(); // TODO: Change the autogenerated stub
		$this->assign('index','index');
    }

    /**
     * @return string
     * @throws \think\Exception
     * @throws \think\exception\DbException
     * 发表论文情况
     */
    public function PaperIndex(){
        $param = $this->request->param();
        $list = Db::name("project_paper")->where(['regiter_id'=>$param['id']])->paginate(10,false,['query'=>request()->param()]);
        $this->assign("list",$list);
        $this->assign("page",$list->render());
        $this->assignconfig("regiter_id",$param['id']);
        $this->assign("regiter_id",$param['id']);
        return $this->view->fetch();
    }

    /**
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 添加论文
     */
    public function PaperAdd(){

        $param = $this->request->param();
        if($this->request->isAjax()){

            if(empty($param["member_json"])){
                $this->error("请填写至少1个作者");
            }else{
                $insert["member_json"]      = json_encode($param["member_json"],JSON_UNESCAPED_UNICODE);//论文作者集合格式[{''user_id'':''1'',"number":''001'',''username'':''小明''}]其中number是工号,user_id是用户id,username是用户名
            }

            if(empty($param["paper_title"])){
                $this->error("请填写论文名称");
            }else{
                $insert["paper_title"]      = $param["paper_title"];//论文名称
            }

            if(empty($param["periodical_title"])){
                $this->error("请填写期刊名称");
            }else{
                $insert["periodical_title"] = $param["periodical_title"];//期刊名称
            }

            if(empty($param["type"])){
                $this->error("请选择论文类型");
            }else{
                $insert["type"]             = $param["type"];//论文类型
            }

            if(empty($param["publish_time"])){
                $this->error("请选择发表日期");
            }else{
                $insert["publish_time"]     = strtotime($param["publish_time"]);//发表日期
            }

            if(empty($param["status"])){
                $this->error("请选择稿件状态");
            }else{
                $insert["status"]           = $param["status"];//稿件状态
            }

            if(empty($param["my_file"])){
                $this->error("请上传支撑材料");
            }else{
                $insert["file"]             = $param["my_file"];//支撑材料
            }

            if(empty($param["regiter_id"])){
                $this->error("参数错误");
            }else{
                $insert["regiter_id"]       = $param["regiter_id"];//项目id
                $insert["container_id"]       = Db::name("project_register")->where(['id'=>$param["regiter_id"]])->value("container_id");//容器id
            }


            $insert["author"]           =  '';//论文作者,作者ID集合
            $insert["memo"]             = $param["memo"];//备注
            $insert["createtime"]       = time();//创建时间
            $user = $this->auth;
            $insert["user_id"]              = $user->id;//备注
            $insert["username"]             = $user->nickname;//备注
            $info = Db::name('project_paper')->where(["paper_title"=>$param["paper_title"],"regiter_id"=>$param["regiter_id"]])->find();

            if($info){
                $this->error("此论文已存在,请勿重复添加");
            }


            $status = Db::name('project_paper')->insert($insert);

            if($status){
                $this->success("添加成功");
            }else{
                $this->error("添加失败");
            }
        }
        $this->assign("regiter_id",$param['regiter_id']);
        $this->assignconfig("regiter_id",$param['regiter_id']);
        return $this->view->fetch();
    }



    /**
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 根据学号或者是工号获取学生或者老师信息
     */
    public function getStudent(){
        $param = $this->request->param();
        $student =[];
        if(!isset($param['type'])){
            $param['type'] =0;
        }
        $info = Db::name("user")->field("nickname,id,student_no")->where(["student_no"=>$param['student_no']])->find();
        if(empty($info) ){
            if( $param['type'] !=1){
                $info = Db::name("teacher")->field("username,id,job_num")->where(["job_num"=>$param['student_no']])->find();
                if(!empty($info)){
                    $student["username"] = $info['username'];
                    $student["user_id"]  = $info['id'];
                    $student["number"]   = $info['job_num'];
                    $student["type"]     = 2;
                }
            }else{
                $msg = "未找到学号是".$param['student_no'].'的人';
            }
        }else{
            $student["username"] = $info['nickname'];
            $student["user_id"]  = $info['id'];
            $student["number"]   = $info['student_no'];
            $student["type"]     = 1;
        }
        if(empty($student)){
            if(empty($msg)){
                $msg =  "未找到工号或学号是".$param['student_no'].'的人';;
            }
            $this->error($msg);
        }else{
            $this->success('','',$student);
        }

    }

    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     * 删除论文
     */
    public function paperDelete(){

        $param = $this->request->param();
        $info = Db::name("project_paper")->where(['paper_id'=>$param['paper_id']])->find();

        if(!empty($info)){
            $status =  Db::name("project_paper")->where(['paper_id'=>$param['paper_id']])->delete();
            if($status){
                $this->success("操作成功");
            }else{
                $this->error("操作失败");
            }

        }else{
            $this->error("此信息不存在");
        }
    }
    /**
     * @return string
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 编辑论文
     */
    public function PaperEdit(){

        $param = $this->request->param();

        if($this->request->isAjax()){
            if(empty($param['paper_id'])){
                $this->error("参数错误");
            }
            if(empty($param["member_json"])){
                $this->error("请填写至少1个作者");
            }else{
                $insert["member_json"]      = json_encode($param["member_json"],JSON_UNESCAPED_UNICODE);//论文作者集合格式[{''user_id'':''1'',"number":''001'',''username'':''小明''}]其中number是工号,user_id是用户id,username是用户名
            }

            if(empty($param["paper_title"])){
                $this->error("请填写论文名称");
            }else{
                $insert["paper_title"]      = $param["paper_title"];//论文名称
            }

            if(empty($param["periodical_title"])){
                $this->error("请填写期刊名称");
            }else{
                $insert["periodical_title"] = $param["periodical_title"];//期刊名称
            }

            if(empty($param["type"])){
                $this->error("请选择论文类型");
            }else{
                $insert["type"]             = $param["type"];//论文类型
            }

            if(empty($param["publish_time"])){
                $this->error("请选择发表日期");
            }else{
                $insert["publish_time"]     = strtotime($param["publish_time"]);//发表日期
            }

            if(empty($param["status"])){
                $this->error("请选择稿件状态");
            }else{
                $insert["status"]           = $param["status"];//稿件状态
            }

            if(empty($param["my_file"])){
                $this->error("请上传支撑材料");
            }else{
                $insert["file"]             = $param["my_file"];//支撑材料
            }

            if(empty($param["regiter_id"])){
                $this->error("参数错误");
            }else{
                $insert["regiter_id"]       = $param["regiter_id"];//项目id
                $insert["container_id"]       = Db::name("project_register")->where(['id'=>$param["regiter_id"]])->value("container_id");//容器id
            }


            $insert["author"]           =  '';//论文作者,作者ID集合
            $insert["memo"]             = $param["memo"];//备注
            $insert["createtime"]       = time();//创建时间

            $info = Db::name('project_paper')->where(["paper_title"=>$param["paper_title"],"regiter_id"=>$param["regiter_id"]])->find();

            if($info['paper_id'] != $param['paper_id']){
                $this->error("此论文已存在,请勿重复添加");
            }

            $status = Db::name('project_paper')->where(['paper_id'=>$param['paper_id']])->update($insert);

            if($status){
                $this->success("操作成功");
            }else{
                $this->error("操作失败");
            }
        }

        $info = Db::name('project_paper')->where(["paper_id"=>$param["paper_id"]])->find();
        $info['filename'] = Db::name('attachment')->where(["url"=>$info["file"]])->value("filename");
        $this->assign("filename",$info['filename']);
        $this->assign("url",$info['file']);
        $this->assignconfig("date",date("Y-m-d",$info['publish_time']));
        $this->assignconfig("paper_id",$param['paper_id']);
        $this->assignconfig("regiter_id",$param['regiter_id']);
        $this->assign("regiter_id",$param['regiter_id']);
        return $this->view->fetch();
    }

    public function getPaperData(){
        $param = $this->request->param();
        $info = Db::name('project_paper')->where(["paper_id"=>$param["paper_id"]])->find();

        if(empty($info)){
            $this->error("此论文不存在");
        }else{
            $info['member_json'] = json_decode( $info['member_json'],true);
            $info['filename'] = Db::name('attachment')->where(["url"=>$info["file"]])->value("filename");
            $this->success('','',$info);
        }
    }
}