Dashboard.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\controller\dict\Commondata;
  4. use app\admin\model\dict\Commontable;
  5. use app\common\controller\Backend;
  6. use think\facade\Db;
  7. class Dashboard extends Backend
  8. {
  9. protected array $noNeedPermission = ['getDashboard','getInsType','getAllIns'];
  10. protected array $noNeedLogin = ['getInsType'];
  11. public function initialize(): void
  12. {
  13. parent::initialize();
  14. }
  15. public function index(): void
  16. {
  17. $this->success('', [
  18. 'remark' => get_route_remark()
  19. ]);
  20. }
  21. public function getDashboard(): void
  22. {
  23. $params = $this->request->post();
  24. $where = [];
  25. $time = time();
  26. if($params['type'] == 1)
  27. {
  28. //周
  29. $currDate = date("Y-m-d");
  30. $currWeekDay = date("w", strtotime($currDate));
  31. // 根据当前日期的星期几计算本周的开始日期和结束日期
  32. $startDate = date("Y-m-d", strtotime("-" . $currWeekDay . " days", strtotime($currDate)));
  33. $start = strtotime($startDate)+86400;
  34. if($time < strtotime($startDate)+86400)
  35. {
  36. $start = $start - 7*86400;
  37. }
  38. $where[] = ['create_time','BETWEEN',[date('Y-m-d 00:00:00',$start),date('Y-m-d 23:59:59',$time)]];
  39. }elseif($params['type'] == 2){
  40. //月
  41. $firstDayOfMonth = date('Y-m-01 00:00:00');
  42. $where[] = ['create_time','BETWEEN',[$firstDayOfMonth,date('Y-m-d 23:59:59',$time)]];
  43. }else{
  44. $this->error('错误的参数请求');
  45. }
  46. $ins_type = Db::name('dict_common_data')->where('type','8')->column('name','name');
  47. \think\facade\Cache::delete('institution_dashboard');
  48. $allIns = Db::name('institution')->where('status',1)->cache('institution_dashboard','3600')->field(['name','create_time','institution_type'])->select();
  49. $institution_code = [];
  50. $institution = [];
  51. foreach ($allIns as $k=>$v)
  52. {
  53. if($ins_type[$v['institution_type']] ?? '')
  54. {
  55. if(isset($institution_code[$v['institution_type']]))
  56. {
  57. $institution_code[$v['institution_type']]++;
  58. $institution[$ins_type[$v['institution_type']]]++;
  59. }else{
  60. $institution_code[$v['institution_type']] = 1;
  61. $institution[$ins_type[$v['institution_type']]] = 1;
  62. }
  63. }
  64. }
  65. $jc_dict = Db::name('dict_exam_project')->count();
  66. $jy_dict = Db::name('dict_lab_item')->count();
  67. $dict = ['jc'=>$jc_dict,'jy'=>$jy_dict];
  68. $patient = Db::name('patient')->where($where)->count();
  69. $hr_jc = Db::name('hr_record')->where($where)->where('ITEMNAMETYPE',1)->count();
  70. $hr_jy = Db::name('hr_record')->where($where)->where('ITEMNAMETYPE',2)->count();
  71. $data = [
  72. 'hr'=>['patient'=>$patient,'jc'=>$hr_jc,'jy'=>$hr_jy],
  73. 'dict'=>$dict,
  74. 'hr_ins'=>$institution
  75. ];
  76. $this->success('',$data);
  77. }
  78. public function getInsType()
  79. {
  80. $common = new \app\admin\model\dict\Commondata();
  81. $arr = $common->where('type',8)->column('name');
  82. $this->success('',$arr);
  83. }
  84. public function getAllIns()
  85. {
  86. $params = $this->request->post();
  87. $where = [];
  88. if(!empty($params['type']))
  89. {
  90. $where['institution_type'] = $params['type'];
  91. }
  92. $nameWhere= [];
  93. if(!empty($params['name']))
  94. {
  95. $nameWhere[] =['name','like' ,'%'.$params['name'].'%'];
  96. }
  97. $allIns = Db::name('institution')->where($where)->where($nameWhere)->where('status',1)->field(['name','create_time','institution_type'])->select();
  98. $this->success('',['all_ins'=>$allIns]);
  99. }
  100. }