AdminExerciseStatisticalController.php 2.8 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2019 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Powerless < wzxaini9@gmail.com>
// +----------------------------------------------------------------------

namespace app\portal\controller;

use cmf\controller\AdminBaseController;
use app\portal\model\InspectModel;
use think\Db;
use think\db\Query;
//甲方演习统计
class AdminExerciseStatisticalController extends AdminBaseController
{

    //列表页
    public function index(){
        //查询所有项目对应的甲方公司
        $res = Db::name('project')
            ->alias('p')
            ->join('company c','p.a_cid = c.id')
            ->where(function(Query $query){
                $param = $this->request->param();

                $common = new AdminCommonController();
                $p_ids = $common->getProjectByCompanyB();
                if(!empty($p_ids)){
                    $query->whereIn('p.id',$p_ids);
                }

                //查询公司
                if (!empty($param['company_name'])) {
                    $keyword = $param['company_name'];
                    $query->where('c.company_name', 'like', "%$keyword%");
                }
                //查询项目
                if (!empty($param['project_name'])) {
                    $keyword = $param['project_name'];
                    $query->where('p.name', 'like', "%$keyword%");
                }
            })
            ->field('p.id,p.name project_name,c.company_name,c.id company_id,p.create_time')
            ->order('p.id desc')
            ->paginate(10,false,['query'=>request()->param()]);

        $common = new AdminCommonController();
        $data = $res->toArray();
        $data = $data['data'];
        foreach($data as &$value){
            //总运行时间
            $value['run_time'] = $common->runTime($value['create_time']);
            //完成次数
            $value['finish_count'] = $common->getCount('exercise',['project_id'=>$value['id'],'status'=>2]);
            //未完次次数
            $value['not_count'] = $common->getCount('exercise',['project_id'=>$value['id'],'status'=>['<>',2]]);
            //总次数
            $value['total_count'] = $common->getCount('exercise',['project_id'=>$value['id']]);
        }
        $page = $res->render();
        $this->assign('list',$data);
        $this->assign('page',$page);
        return $this->fetch();
    }

}