StatController.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\Docter;
  5. use App\Models\Order;
  6. use App\Models\Schedule;
  7. use App\Models\SchedulePeriod;
  8. use App\Models\Vaccine;
  9. use Encore\Admin\Facades\Admin;
  10. use Illuminate\Support\Facades\DB;
  11. class StatController extends Controller
  12. {
  13. public static $org_id;
  14. public function __construct()
  15. {
  16. self::$org_id = Admin::user()->org_id;;
  17. }
  18. //疫苗统计
  19. public static function vaccine()
  20. {
  21. $where = [];
  22. if(self::$org_id){
  23. $where['organization_id']=self::$org_id;
  24. }
  25. $data ['sum_num'] = Vaccine::where($where)->count();
  26. $data['have_num'] = Vaccine::where($where)->sum('stock');
  27. $data['less_num'] = Vaccine::where($where)->where(['stock'=>0])->count();//取苗钟数
  28. $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();
  29. $data['today_vaccine'] = Order::where(['product_type'=>4])->where($where)->with('orderPatient','appoint_start_time',strtotime('today'))->count();//接诊患者(人次)
  30. return $data;
  31. }
  32. //实时数据
  33. public static function service()
  34. {
  35. $where = [];
  36. if(self::$org_id){
  37. $where['organization_id']=self::$org_id;
  38. }
  39. $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();
  40. $data['schedule_docter'] = SchedulePeriod::distinct('docter_id')->where($where)->where('schedule_date',date('Y-m-d H:i:s',time()))->count();
  41. // $data['paitent_num'] = Order::where(['order_status'=>1])->distinct()->count()->BgroupBy('patient_id');
  42. $data['paitent_num'] = Order::whereHas('orderPatient',function ($query){
  43. $query->where(['appoint_start_time'=>strtotime('today')]);
  44. })->where(['product_type'=>4])->where($where)->count();//接诊患者(人次)
  45. return $data;
  46. }
  47. //订单概况
  48. public static function nurse()
  49. {
  50. //3.门诊预约 4.疫苗接种预约 5.儿保预约
  51. $where = [];
  52. if(self::$org_id){
  53. $where['organization_id']=self::$org_id;
  54. }
  55. $nurse_num[] = Order::where('product_type',3)->where($where)->count();
  56. $nurse_num[] = Order::where('product_type',4)->where($where)->count();
  57. $nurse_num[] = Order::where('product_type',5)->where($where)->count();
  58. return $nurse_num;
  59. }
  60. //排班统计
  61. public static function schedule()
  62. {
  63. $where = [];
  64. if(self::$org_id){
  65. $where['organization_id']=self::$org_id;
  66. }
  67. $ids = SchedulePeriod::where('schedule_date',date("Y-m-d"))->where($where)->distinct('docter_id')->pluck('docter_id')->toArray();
  68. $data = ['clinic_num'=>0,'vaccine_num'=>0,'nurse_num'=>0];
  69. if(empty($ids)){
  70. return $data;
  71. };
  72. $docters = Docter::whereIn('id',$ids)->get(['id','type'])->GroupBy('type');
  73. foreach ($docters as $key => $val){
  74. if($key === 1){
  75. $data['clinic_num'] = count($val);
  76. } else if($key == 2){
  77. $data['vaccine_num'] = count($val);
  78. } else if($key == 3){
  79. $data['nurse_num'] = count($val);
  80. }
  81. }
  82. return $data;
  83. }
  84. //门诊统计
  85. public static function clinc()
  86. {
  87. $orgId = self::$org_id;
  88. $order = Order::where(['product_type'=>3,'organization_id'=>$orgId]);
  89. $today = $order->where('created_at','>=',date('Y-m-d'))->whereNotIn('order_status',[1,5,6])->count();
  90. $docters = Schedule::where(['organization'=>$orgId,'schedule_date'=>date('Y-m-d',time())])->count();
  91. $yesterday = $order->whereBetween(date('Y-m-d',[strtotime('-1days'),date('Y-m-d')]))->whereNotIn('order_status',[1,5,6])->count();
  92. $yesterday = $order->whereBetween(date('Y-m-d',[strtotime('-1days'),date('Y-m-d')]))->whereNotIn('order_status',[1,5,6])->count();
  93. return [];
  94. }
  95. }