123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- <?php
- namespace app\api\controller\screen;
- use app\hander\HelpHander;
- use app\api\controller\screen\Index;
- use think\Db;
- class Waste extends Index
- {
- public function cateList(){
- $type = input('type',1);
- if($type == 1){
- $map[] = ['create_yyyy','=',date('Y')];
- }else{
- $map[] = ['create_yyyymm','=',date('Ym')];
- }
- $list = Db::name('waste_type')
- ->field('id,title')
- //->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->limit(6)
- ->select();
- foreach ($list as $k=>$v){
- $record = Db::name('waste_record')
- ->where('cateid',$v['id'])
- ->where($map)
- ->where('del',0)
- ->sum('weight');
- $list[$k]['kg'] = round($record/1000,1);
- }
- HelpHander::success($list);
- }
- public function deviceList(){
- $device = Db::name('dep')
- ->alias('d')
- ->field('d.title,a.id')
- ->join('address a','a.dep_id=d.id')
- ->where('d.org_id',$this->orgId)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(7,a.types)"))
- ->where('a.del',0)
- ->where('a.enable',1)
- ->group('d.title')
- ->select();
- $cate = Db::name('waste_type')
- ->field('id,title')
- // ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- foreach ($device as $k=>$v){
- $device[$k]['kg'] = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('waste_device_id',$v['id'])
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->sum('weight');
- }
- $newList = array_slice(list_sort_by($device,'kg','desc'),0,5);
- $lists = $cateTitle = [];
- foreach ($cate as $k=>$v){
- $cateTitle[] = $v['title'];
- $aa = [];
- $lists[$k]['title'] = $v['title'];
- foreach ($newList as $kk=>$vv){
- $record = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('waste_device_id',$vv['id'])
- ->where('cateid',$v['id'])
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->sum('weight');
- $aa[] = !empty($record)? round($record/1000,1):0;
- }
- $lists[$k]['list'] = $aa;
- }
- $title = array_column($device,'title');
- // $cc = [];
- // foreach ($cateTitle as $k=>$v){
- // $cc[$k]['title'] = $v;
- // foreach ($lists as $kk=>$vv){
- // $cc[$k]['list'] = $vv;
- // }
- // }
- $data = [
- 'title'=>$title,
- 'title1'=>$cateTitle,
- 'list'=>$lists,
- ];
- HelpHander::success($data);
- }
- public function userWorkWaste(){
- $record = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->group('user_id')
- ->column('user_id');
- $lists = [];
- foreach ($record as $k=>$v){
- $list1 = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('user_id',$v)
- ->where('del',0)
- ->where('create_yyyymmdd',date('Ymd'))
- ->sum('weight');
- $lists[$k]['title'] = Db::name('user')->where('id',$v)->value('real_name');
- $lists[$k]['kg'] = round($list1/1000,1);
- }
- $endData = array_slice(list_sort_by($lists,'kg','desc'),0,5);
- $data = [
- 'title'=>array_column($endData,'title'),
- 'lists'=>array_column($endData,'kg'),
- ];
- HelpHander::success($data);
- }
- public function wasteRecord(){
- $list = Db::name('waste_record')
- ->where('del',0)
- ->where('org_id',$this->orgId)
- ->where('create_yyyymmdd',date('Ymd'))
- ->select();
- foreach ($list as $k=>$v){
- $list[$k]['device_name'] = Db::name('address')
- ->where('id',$v['waste_device_id'])
- ->value('title');
- $list[$k]['user_name'] = Db::name('user')
- ->where('id',$v['user_id'])
- ->value('real_name');
- if($v['status'] == 0){
- $list[$k]['status'] = '已收取';
- }elseif ($v['status'] == 1){
- $list[$k]['status'] = '已交接';
- }elseif ($v['status'] == 2){
- $list[$k]['status'] = '已转运';
- }else{
- $list[$k]['status'] = '医废异常';
- }
- $list[$k]['create_time'] = date('m-d H:i');
- }
- $data = [];
- foreach ($list as $k=>$v){
- $data[$k][] = $v['device_name'];
- $data[$k][] = $v['user_name'];
- $data[$k][] = $v['create_time'];
- $data[$k][] = $v['status'];
- }
- HelpHander::success($data);
- }
- public function monthCateRecord(){
- $month = input('month','');
- if($month !=''){
- if($month > 0 && $month < 10){
- $date = date('Y').'0'.$month;
- }elseif ($month >10){
- $date = date('Y').$month;
- }
- }else{
- $date = date('Ym');
- }
- // $em = cal_days_in_month(CAL_GREGORIAN,$month,date('Y'));
- $em = date('t',strtotime($date));
- $sDay = strtotime($date.'01');
- $arr = [];
- for ($i = 0;$i<$em;$i++){
- $arr[$i]['date'] = date('m-d',$sDay+$i*86400);
- $arr[$i]['ymd'] = date('Ymd',$sDay+$i*86400);
- }
- $cate = Db::name('waste_type')
- ->field('id,title')
- // ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('enable',1)
- ->select();
- $lists = $cateTitle = [];
- foreach ($cate as $k=>$v){
- $cateTitle[] = $v['title'];
- $lists[$k]['title'] = $v['title'];
- $aa = [];
- foreach ($arr as $kk=>$vv){
- $record = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('cateid',$v['id'])
- ->where('del',0)
- ->where('create_yyyymmdd',$vv['ymd'])
- ->sum('weight');
- $aa[$kk] = $record>0? round($record/1000,1):0;
- }
- $lists[$k]['list'] = $aa;
- }
- // $cc = [];
- // foreach ($cateTitle as $k=>$v){
- // $cc[$k]['title'] = $v;
- // foreach ($lists as $kk=>$vv){
- // $cc[$k]['list'] = $vv['weight'];
- // }
- // }
- $data = [
- 'date' =>array_column($arr,'date'),
- 'cate' =>$cateTitle,
- 'list'=>$lists
- ];
- HelpHander::success($data);
- }
- // 医废收取量统计 当天及30天内平均收取重量
- public function depRecord(){
- //先取30内的科室
- $curDay = date('Ymd');
- $start = date('Ymd',strtotime(date('Y-m-d')) - 29*24*60*60);
- $lists = Db::name('waste_record')
- ->alias('wr')
- ->join('address a','a.id = wr.waste_device_id')
- ->join('dep d','d.id = a.dep_id')
- ->where('wr.org_id',$this->orgId)
- ->where('wr.del',0)
- ->where('wr.create_yyyymmdd','<=',$curDay)
- ->where('wr.create_yyyymmdd','>=',$start)
- ->field('d.id,d.title')
- ->group('d.id')
- ->distinct(true)
- ->select();
- $titles = [];
- $y1 = [];
- $y2 = [];
- foreach ($lists as $k=>$v){
- $titles[] = $v['title'];
- $count1 = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('create_yyyymmdd','=',$curDay)
- ->sum('weight');
- $y1[] = round($count1/1000,1);
- $count2 = Db::name('waste_record')
- ->where('org_id',$this->orgId)
- ->where('del',0)
- ->where('create_yyyymmdd','<=',$curDay)
- ->where('create_yyyymmdd','>=',$start)
- ->sum('weight');
- $y2[] = round(($count2/1000)/30,1);
- }
- HelpHander::success(['titles' => $titles,'y1' => $y1,'y2' => $y2]);
- }
- public function depRecordList(){
- $dep = Db::name('dep')
- ->alias('d')
- ->field('d.title,a.id')
- ->join('address a','a.dep_id=d.id')
- ->where('d.org_id',$this->orgId)
- ->where('d.del',0)
- ->where('d.enable',1)
- ->where('','exp',Db::raw("FIND_IN_SET(7,a.types)"))
- ->where('a.del',0)
- ->where('a.enable',1)
- ->group('d.title')
- ->limit(5)
- ->select();
- $x = $y1 = $y2 = [];
- foreach ($dep as $k=>$v){
- $x[] = $v['title'];
- $record = Db::name('waste_record')
- ->where('waste_device_id',$v['id'])
- ->where('create_yyyymmdd',date('Ymd'))
- ->where('del',0)
- ->sum('weight');
- $y1[] = round($record/1000,1);
- $record2 = Db::name('waste_record')
- ->where('waste_device_id',$v['id'])
- ->where('create_yyyymmdd','>',date("Ymd",mktime(0,0,0,date("m")-1,date("d"),date("Y"))))
- ->where('create_yyyymmdd','<=',date('Ymd'))
- ->where('del',0)
- ->sum('weight');
- $y2[] = round($record2/1000/30,1);
- }
- HelpHander::success(['x'=>$x,'y1'=>$y1,'y2'=>$y2]);
- }
- }
|