Explorar o código

更新数据中心统计数据不一致的问题

ChenWuJie %!s(int64=4) %!d(string=hai) anos
pai
achega
bee8466c92

+ 21 - 18
app/Community/Controllers/HomeController.php

xqd xqd xqd
@@ -33,7 +33,7 @@ class HomeController extends Controller
                 $data = StatController::orderTotal();
                 $row->column(3,new InfoBox('门诊订单总数(个)', 'users', 'aqua', '/cdms/orders', $data[0]));
                 $row->column(3,new InfoBox('计免订单总数(个)', 'user', 'aqua', '/cdms/order_vaccines', $data[1]));
-                $row->column(3,new InfoBox('儿保订单总数(个)', 'calendar-check-o', 'aqua', '/cdms/order_nuurse', $data[2]));
+                $row->column(3,new InfoBox('儿保订单总数(个)', 'calendar-check-o', 'aqua', '/cdms/order_nurses', $data[2]));
                 $row->column(3,new InfoBox('服务患者次数(次)', 'user', 'aqua', '/cdms/home', $data[3]));
             })
             ->row(function (Row $row){
@@ -54,33 +54,37 @@ class HomeController extends Controller
                 return $row->column(12,'<p style="font-family:Arial,Helvetica,sans-serif; font-size:1.2em; margin-top20px;vertical-align:middle; font-weight:normal ">计免预约</p>');
             })
             ->row(function (Row $row){
-                $data = StatController::nurse();
-                $today = 'orderPatient[appoint_start_time][start]='.date('Y-m-d 00:00:00',time()).'&orderPatient[appoint_start_time][end]='.date('Y-m-d 00:00:00', strtotime('+1days'));
-                $yersterday = 'orderPatient[appoint_start_time][start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
-                    .'&orderPatient[appoint_start_time][end]='.date('Y-m-d 00:00:00', time());
-                $tommrow = 'orderPatient[appoint_start_time][start]='.date('Y-m-d 00:00:00',strtotime('+1 days'))
-                    .'&orderPatient[appoint_start_time][end]='.date('Y-m-d 00:00:00', strtotime('+2 days'));
+                $data = StatController::vaccine();
+                $today = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('today')).'&appoint_start_time[end]='.date('Y-m-d 00:00:00', strtotime('+1days'));
+                $yersterday = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
+                    .'&appoint_start_time[end]='.date('Y-m-d 00:00:00', time());
+                $people = 'end_time[start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
+                    .'&end_time[end]='.date('Y-m-d 00:00:00', time());
+                $tomorrow = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('+1 days'))
+                    .'&appoint_start_time[end]='.date('Y-m-d 00:00:00', strtotime('+2 days'));
 
 
                 $row->column(3,new InfoBox('今日预约数量(人)', 'users', 'aqua', '/cdms/order_vaccines?'.$today, $data['today']));
                 $row->column(3,new InfoBox('昨日预约数量(人)', 'user', 'aqua', '/cdms/order_vaccines?'.$yersterday, $data['yesterday']));
-                $row->column(3,new InfoBox('昨日接种人数(人)', 'user', 'aqua', '/cdms/order_vaccines?status=4&'.$yersterday, $data['people']));
-                $row->column(3,new InfoBox('明日预约数量(人)', 'user', 'aqua', '/cdms/order_vaccines?'.$tommrow, $data['tomorrow']));
+                $row->column(3,new InfoBox('昨日接种人数(人)', 'user', 'aqua', '/cdms/order_vaccines?status=4&'.$people, $data['people']));
+                $row->column(3,new InfoBox('明日预约数量(人)', 'user', 'aqua', '/cdms/order_vaccines?'.$tomorrow, $data['tomorrow']));
             })
             ->row(function (Row $row){
                 return $row->column(12,'<p style="font-family:Arial,Helvetica,sans-serif; font-size:1.2em; margin-top20px;vertical-align:middle; font-weight:normal ">儿保预约</p>');
             })
             ->row(function (Row $row){
                 $data = StatController::nurse();
-                $today = 'patients[appoint_start_time][start]='.date('Y-m-d 00:00:00',time()).'&patients[appoint_start_time][end]='.date('Y-m-d 00:00:00', strtotime('+1days'));
-                $yersterday = 'patients[appoint_start_time][start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
-                    .'&patients[appoint_start_time][end]='.date('Y-m-d 00:00:00', time());
-                $tommrow = 'patients[appoint_start_time][start]='.date('Y-m-d 00:00:00',strtotime('+1 days'))
-                    .'&patients[appoint_start_time][end]='.date('Y-m-d 00:00:00', strtotime('+2 days'));
+                $today = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',time()).'&appoint_start_time[end]='.date('Y-m-d 00:00:00', strtotime('+1days'));
+                $yersterday = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
+                    .'&appoint_start_time[end]='.date('Y-m-d 00:00:00', time());
+                $tommrow = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('+1 days'))
+                    .'&appoint_start_time[end]='.date('Y-m-d 00:00:00', strtotime('+2 days'));
+                $people = 'end_time[start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
+                    .'&end_time[end]='.date('Y-m-d 00:00:00', time());
 
                 $row->column(3,new InfoBox('今日预约数量(人)', 'users', 'aqua', '/cdms/order_nurses?'.$today, $data['today']));
                 $row->column(3,new InfoBox('昨日预约数量(人)', 'user', 'aqua', '/cdms/order_nurses?'.$yersterday, $data['yesterday']));
-                $row->column(3,new InfoBox('昨日接种人数(人)', 'user', 'aqua', '/cdms/order_nurses?orders[order_status]=4&'.$yersterday, $data['people']));
+                $row->column(3,new InfoBox('昨日接种人数(人)', 'user', 'aqua', '/cdms/order_nurses?orders[order_status]=4&'.$people, $data['people']));
                 $row->column(3,new InfoBox('明日预约数量(人)', 'user', 'aqua', '/cdms/order_nurses?'.$tommrow, $data['tomorrow']));
             })
             ->row(function (Row $row){
@@ -88,9 +92,8 @@ class HomeController extends Controller
             })
             ->row(function (Row $row){
                 $data = StatController::vaccineToal();
-                $yersterday = 'orderPatient[appoint_start_time][start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
-                    .'&orderPatient[appoint_start_time][end]='.date('Y-m-d 00:00:00', time());
-
+                $yersterday = 'appoint_start_time[start]='.date('Y-m-d 00:00:00',strtotime('-1 days'))
+                    .'&appoint_start_time[end]='.date('Y-m-d 00:00:00', time());
                 $row->column(3,new InfoBox('疫苗总库存(支)', 'first-order', 'aqua', '/cdms/vaccines', $data['have_num']));
                 $row->column(3,new InfoBox('疫苗库存告急(中)', 'first-order', 'aqua', '/cdms/vaccines', $data['less_num']));
                 $row->column(3,new InfoBox('昨日接种消耗(支)', 'first-order', 'aqua', '/cdms/order_vaccines?order_status=4&'.$yersterday, $data['yesterday']));

+ 2 - 1
app/Community/Controllers/OrderNurseController.php

xqd
@@ -110,7 +110,8 @@ class OrderNurseController extends AdminController
                 $filter->like('patient.phone','电话');
                 $filter->like('patient.name','患者名称');
                 $filter->equal('order_status','订单状态')->select(Order::$_order_status);
-                $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
+                $filter->timestampBetween('appoint_start_time','预约时间')->datetime();
+                $filter->timestampBetween('end_time','接种时间')->datetime();
             });
         });
 

+ 7 - 3
app/Community/Controllers/OrderVaccinesController.php

xqd xqd xqd xqd
@@ -39,6 +39,10 @@ class OrderVaccinesController extends AdminController
         $res = request()->all();
 
         $grid->disableExport(false);
+//        1 => 1614700800
+//      2 => 1614787200
+//      3 => 1614787200
+//      4 => 1614873600
         $grid->export(function ($export) {
             $export->filename('疫苗订单'.Date('Y-m-d',time()));
             $export->column('order_status', function ($value, $original) {
@@ -46,7 +50,6 @@ class OrderVaccinesController extends AdminController
                 return $order_status_arr[intval($original)];
             } );
         });
-
         $user = Admin::user();
         $is_admin = Admin::user()->inRoles(['administrator','devloper']);
         $where = ['product_type'=>4];
@@ -55,7 +58,7 @@ class OrderVaccinesController extends AdminController
             $where = ['product_type'=>4,'organization_id'=>$org_id];
         }
         $grid->model()->where($where);
-        if(!empty($res['orderPatient']['appoint_start_time']['start']) || !empty($res['orderPatient']['appoint_start_time']['start']) ){
+        if(!empty($res['appoint_start_time']['start']) || !empty($res['appoint_start_time']['start']) ){
             $grid->model()->orderBy('appoint_start_time');
         } else {
             $grid->model()->orderBy('appoint_start_time','desc');
@@ -118,7 +121,8 @@ class OrderVaccinesController extends AdminController
                 $filter->like('patient.phone','电话');
                 $filter->like('patient.name','患者名称');
                 $filter->equal('order_status','订单状态')->select(Order::$_order_status);
-                $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
+                $filter->timestampBetween('appoint_start_time','预约时间')->datetime();
+                $filter->timestampBetween('end_time','接种时间')->datetime();
             });
         });
         $grid->tools(function ($tools) {

+ 11 - 4
app/Community/Controllers/ScheduleStatController.php

xqd
@@ -23,10 +23,17 @@ class ScheduleStatController extends Admin
         for ($i=1;$i<=7;$i++){
             $time = $weekStartTime + ($i-1)*86400;
             $date = date('Y-m-d',$time);
-
-            $amCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>1,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
-            $pmCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>2,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
-            $evCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>3,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+            if ($org_id == 0)
+            {
+                $amCount = SchedulePeriod::where(['schedule_date'=>$date,'type'=>1,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+                $pmCount = SchedulePeriod::where(['schedule_date'=>$date,'type'=>2,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+                $evCount = SchedulePeriod::where(['schedule_date'=>$date,'type'=>3,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+            }else
+            {
+                $amCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>1,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+                $pmCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>2,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+                $evCount = SchedulePeriod::where(['organization_id'=>$org_id,'schedule_date'=>$date,'type'=>3,'schedule_type'=>$scheduleType])->distinct('docter_id')->count();
+            }
             $week[$i] = [$amCount,$pmCount,$evCount];
         }
 

+ 96 - 48
app/Community/Controllers/StatController.php

xqd xqd xqd xqd xqd
@@ -31,38 +31,53 @@ class StatController extends  Controller
             $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')));
         //今日预约
-        $today = $order->whereHas('orderPatient',function ($query){
-            $query->whereBetween('appoint_start_time',[strtotime('today'),strtotime('+1days')]);
-        })->count();
-
-        //明日预约
-        $tomorrow = $order->whereHas('orderPatient',function ($query){
-            $query->whereBetween('appoint_start_time',[date('Y-m-d',strtotime('+1 days')),date('Y-m-d',strtotime('+2 days'))]);
-        })->whereNotIn('order_status',[1,5,6])->count();
+        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();
 
-        //昨日接诊人数
-        $people = $order->whereBetween('end_time',[strtotime('-1days'),strtotime('today')])->where('order_status',4)->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();
+        }
 
         $data['today'] = $today;
         $data['yesterday'] = $yesterday;
         $data['people'] = $people;
-        $data['tomorrow '] = $tomorrow;
-
-
+        $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;
-
     }
 
     //儿保
@@ -74,25 +89,47 @@ class StatController extends  Controller
             $where['organization_id']=$org_id;
         }
         $order = Order::where(['product_type'=>5])->where($where);
-
-        //今日预约
-        $today = $order->whereHas('orderPatient',function ($query){
-            $query->whereBetween('appoint_start_time',[strtotime('today'),strtotime('+1days')]);
-        })->count();
-
-        //明日预约
-        $tomorrow = $order->whereHas('orderPatient',function ($query){
-            $query->whereBetween('appoint_start_time',[date('Y-m-d',strtotime('+1 days')),date('Y-m-d',strtotime('+2 days'))]);
-        })->whereNotIn('order_status',[1,5,6])->count();
-
-        //昨日服务人数
-        $people = $order->whereBetween('end_time',[strtotime('-1days'),strtotime('today')])->where('order_status',4)->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();
-
+        $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;
@@ -110,15 +147,26 @@ class StatController extends  Controller
             $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'=>0])->count();//缺苗钟数
-        $ids = Order::where(['product_type'=>4])->where($where)->whereHas('orderPatient',function ($query){
-           $query->where('appoint_start_time',strtotime('today'));//订单id
-        })->pluck('id')->toArray();
-
+        $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;
     }
     //实时数据
@@ -152,7 +200,7 @@ class StatController extends  Controller
             $where['organization_id']=$org_id;
         }
         //todo 是否需要区别状态
-        $order_num[] = Order::where('product_type',3)->where($where)->count();
+        $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();
@@ -199,7 +247,7 @@ class StatController extends  Controller
         //今日预约数
         $today = $order->whereHas('orderPatient',function ($query){
             $query->whereBetween('appoint_start_time',[strtotime('today'),strtotime('+1 days')]);
-        })->whereNotIn('order_status',[1,5,6])->count();
+        })->count();
 
         //医生排班人数
         $docters = SchedulePeriod::where(['schedule_date'=>date('Y-m-d',time()),'schedule_type'=>1])->where($where)->distinct('docter_id')->count();