AdminExerciseStatisticalController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?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();
}
}