org_id; } //疫苗预约 public static function vaccine() { $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } $order = Order::where(['product_type'=>4])->where($where); $oneday = strtotime(date('Y-m-d 00:00:00',strtotime('+1 days'))); $twoday = strtotime(date('Y-m-d 00:00:00',strtotime('+2 days'))); $beforeoneday = strtotime(date('Y-m-d 00:00:00',strtotime('-1 days'))); //今日预约 if ($org_id) { $today = Order::where(['product_type'=>4]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[strtotime('today'),strtotime(date('Y-m-d 00:00:00',strtotime('+1 days')))]) ->count(); $tomorrow = Order::where(['product_type'=>4]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[$oneday,$twoday]) ->count(); $people = Order::where(['product_type'=>4]) ->where('organization_id',$org_id) ->whereBetween('end_time',[$beforeoneday,strtotime('today')]) ->where('order_status',4)->count(); $yesterday = Order::where(['product_type'=>4]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[$beforeoneday,strtotime(date('Y-m-d 00:00:00',strtotime('today')))]) ->count(); }else{ $today = Order::where(['product_type'=>4]) ->whereBetween('appoint_start_time',[strtotime('today'),strtotime(date('Y-m-d 00:00:00',strtotime('+1 days')))]) ->count(); $tomorrow = Order::where(['product_type'=>4]) ->whereBetween('appoint_start_time',[$oneday,$twoday]) ->count(); $people = Order::where(['product_type'=>4])->whereBetween('end_time',[$beforeoneday,strtotime('today')])->where('order_status',4)->count(); $yesterday = Order::where(['product_type'=>4]) ->whereBetween('appoint_start_time',[$beforeoneday,strtotime(date('Y-m-d 00:00:00',strtotime('today')))]) ->count(); } $data['today'] = $today; $data['yesterday'] = $yesterday; $data['people'] = $people; $data['tomorrow'] = $tomorrow; // $data ['sum_num'] = Vaccine::where($where)->count(); // $data['have_num'] = Vaccine::where($where)->sum('stock'); // $data['less_num'] = Vaccine::where($where)->where(['stock'=>0])->count();//取苗钟数 // $data['today_schedule'] = Order::where(['order_status'=>1])->where($where)->where('product_type',4)->where('created_at','>',date('Y-m-d H:i:s',time()))->count(); // $data['today_vaccine'] = Order::where(['product_type'=>4])->where($where)->with('orderPatient','appoint_start_time',strtotime('today'))->count();//接诊患者(人次) return $data; } //儿保 public static function nurse() { $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } $order = Order::where(['product_type'=>5])->where($where); $oneday = strtotime(date('Y-m-d 00:00:00',strtotime('+1 days'))); $twoday = strtotime(date('Y-m-d 00:00:00',strtotime('+2 days'))); $beforeoneday = strtotime(date('Y-m-d 00:00:00',strtotime('-1 days'))); if ($org_id) { //今日预约 $today = Order::where(['product_type'=>5]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[strtotime('today'),strtotime('+1days')]) ->count(); //明日预约 $tomorrow = Order::where(['product_type'=>5]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[$oneday,$twoday]) ->count(); //昨日服务人数 $people = Order::where(['product_type'=>5]) ->where('organization_id',$org_id) ->whereBetween('end_time',[$beforeoneday,strtotime('today')])->where('order_status',4)->count(); //昨日预约 $yesterday = Order::where(['product_type'=>5]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[$beforeoneday,date('Y-m-d 00:00:00',strtotime('today'))]) ->count(); }else{ //今日预约 $today = Order::where(['product_type'=>5]) ->whereBetween('appoint_start_time',[strtotime('today'),$oneday]) ->count(); //明日预约 $tomorrow = Order::where(['product_type'=>5]) ->whereBetween('appoint_start_time',[$oneday,$twoday]) ->count(); //昨日服务人数 $people = Order::where(['product_type'=>5]) ->whereBetween('end_time',[$beforeoneday,strtotime('today')])->where('order_status',4)->count(); //昨日预约 $yesterday = Order::where(['product_type'=>5]) ->whereBetween('appoint_start_time',[$beforeoneday,strtotime(date('Y-m-d 00:00:00',strtotime('today')))]) ->count(); } $data['today'] = $today; $data['tomorrow'] = $tomorrow; $data['people'] = $people; $data['yesterday'] = $yesterday; return $data; } //疫苗统计 public static function vaccineToal() { $where = []; $another = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; $another['org_id'] = $org_id; } $oneday = strtotime(date('Y-m-d 00:00:00',strtotime('+1 days'))); $twoday = strtotime(date('Y-m-d 00:00:00',strtotime('+2 days'))); $beforeoneday = strtotime(date('Y-m-d 00:00:00',strtotime('-1 days'))); $data['have_num'] = Vaccine::where($another)->sum('stock'); //疫苗库存总数 $data['less_num'] = Vaccine::where($another)->where(['stock'=>10])->count();//缺苗钟数 if ($org_id) { $ids = Order::where(['product_type'=>4]) ->where('organization_id',$org_id) ->whereBetween('appoint_start_time',[$beforeoneday,strtotime('today')]) ->where('order_status',4) ->pluck('id')->toArray(); }else { $ids = Order::where(['product_type'=>4]) ->whereBetween('appoint_start_time',[$beforeoneday,strtotime('today')]) ->where('order_status',4) ->pluck('id')->toArray(); } $data['yesterday']= OrderVaccine::whereIn('order_id',$ids)->count(); //疫苗订单总数 return $data; } //实时数据 public static function service() { $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } $data['schedule_paitent'] = Order::where(['order_status'=>1])->where($where)->whereIn('product_type',[3,4,5])->where('created_at','>',date('Y-m-d H:i:s',time()))->count(); $data['schedule_docter'] = SchedulePeriod::distinct('docter_id')->where($where)->where('schedule_date',date('Y-m-d H:i:s',time()))->count(); // $data['paitent_num'] = Order::where(['order_status'=>1])->distinct()->count()->BgroupBy('patient_id'); $data['paitent_num'] = Order::whereHas('orderPatient',function ($query){ $query->where(['appoint_start_time'=>strtotime('today')]); })->where(['product_type'=>4])->where($where)->count();//接诊患者(人次) return $data; } //订单概况 public static function orderTotal() { //3.门诊预约 4.疫苗接种预约 5.儿保预约 $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } //todo 是否需要区别状态 $order_num[] = Order::where('product_type',3)->where($where)->where('payment_status','!=',1)->count(); $order_num[] = Order::where('product_type',4)->where($where)->count(); $order_num[] = Order::where('product_type',5)->where($where)->count(); $order_num[] = Order::whereIn('product_type',[3,4,5])->where($where)->count(); return $order_num; } //排班统计 public static function schedule() { $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } $ids = SchedulePeriod::where('schedule_date',date("Y-m-d"))->where($where)->distinct('docter_id')->pluck('docter_id')->toArray(); $data = ['clinic_num'=>0,'vaccine_num'=>0,'nurse_num'=>0]; if(empty($ids)){ return $data; }; $docters = Docter::whereIn('id',$ids)->get(['id','type'])->GroupBy('type'); foreach ($docters as $key => $val){ if($key === 1){ $data['clinic_num'] = count($val); } else if($key == 2){ $data['vaccine_num'] = count($val); } else if($key == 3){ $data['nurse_num'] = count($val); } } return $data; } //门诊统计 public static function clinc() { $where = []; $org_id = Admin::user()->org_id; if($org_id){ $where['organization_id']=$org_id; } $order = Order::where(['product_type'=>3])->where($where); //今日预约数 $today = $order->whereHas('orderPatient',function ($query){ $query->whereBetween('appoint_start_time',[strtotime('today'),strtotime('+1 days')]); })->count(); //医生排班人数 $docters = SchedulePeriod::where(['schedule_date'=>date('Y-m-d',time()),'schedule_type'=>1])->where($where)->distinct('docter_id')->count(); //昨日预约 $yesterday = $order->whereHas('orderPatient',function ($query){ $query->whereBetween('appoint_start_time',[date('Y-m-d',strtotime('-1 days')),date('Y-m-d',strtotime('today'))]); })->whereNotIn('order_status',[1,5,6])->count(); //昨日接诊人数 $people= $order->whereBetween('end_time',[strtotime('-1days'),strtotime('today')])->where('order_status',4)->count(); $data['today'] = $today; $data['docters'] = $docters; $data['yesterday'] = $yesterday; $data['people'] = $people; return $data; } }