ProjectResult.php 7.2 KB
<?php

namespace app\school\controller\project_conclusion;

use app\common\controller\DoubleBase;
use app\school\model\project_common\ProjectResult as ProjectResultClass;
use think\Db;

class ProjectResult extends DoubleBase
{
    protected $containerId = null;
    protected $model = null;
    protected $shopIdAutoCondition = false;

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


    public function index() {

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

    /**
     * 根据成果类型,返回项目成果数据
     * @return array
     */
    public function data()
    {
        if ($this->request->isAjax()) {
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $resultType = $this->request->param('result_type');
//            $dataWhere = ['project_container_id' => $this->containerId, 'result_type' => $resultType];
//            $total = $this->model->where($where)->where($dataWhere)->count();
//            $rows = $this->model->where($where)->where($dataWhere)->limit($offset, $limit)->select();

            switch ($resultType){
                case 'winning':
                    $res = $this->getWinning();
                    break;
                case 'paper':
                    $res = $this->getPaper();
                    break;
                case 'patent':
                    $res = $this->getPatent();
                    break;
                case 'copyright':
                    $res = $this->getCopyright();
                    break;
                case 'physical':
                    $res = $this->getPhysical();
                    break;
            }
            // todo
            // 需要将rows里的result_data字段从json转换为数组,并与row合并

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

            return $res;
        }
    }

    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 竞赛获奖情况
     */
    public function getWinning(){
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $dataWhere = ['container_id' => $this->containerId];
        $total = Db::name("project_competition")->where($where)->where($dataWhere)->count();
        $rows  = Db::name("project_competition")->where($where)->where($dataWhere)->limit($offset, $limit)->select();

        foreach ($rows as $k=>$v){
            $v['id'] = $v['competition_id'];
            $v['students'] = json_decode($v['student_json'],true);
            $v['project_name'] =  Db::name('project_register')->where('id',$v["regiter_id"])->value("project_name");
            $v['reward_date'] = date("Y-m-d",$v['reward_date']);
            $rows[$k] = $v;
        }

        return [
            'total' => $total,
            'rows' => $rows
        ];
    }
    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 论文发表情况
     */
    public function getPaper(){
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $dataWhere = ['container_id' => $this->containerId];
        $total = Db::name("project_paper")->where($where)->where($dataWhere)->count();
        $rows  = Db::name("project_paper")->where($where)->where($dataWhere)->limit($offset, $limit)->select();
        foreach ($rows as $k=>$v){
            $v['id'] = $v['paper_id'];
            $v['member_json'] = json_decode($v['member_json'],true);
            $v['project_name'] =  Db::name('project_register')->where('id',$v["regiter_id"])->value("project_name");
            $v['publish_time'] = date("Y-m-d",$v['publish_time']);
            $rows[$k] = $v;
        }
        return [
            'total' => $total,
            'rows' => $rows
        ];
    }
    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 申请专利
     */
    public function getPatent(){
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $dataWhere = ['container_id' => $this->containerId];
        $total = Db::name("project_patent")->where($where)->where($dataWhere)->count();
        $rows  = Db::name("project_patent")->where($where)->where($dataWhere)->limit($offset, $limit)->select();
        foreach ($rows as $k=>$v){
            $v['id'] = $v['patent_id'];
            $v['applicant_json'] = json_decode($v['applicant_json'],true);
            $v['project_name'] =  Db::name('project_register')->where('id',$v["regiter_id"])->value("project_name");
            $v['patent_date'] = date("Y-m-d",$v['patent_date']);
            $v['grant_date']  = date("Y-m-d",$v['grant_date']);
            $rows[$k] = $v;
        }
        return [
            'total' => $total,
            'rows' => $rows
        ];
    }
    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 申请著作权情况
     */
    public function getCopyright(){
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $dataWhere = ['container_id' => $this->containerId];
        $total = Db::name("project_copyright")->where($where)->where($dataWhere)->count();
        $rows  = Db::name("project_copyright")->where($where)->where($dataWhere)->limit($offset, $limit)->select();
        foreach ($rows as $k=>$v){
            $v['id'] = $v['copyright_id'];
            $v['applicant_json'] = json_decode($v['applicant_json'],true);
            $v['project_name'] =  Db::name('project_register')->where('id',$v["regiter_id"])->value("project_name");
            $v['registration_date'] = date("Y-m-d",$v['registration_date']);
            $rows[$k] = $v;
        }
        return [
            'total' => $total,
            'rows' => $rows
        ];
    }
    /**
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * 实物制作情况
     */
    public function getPhysical(){
        list($where, $sort, $order, $offset, $limit) = $this->buildparams();
        $dataWhere = ['container_id' => $this->containerId];
        $total = Db::name("project_production")->where($where)->where($dataWhere)->count();
        $rows  = Db::name("project_production")->where($where)->where($dataWhere)->limit($offset, $limit)->select();
        foreach ($rows as $k=>$v){
            $v['id'] = $v['production_id'];
            $v['project_name'] =  Db::name('project_register')->where('id',$v["regiter_id"])->value("project_name");

            $rows[$k] = $v;
        }
        return [
            'total' => $total,
            'rows' => $rows
        ];
    }

}