AdminFaultController.php
1.7 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
<?php
/**
* Created by PhpStorm.
* User: ruidiudiu
* Date: 2018/11/23
* Time: 11:57
*/
namespace app\portal\controller;
use app\portal\model\EquipmentModel;
use app\portal\model\OrderModel;
use cmf\controller\AdminBaseController;
use think\Db;
/**
* Class AdminFaultController
* @package app\portal\controller
* @adminMenuRoot(
* 'name' =>'故障统计',
* 'action' =>'index',
* 'parent' =>'',
* 'display'=> true,
* 'order' => 1,
* 'icon' =>'th',
* 'remark' =>'故障统计'
* )
*/
class AdminFaultController extends AdminBaseController{
public function index(){
$data=Db::name('fault')->alias('a')
->field('a.eq_name,b.hospital,b.serial_number')
->join('equipment b','a.eq_name=b.name')
->group('a.eq_name')
->paginate(10)->each(function ($item){
//计费故障次数
$item['fault_time']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>1])->count();
//锁故障次数
$item['fault_lock']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>3])->count();
//床故障次数
$item['fault_bed']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>2])->count();
//其他故障次数
$item['fault_other']=Db::name('fault')->where(['eq_name'=>$item['eq_name'],'fault_type'=>4])->count();
//故障总数
$item['fault']=Db::name('fault')->where(['eq_name'=>$item['eq_name']])->count();
return $item;
});
$this->assign('data',$data);
return $this->fetch();
}
}