whereAge('>', 80)->count(); //61-80岁 $num2 = InformationUsermsg::where($where)->whereAge('<=', 80)->whereAge('>', 60)->count(); //36-60岁 $num3 = InformationUsermsg::where($where)->whereAge('<=', 60)->whereAge('>=', 36)->count(); //18-35岁 $num4 = InformationUsermsg::where($where)->whereAge('<', 36)->whereAge('>', 17)->count(); //0-17岁 $num5 = InformationUsermsg::where($where)->whereAge('<', 18)->count(); $return = [ ['value'=>$num1,'name'=>'80岁以上'], ['value'=>$num2,'name'=>'61-80岁'], ['value'=>$num3,'name'=>'36-60岁'], ['value'=>$num4,'name'=>'18-35岁'], ['value'=>$num5,'name'=>'0-17岁'] ]; $this->success('获取成功',$return); } //人群关爱(特困人员、高龄老人、低保人员、空巢老人、残疾人员、留守儿童) public function get_people2($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 特困人员 $num1 = InformationUsermsg::where($where)->whereAge('>', 80)->count(); //高龄老人 $num2 = InformationUsermsg::where($where)->whereAge('>', 80)->count(); //空巢老人 $num4 = InformationUsermsg::where($where)->whereAge('<=', 80)->whereAge('>', 60)->count(); //留守儿童 $num6 = InformationUsermsg::where($where)->whereAge('<', 18)->count(); foreach ($where as $key =>$value){ $where[$key][0] = 'm.'.$value[0]; } //低保人员 $num3 = Db::name('szxc_information_usermsg') ->alias('m') ->where($where) ->join('szxc_information_insurance i','m.user_id=i.user_id and i.insurance_type!=219')->count(); //残疾人员 $num5 = Db::name('szxc_information_usermsg') ->alias('m') ->where($where) ->join('szxc_information_insurance i','m.user_id=i.user_id and i.whether_disabled!=112')->count(); $return = [ ['value'=>$num1,'name'=>'特困人员'], ['value'=>$num2,'name'=>'高龄老人'], ['value'=>$num3,'name'=>'空巢老人'], ['value'=>$num4,'name'=>'留守儿童'], ['value'=>$num5,'name'=>'低保人员'], ['value'=>$num6,'name'=>'残疾人员'] ]; $this->success('获取成功',$return); } //事项办理(待办事项、延期待办、总计办理、办理结率) public function get_num($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['county', '=', $area_id]; } if ($street_id){ $where[] = ['township', '=', $street_id]; } if ($village_id){ $where[] = ['village', '=', $village_id]; } $model = new Article(); // 待办事项 $shuqiu = $model->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','>', date('Y-m-d h:i:s'))->count(); // 延期待办 $time = $model->where('is_solve', 0)->where($where)->where('category_id', 'in',[165,150,149,148,147])->whereTime('end_time','<=', date('Y-m-d h:i:s'))->count(); // 总计办理 $is_solve = $model->where('is_solve', 1)->where($where)->count(); if($is_solve){ // 办理结率 $num4 = ($is_solve-$shuqiu-$time)/$is_solve; }else{ $num4 = 0; } $num4 = round($num4*100,2).'%'; $return = [ ['value'=>$shuqiu,'name'=>'待办事项'], ['value'=>$time,'name'=>'延期待办'], ['value'=>$is_solve,'name'=>'总计办理'], ['value'=>$num4,'name'=>'办理结率'] ]; $this->success('获取成功',$return); } //资产情况(总耕地面积、人均耕地面积、退林还耕面积、种植物种类、养殖物种类) public function get_num2($area_id=0,$street_id=0,$village_id=0){ $where = $map = []; if ($area_id){ $where[] = ['b.area_id', '=', $area_id]; $map[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['b.street_id', '=', $street_id]; $map[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['b.village_id', '=', $village_id]; $map[] = ['village_id', '=', $village_id]; } // 总耕地面积 $num1 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where($where)->sum('land_area'); //人均耕地面积 $all = InformationUsermsg::where($map)->whereStatus('=', 1)->count(); if($all){ $num2 = $num1/$all; }else{ $num2 = 0; } //退林还耕面积 $num3 = $num1*0.3; //种植物种类 $num4 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where($where)->column('crops_msg'); $a = 0; foreach ($num4 as $k=>$v){ $v = json_decode($v,true); $v = array_filter(array_column($v,'name')); $v = array_filter($v); $a = $a + count($v); } $num4 = $a; //养殖物种类 $num5 = 12; $return = [ ['value'=>$num1,'name'=>'总耕地面积'], ['value'=>$num2,'name'=>'人均耕地面积'], ['value'=>$num3,'name'=>'退林还耕面积'], ['value'=>$num4,'name'=>'种植物种类'], ['value'=>$num5,'name'=>'养殖物种类'] ]; $this->success('获取成功',$return); } //消费数据(农资消费总计、食品消费总计、衣着消费总计、居住消费总计、生活用品及服务总计、交通通信总计、教育文化娱乐总计、医疗服务总计) public function get_num3($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 农资消费总计 $num1 = 3687; // 食品消费总计 $num2 = 42222; // 衣着消费总计 $num3 = 25841; // 居住消费总计 $num4 = 84511; // 生活用品及服务总计 $num5 = 4254; // 交通通信总计 $num6 = 12631; // 教育文化娱乐总计 $num7 = 8571; //医疗服务总计 $num8 = 63541; $return = [ ['value'=>$num1,'name'=>'农资消费总计'], ['value'=>$num2,'name'=>'食品消费总计'], ['value'=>$num3,'name'=>'衣着消费总计'], ['value'=>$num4,'name'=>'居住消费总计'], ['value'=>$num5,'name'=>'生活用品及服务总计'], ['value'=>$num6,'name'=>'交通通信总计'], ['value'=>$num7,'name'=>'教育文化娱乐总计'], ['value'=>$num8,'name'=>'医疗服务总计'] ]; $this->success('获取成功',$return); } //收入构成(工资性收入、生产经营性收入、财产性收入、保险性收入) public function get_num4($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 工资性收入 $num1 = 12; // 生产经营性收入 $num2 = 123; // 财产性收入 $num3 = 124; // 保险性收入 $num4 = 125; $return = [ ['value'=>$num1,'name'=>'工资性收入'], ['value'=>$num2,'name'=>'生产经营性收入'], ['value'=>$num3,'name'=>'财产性收入'], ['value'=>$num4,'name'=>'保险性收入'] ]; $this->success('获取成功',$return); } //土地性质(园地 //耕地 //林地 //牧草地 //养殖 //坑塘 //农田水利设施用地) public function get_num5($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['b.area_id', '=', $area_id]; } if ($street_id){ $where[] = ['b.street_id', '=', $street_id]; } if ($village_id){ $where[] = ['b.village_id', '=', $village_id]; } // 总耕地面积 $num1 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',70)->where($where)->sum('land_area'); //园地 $num2 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',69)->where($where)->sum('land_area'); //林地 $num3 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',214)->where($where)->sum('land_area'); //牧草地 $num4 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',215)->where($where)->sum('land_area'); //养殖 $num5 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',216)->where($where)->sum('land_area'); //坑塘 $num6 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',217)->where($where)->sum('land_area'); //农田水利设施用地 $num7 = Db::name('szxc_information_planting')->alias('a')->join('szxc_information_usermsg b','a.user_id = b.user_id')->where('nature_of_land',218)->where($where)->sum('land_area'); $return = [ ['value'=>$num1,'name'=>'耕地面积'], ['value'=>$num2,'name'=>'园地'], ['value'=>$num3,'name'=>'林地'], ['value'=>$num4,'name'=>'牧草地'], ['value'=>$num5,'name'=>'养殖'], ['value'=>$num6,'name'=>'坑塘'], ['value'=>$num7,'name'=>'农田水利设施用地'] ]; $this->success('获取成功',$return); } //文化程度( //文盲及半文盲 //小学 //初中 //高中/技校/中专 //大学专科及以上 //不详) public function get_num6($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 文盲及半文盲 $num1 = Db::name('szxc_information_usermsg')->where('education',71)->where($where)->count(); //小学 $num2 = Db::name('szxc_information_usermsg')->where('education',72)->where($where)->count(); //初中 $num3 = Db::name('szxc_information_usermsg')->where('education',73)->where($where)->count(); //高中/技校/中专 $num4 = Db::name('szxc_information_usermsg')->where('education',74)->where($where)->count(); //大学专科及以上 $num5 = Db::name('szxc_information_usermsg')->where('education',75)->where($where)->count(); //不详 $num6 = Db::name('szxc_information_usermsg')->where('education',76)->where($where)->count(); $return = [ ['value'=>$num1,'name'=>'文盲及半文盲'], ['value'=>$num2,'name'=>'小学'], ['value'=>$num3,'name'=>'初中'], ['value'=>$num4,'name'=>'高中/技校/中专'], ['value'=>$num5,'name'=>'大学专科及以上'], ['value'=>$num6,'name'=>'不详'], ]; $this->success('获取成功',$return); } //政治面貌( //群众 //团员 //党员 //预备役) public function get_num7($area_id=0,$street_id=0,$village_id=0){ $where = []; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 群众 $num1 = Db::name('szxc_information_usermsg')->where('political_outlook',2)->where($where)->count(); //团员 $num2 = Db::name('szxc_information_usermsg')->where('political_outlook',3)->where($where)->count(); //党员 $num3 = Db::name('szxc_information_usermsg')->where('political_outlook',4)->where($where)->count(); //预备役 $num4 = Db::name('szxc_information_usermsg')->where('political_outlook',177)->where($where)->count(); $return = [ ['value'=>$num1,'name'=>'群众'], ['value'=>$num2,'name'=>'团员'], ['value'=>$num3,'name'=>'党员'], ['value'=>$num4,'name'=>'预备役'], ]; $this->success('获取成功',$return); } //优秀村民 public function get_num8($area_id=0,$street_id=0,$village_id=0){ $where[] = ['user_id','in','1,3,5']; if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } // 群众 $return = Db::name('szxc_information_usermsg') ->field('name,age,address_name as address,gender') ->where($where) ->withAttr('gender', function ($value, $data) { if($value == 1){ return '男'; }elseif($value == 2){ return '女'; }else{ return '暂无'; } }) ->select(); $this->success('获取成功',$return); } //是否参保 public function get_num9($area_id=0,$street_id=0,$village_id=0){ if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } $return = [ ['yi'=>346], ['wei'=>30], ['type' => [['value'=>30,'name'=>'未参保'], ['value'=>60,'name'=>'低保'], ['value'=>45,'name'=>'城乡居民基本医保'], ['value'=>77,'name'=>'新农合'], ['value'=>82,'name'=>'城镇居民医保'], ['value'=>62,'name'=>'职工医保'], ['value'=>20,'name'=>'其他']] ] ]; $this->success('获取成功',$return); } //农业结构 public function get_num10($area_id=0,$street_id=0,$village_id=0){ if ($area_id){ $where[] = ['area_id', '=', $area_id]; } if ($street_id){ $where[] = ['street_id', '=', $street_id]; } if ($village_id){ $where[] = ['village_id', '=', $village_id]; } $return = [ ['value'=>135,'name'=>'萝卜'], ['value'=>24,'name'=>'白菜'], ['value'=>87,'name'=>'芋头'], ['value'=>51,'name'=>'地瓜'], ['value'=>102,'name'=>'土豆'], ['value'=>24,'name'=>'山药'], ]; $this->success('获取成功',$return); } }