123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?php
- namespace app\admin\controller;
- use app\admin\controller\dict\Commondata;
- use app\admin\model\dict\Commontable;
- use app\common\controller\Backend;
- use think\facade\Db;
- class Dashboard extends Backend
- {
- protected array $noNeedPermission = ['getDashboard','getInsType','getAllIns'];
- protected array $noNeedLogin = ['getInsType'];
- public function initialize(): void
- {
- parent::initialize();
- }
- public function index(): void
- {
- $this->success('', [
- 'remark' => get_route_remark()
- ]);
- }
- public function getDashboard(): void
- {
- $params = $this->request->post();
- $where = [];
- $time = time();
- if($params['type'] == 1)
- {
- //周
- $currDate = date("Y-m-d");
- $currWeekDay = date("w", strtotime($currDate));
- // 根据当前日期的星期几计算本周的开始日期和结束日期
- $startDate = date("Y-m-d", strtotime("-" . $currWeekDay . " days", strtotime($currDate)));
- $start = strtotime($startDate)+86400;
- if($time < strtotime($startDate)+86400)
- {
- $start = $start - 7*86400;
- }
- $where[] = ['create_time','BETWEEN',[date('Y-m-d 00:00:00',$start),date('Y-m-d 23:59:59',$time)]];
- }elseif($params['type'] == 2){
- //月
- $firstDayOfMonth = date('Y-m-01 00:00:00');
- $where[] = ['create_time','BETWEEN',[$firstDayOfMonth,date('Y-m-d 23:59:59',$time)]];
- }else{
- $this->error('错误的参数请求');
- }
- $ins_type = Db::name('dict_common_data')->where('type','8')->column('name','name');
- \think\facade\Cache::delete('institution_dashboard');
- $allIns = Db::name('institution')->where('status',1)->cache('institution_dashboard','3600')->field(['name','create_time','institution_type'])->select();
- $institution_code = [];
- $institution = [];
- foreach ($allIns as $k=>$v)
- {
- if($ins_type[$v['institution_type']] ?? '')
- {
- if(isset($institution_code[$v['institution_type']]))
- {
- $institution_code[$v['institution_type']]++;
- $institution[$ins_type[$v['institution_type']]]++;
- }else{
- $institution_code[$v['institution_type']] = 1;
- $institution[$ins_type[$v['institution_type']]] = 1;
- }
- }
- }
- $jc_dict = Db::name('dict_exam_project')->count();
- $jy_dict = Db::name('dict_lab_item')->count();
- $dict = ['jc'=>$jc_dict,'jy'=>$jy_dict];
- $patient = Db::name('patient')->where($where)->count();
- $hr_jc = Db::name('hr_record')->where($where)->where('ITEMNAMETYPE',1)->count();
- $hr_jy = Db::name('hr_record')->where($where)->where('ITEMNAMETYPE',2)->count();
- $data = [
- 'hr'=>['patient'=>$patient,'jc'=>$hr_jc,'jy'=>$hr_jy],
- 'dict'=>$dict,
- 'hr_ins'=>$institution
- ];
- $this->success('',$data);
- }
- public function getInsType()
- {
- $common = new \app\admin\model\dict\Commondata();
- $arr = $common->where('type',8)->column('name');
- $this->success('',$arr);
- }
- public function getAllIns()
- {
- $params = $this->request->post();
- $where = [];
- if(!empty($params['type']))
- {
- $where['institution_type'] = $params['type'];
- }
- $nameWhere= [];
- if(!empty($params['name']))
- {
- $nameWhere[] =['name','like' ,'%'.$params['name'].'%'];
- }
- $allIns = Db::name('institution')->where($where)->where($nameWhere)->where('status',1)->field(['name','create_time','institution_type'])->select();
- $this->success('',['all_ins'=>$allIns]);
- }
- }
|