ProjectPatent.php 10.8 KB
<?php


namespace app\index\controller;


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

class ProjectPatent 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 PatentIndex(){
        $param = $this->request->param();
        $list = Db::name("project_patent")->where(['regiter_id'=>$param['regiter_id']])->paginate(10,false,['query'=>request()->param()]);
        $this->assign("list",$list);
        $this->assign("page",$list->render());
        $this->assignconfig("regiter_id",$param['regiter_id']);
        $this->assign("regiter_id",$param['regiter_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 PatentAdd(){

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

        if($this->request->isAjax()){

            if(empty($param["patent_title"])){
                $this->error("请输入专利题名");
            }else{
                $insert["patent_title"]     = $param["patent_title"];//专利题名
            }

            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
            }
            if(empty($param["type"])){
                $this->error("请选择类型");
            }else{
                $insert["type"]             = $param["type"];//类型
            }
            if(empty($param["patent_number"])){
                $this->error("请填写申请专利号");
            }else{
                $insert["patent_number"]    = $param["patent_number"];//申请专利号
            }
            if(empty($param["patent_date"])){
                $this->error("请选择发表日期");
            }else{
                $insert["patent_date"]      = strtotime($param["patent_date"]);//发表日期
            }
            if(empty($param["grant_number"])){
                $this->error("请填写授权专利号");
            }else{
                $insert["grant_number"]     = $param["grant_number"];//授权专利号
            }
            if(empty($param["grant_date"])){
                $this->error("请选择发表日期");
            }else{
                $insert["grant_date"]       =  strtotime($param["grant_date"]);//授权日期
            }
            if(empty($param["my_file"])){
                $this->error("请上传支撑材料");
            }else{
                $insert["file"]             = $param["my_file"];//支撑材料
            }
            if(empty($param["obligee"])){
                $this->error("请输入第几权利人");
            }else{
                $insert["obligee"]          = $param["obligee"];//第几权利人
            }
            if(empty($param["applicant_json"])){
                $this->error("请至少填写一个申请者");
            }else{
                $insert["applicant_json"]          = json_encode($param["applicant_json"],JSON_UNESCAPED_UNICODE);//第几权利人
            }
            $insert["applicant"]        ='';//论文作者,作者ID集合
            $insert["memo"]             = $param["memo"];//备注
            $insert["createtime"]       = time();//创建时间
            $user = $this->auth;
            $insert["user_id"]              = $user->id;//备注
            $insert["username"]             = $user->nickname;//备注
            $info = Db::name('project_patent')->where(["patent_title"=>$param["patent_title"],"regiter_id"=>$param["regiter_id"]])->find();

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

            $status = Db::name('project_patent')->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\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     * 删除论文
     */
    public function PatentDelete(){

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

        if(!empty($info)){
            $status =  Db::name("project_patent")->where(['patent_id'=>$param['patent_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 PatentEdit(){

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

        if($this->request->isAjax()){

            if(empty($param["patent_title"])){
                $this->error("请输入专利题名");
            }else{
                $insert["patent_title"]     = $param["patent_title"];//专利题名
            }

            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
            }
            if(empty($param["type"])){
                $this->error("请选择类型");
            }else{
                $insert["type"]             = $param["type"];//类型
            }
            if(empty($param["patent_number"])){
                $this->error("请填写申请专利号");
            }else{
                $insert["patent_number"]    = $param["patent_number"];//申请专利号
            }
            if(empty($param["patent_date"])){
                $this->error("请选择发表日期");
            }else{
                $insert["patent_date"]      = strtotime($param["patent_date"]);//发表日期
            }
            if(empty($param["grant_number"])){
                $this->error("请填写授权专利号");
            }else{
                $insert["grant_number"]     = $param["grant_number"];//授权专利号
            }
            if(empty($param["grant_date"])){
                $this->error("请选择发表日期");
            }else{
                $insert["grant_date"]       =  strtotime($param["grant_date"]);//授权日期
            }
            if(empty($param["my_file"])){
                $this->error("请上传支撑材料");
            }else{
                $insert["file"]             = $param["my_file"];//支撑材料
            }
            if(empty($param["obligee"])){
                $this->error("请输入第几权利人");
            }else{
                $insert["obligee"]          = $param["obligee"];//第几权利人
            }
            if(empty($param["applicant_json"])){
                $this->error("请至少填写一个申请者");
            }else{
                $insert["applicant_json"]          = json_encode($param["applicant_json"],JSON_UNESCAPED_UNICODE);//第几权利人
            }

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

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

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

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

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

        $info = Db::name('project_patent')->where(["patent_id"=>$param["patent_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['patent_date']));
        $this->assignconfig("grant_date",date("Y-m-d",$info['grant_date']));
        $this->assignconfig("patent_id",$param['patent_id']);
        $this->assignconfig("regiter_id",$param['regiter_id']);
        $this->assign("regiter_id",$param['regiter_id']);
        return $this->view->fetch();
    }

    public function getPatentData(){
        $param = $this->request->param();
        $info = Db::name('project_patent')->where(["patent_id"=>$param["patent_id"]])->find();
        if(empty($info)){
            $this->error("此论文不存在");
        }else{
            $info['filename'] = Db::name('attachment')->where(["url"=>$info["file"]])->value("filename");
            $info['applicant_json'] = json_decode( $info['applicant_json'],true);
            $this->success('','',$info);
        }
    }

    public function isOccupy(){
        $param = $this->request->param();
        if(empty($param['number'])){
            $this->success();
        }else{
            if($param['type']==1){
                $info = Db::name('project_patent')->where(["patent_number"=>$param["number"]])->find();

                if(!empty($info)){
                    $this->error("申请专利号已存在");
                }else{
                    $this->success();
                }
            }else{
                $info = Db::name('project_patent')->where(["grant_number"=>$param["number"]])->find();

                if(!empty($info)){
                    $this->error("授权专利号已存在");
                }else{
                    $this->success();
                }
            }

        }

    }
}