1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
- namespace App\Community\Controllers;
- use App\Http\Controllers\Controller;
- use App\Models\Docter;
- use App\Models\Order;
- use App\Models\Schedule;
- use App\Models\SchedulePeriod;
- use App\Models\Vaccine;
- use Illuminate\Support\Facades\DB;
- class StatController extends Controller
- {
- //疫苗统计
- public static function vaccine()
- {
- $data ['sum_num'] = Vaccine::count();
- $data['have_num'] = Vaccine::sum('stock');
- $data['less_num'] = Vaccine::where(['stock'=>0])->count();//取苗钟数
- $data['today_schedule'] = Order::where(['order_status'=>1])->where('product_type',4)->where('created_at','>',date('Y-m-d H:i:s',time()))->count();
- $data['today_vaccine'] = Order::where(['product_type'=>4])->with('orderPatient','appoint_start_time',strtotime('today'))->count();//接诊患者(人次)
- return $data;
- }
- //实时数据
- public static function service()
- {
- $data['schedule_paitent'] = Order::where(['order_status'=>1])->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('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])->count();//接诊患者(人次)
- return $data;
- }
- //儿保概况
- public static function nurse()
- {
- $nurse_num = Order::where('product_type',5)->where('created_at','>',strtotime('today'))->count();
- return $nurse_num;
- }
- //排班统计
- public static function schedule()
- {
- $ids = SchedulePeriod::where('schedule_date',date("Y-m-d"))->distinct('docter_id')->pluck('docter_id');
- $data = ['clinic_num'=>0,'vaccine_num'=>0,'nurse_num'=>0];
- if(empty($ids)){
- return $data;
- };
- $docters = Docter::whereIn('id',$ids->toArray())->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;
- }
- }
|