|
@@ -1285,6 +1285,256 @@ class WasteStatistics extends Auth {
|
|
|
echo $res;
|
|
|
}
|
|
|
|
|
|
+ //科室月统计
|
|
|
+ public function wasteDeviceMonth() {
|
|
|
+ $month = input('start',date('Y-m'));
|
|
|
+ $addr_id = input('addr_id','');
|
|
|
+ $type_id = input('type_id','');
|
|
|
+
|
|
|
+ $addressList = (new \app\common\model\Address())->getListByType(7,$this->orgId);
|
|
|
+
|
|
|
+ $tMap[] = ['del','=',0];
|
|
|
+ $tMap[] = ['enable','=',1];
|
|
|
+ //$tMap[] = ['org_id','=',$this->orgId];
|
|
|
+ $typeList1 = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->field('id,title')
|
|
|
+ ->select();
|
|
|
+ if($type_id!=''){
|
|
|
+ $tMap[] = ['id','in',explode(',',$type_id)];
|
|
|
+ $typeList = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->field('id,title,type')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $typeList = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->field('id,title,type')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = $this->wasteDeviceMonthData($month,$addr_id,$type_id);
|
|
|
+
|
|
|
+ $this->assign('data',$data['list']);
|
|
|
+ $this->assign('typeList',$typeList);
|
|
|
+ $this->assign('typeList1',$typeList1);
|
|
|
+ $this->assign('addressList',$addressList);
|
|
|
+ $this->assign('start',$month);
|
|
|
+ $this->assign('addr_id',$addr_id?explode(',',$addr_id):[]);
|
|
|
+ $this->assign('type_id',$type_id?explode(',',$type_id):[]);
|
|
|
+ return $this->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ public function wasteDeviceMonthData($month,$addr_id,$type_id){
|
|
|
+
|
|
|
+ $org_id = $this->orgId;
|
|
|
+ $aMap = [];
|
|
|
+ if($addr_id!=''){
|
|
|
+ $aMap[] = ['id','in',explode(',',$addr_id)];
|
|
|
+ }
|
|
|
+ $aMap[]=['','exp',Db::raw("FIND_IN_SET(7,types)")];
|
|
|
+ $dep = Db::name('address')
|
|
|
+ ->where('org_id',$org_id)
|
|
|
+ ->where('enable',1)
|
|
|
+ ->where('del',0)
|
|
|
+ ->where($aMap)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $tMap = [];
|
|
|
+ if($type_id!=''){
|
|
|
+ $tMap[] = ['id','in',explode(',',$type_id)];
|
|
|
+ }
|
|
|
+
|
|
|
+ $type = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->where('enable',1)
|
|
|
+ ->where('del',0)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+
|
|
|
+ $date = date('Ym',strtotime($month));
|
|
|
+ $tnum = $tkg = 0;
|
|
|
+
|
|
|
+ $records = Db::name('waste_record')
|
|
|
+ ->where('org_id',$org_id)
|
|
|
+ ->where('del',0)
|
|
|
+ ->where('create_yyyymm',$date)
|
|
|
+ ->field('waste_device_id,cateid,weight,num')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ foreach ($dep as $k=>$v){
|
|
|
+ $ttkg = $ttnums = 0;
|
|
|
+ foreach ($type as $k1=>$v1){
|
|
|
+
|
|
|
+ $datas = 0;
|
|
|
+ $totals = 0;
|
|
|
+ $weight = 0;
|
|
|
+ $weight2 = 0;
|
|
|
+ $ttnums = 0;
|
|
|
+ $totalkg = 0;
|
|
|
+ $num = '';
|
|
|
+ $totalNum = 0;
|
|
|
+ $num2 = '';
|
|
|
+ $totalNum2 = 0;
|
|
|
+ foreach ($records as $rk=>$rv){
|
|
|
+ if($rv['waste_device_id'] == $v['id'] && $rv['cateid'] == $v1['id']){
|
|
|
+ $datas++;
|
|
|
+ $weight += $rv['weight'];
|
|
|
+// $weight2 += $rv['weight'];
|
|
|
+
|
|
|
+ if($v1['type'] == 1){
|
|
|
+ $totalNum += $rv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($rv['cateid'] == $v1['id']){
|
|
|
+ if($addr_id!=''){
|
|
|
+ $addr_ids = explode(',',$addr_id);
|
|
|
+ if(in_array($rv['waste_device_id'],$addr_ids)){
|
|
|
+ $totals++;
|
|
|
+ $weight2 += $rv['weight'];
|
|
|
+ if($v1['type'] == 1){
|
|
|
+ $totalNum2 += $rv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $totals++;
|
|
|
+ $weight2 += $rv['weight'];
|
|
|
+ if($v1['type'] == 1){
|
|
|
+ $totalNum2 += $rv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if($rv['waste_device_id'] == $v['id']){
|
|
|
+ if($addr_id!=''){
|
|
|
+ $addr_ids = explode(',',$addr_id);
|
|
|
+ if(in_array($rv['waste_device_id'],$addr_ids)){
|
|
|
+ $ttnums++;
|
|
|
+ $totalkg += $rv['weight'];
|
|
|
+ if($v1['type'] == 1){
|
|
|
+ $totalNum2 += $rv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ $ttnums++;
|
|
|
+ $totalkg += $rv['weight'];
|
|
|
+ if($v1['type'] == 1){
|
|
|
+ $totalNum2 += $rv['num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $dep[$k]['data'][] = $datas;
|
|
|
+ $dep[$k]['total'][] = $totals;
|
|
|
+// $dep[$k]['data'][] = $weight?round($weight/1000,2):0;
|
|
|
+// $dep[$k]['total'][] = $weight2?round($weight2/1000,2):0;
|
|
|
+ $dep[$k]['nums'] = $ttnums;
|
|
|
+ $ttkg = $totalkg?round($totalkg/1000,3):0;
|
|
|
+ $dep[$k]['totalkg'] = $ttkg;
|
|
|
+
|
|
|
+ $we = $weight?round($weight/1000,3):0;
|
|
|
+
|
|
|
+ if($totalNum > 0){
|
|
|
+ $num = '('.$totalNum.$v1['unit'].')';
|
|
|
+ }
|
|
|
+ $dep[$k]['data'][] = $we.$num;
|
|
|
+
|
|
|
+ $we2 = $weight2?round($weight2/1000,3):0;
|
|
|
+ if($totalNum2 > 0){
|
|
|
+ $num2 = '('.$totalNum2.$v1['unit'].')';
|
|
|
+ }
|
|
|
+ $dep[$k]['total'][] =$we2.$num2;
|
|
|
+
|
|
|
+ }
|
|
|
+ $tnum += $ttnums;
|
|
|
+ $tkg += $ttkg;
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'list'=>$dep,
|
|
|
+ 'tnum'=>$tnum,
|
|
|
+ 'tkg'=>$tkg,
|
|
|
+ ];
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function wasteDeviceMonthExport()
|
|
|
+ {
|
|
|
+ set_time_limit(0);
|
|
|
+ ini_set("memory_limit", "1024M");
|
|
|
+ $month = input('start',date('Y-m-d'));
|
|
|
+ $addr_id = input('addr_id','');
|
|
|
+ $type_id = input('type_id','');
|
|
|
+ $data = $this->wasteDeviceMonthData($month,$addr_id,$type_id);
|
|
|
+ $data = $data['list'];
|
|
|
+ $tMap[] = ['del','=',0];
|
|
|
+ $tMap[] = ['enable','=',1];
|
|
|
+ if($type_id!=''){
|
|
|
+ $tMap[] = ['id','in',explode(',',$type_id)];
|
|
|
+ $type = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->field('id,title,type')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ }else{
|
|
|
+ $type = Db::name('waste_type')
|
|
|
+ ->where($tMap)
|
|
|
+ ->field('id,title,type')
|
|
|
+ ->select();
|
|
|
+ }
|
|
|
+
|
|
|
+ $title = '科室月统计';
|
|
|
+ if(!empty($month)){
|
|
|
+ $title = $month.'科室月统计';
|
|
|
+
|
|
|
+ }
|
|
|
+ header("Content-type: application/vnd.ms-excel");
|
|
|
+ header("Content-Type: application/force-download");
|
|
|
+ header("Content-Disposition: attachment; filename=".$title.".xls");
|
|
|
+ header('Expires:0');
|
|
|
+ header('Pragma:public');
|
|
|
+ $res = '';
|
|
|
+ $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
|
|
|
+ $res.='<tr style="background: #ffffff;">
|
|
|
+ <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="2">地点</th>';
|
|
|
+ foreach ($type as $k=>$v){
|
|
|
+ $res.=' <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" colspan="2">'.$v['title'].'</th>';
|
|
|
+
|
|
|
+ }
|
|
|
+ $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="2">备注</th>';
|
|
|
+ $res.='<tr style="background: #ffffff;">';
|
|
|
+ foreach ($type as $v){
|
|
|
+ $res.=' <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">件数/包</th>
|
|
|
+ <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">重量kg</th>';
|
|
|
+ }
|
|
|
+ foreach ($data as $k=>$v){
|
|
|
+ $res.='<tr style="background: #ffffff;">';
|
|
|
+ $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['title'].'</td>';
|
|
|
+ foreach ($v['data'] as $k1=>$v1){
|
|
|
+ $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
|
|
|
+ }
|
|
|
+ $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd"></td>';
|
|
|
+ $res.='</tr>';
|
|
|
+
|
|
|
+ }
|
|
|
+ $res.='<tr style="background: #ffffff;">
|
|
|
+ <td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">共计:</td>';
|
|
|
+ if(!empty($data)){
|
|
|
+ foreach ($data[0]['total'] as $k1=>$v1){
|
|
|
+ $res.=' <td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $res.='<td style="border-bottom: 1px solid #ddd;border-right: 1px solid #ddd"></td>
|
|
|
+ </tr>';
|
|
|
+ echo $res;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
// 医废年统计
|
|
|
public function wasteYears() {
|
|
|
$month = input('start',date('Y'));
|