123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207 |
- <?php
- namespace app\admin\controller\statistics;
- use app\common\controller\Backend;
- use think\Db;
- /**
- * 公众号访问报告详情
- *
- * @icon fa fa-circle-o
- */
- class Wechat extends Backend
- {
-
- /**
- * Wechat模型对象
- * @var \app\admin\model\statistics\Wechat
- */
- protected $model = null;
- protected $noNeedRight = ['visitLink'];
- public function _initialize()
- {
- parent::_initialize();
- $this->model = new \app\admin\model\statistics\Wechat;
- }
-
- /**
- * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
- * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
- * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
- */
- /**
- * 查看
- */
- public function index()
- {
- //设置过滤方法
- $this->request->filter(['strip_tags']);
- if ($this->request->isAjax()) {
- //如果发送的来源是Selectpage,则转发到Selectpage
- if ($this->request->request('keyField')) {
- return $this->selectpage();
- }
- $childInsIds = $this->auth->getMyInsId();
- if($childInsIds == false){
- $more = false;
- } else {
- $more = ['institution_id' => ['in', $childInsIds]];
- }
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $filter = $this->request->get("filter", '');
- $op = $this->request->get("op", '', 'trim');
- $filter = (array)json_decode($filter, true);
- $having = '';
- if($filter['t'] ?? null)
- {
- $t = $filter['t'];
- $having = "t='$t'";
- }
- $where = '';
- if($filter['institution_id'] ?? null)
- {
- $where = ['institution_id'=>$filter['institution_id']];
- $more = false;
- }
- $all = $this->model
- ->where($where)
- ->where($more)
- ->group("institution_id,t")
- ->field("count(distinct(exam_id)) as c,institution_id,DATE_FORMAT(createdAt,'%Y-%m-%d') as t")
- ->having($having)
- ->select();
- $total = count($all);
- $list = $this->model
- ->where($where)
- ->where($more)
- ->group("institution_id,t")
- ->field("count(distinct(exam_id)) as c,institution_id,institution_id as id,DATE_FORMAT(createdAt,'%Y-%m-%d') as t")
- ->having($having)
- ->order('t desc,institution_id')
- ->limit($offset, $limit)
- ->select();
- $ins = Db::table('institution')->column('id,name');
- foreach ($list as $k=>$v)
- {
- if($ins[$v['institution_id']])
- {
- $list[$k]['institution_name'] = $ins[$v['institution_id']];
- }else{
- $list[$k]['institution_name'] = '';
- }
- }
- $list = collection($list)->toArray();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- public function visitList($ids)
- {
- $this->view->assign("id", $ids);
- return $this->view->fetch();
- }
- public function visitLink()
- {
- set_time_limit(0);
- if ($this->request->isAjax())
- {
- list($where, $sort, $order, $offset, $limit) = $this->buildparams();
- $ins = $this->request->param('ins');
- $institution = ['institution_id'=>$ins];
- $filter = $this->request->get("filter", '');
- $filter = (array)json_decode($filter, true);
- if($filter['createdAt'] ?? null)
- {
- $time = explode(' - ',$filter['createdAt']);
- $time1 = $time[0];
- $time2 = $time[1];
- }else{
- $time = date('Y-m-d');
- $time1 = $time.' 00:00:00';
- $time2 = $time.' 23:59:59';
- }
- $exam = [];
- if($filter['exam_class'] ?? null)
- {
- $exam = ['exam_class'=>$filter['exam_class']];
- }
- $visit = $this->model
- ->whereTime('createdAt',[$time1,$time2])
- ->where($institution)
- ->select();
- $ids = [];
- $cTime = [];
- $type = [];
- foreach ($visit as $k=>$v)
- {
- $ids[] = $v['exam_id'];
- $cTime[$v['exam_id']] = $v['createdAt'];
- if($type[$v['exam_id']] ?? null)
- {
- $type[$v['exam_id']] = $type[$v['exam_id']].','.$v['source'];
- }else{
- $type[$v['exam_id']] = $v['source'];
- }
- }
- $list = Db::table('exams')->where('id','in',$ids)->where($exam)->field('id,name,exam_datetime,patient_num,accession_num,phone,exam_class')->limit($offset, $limit)->select();
- foreach ($list as $k=>$v)
- {
- $list[$k]['createdAt'] = $cTime[$v['id']];
- $source = '';
- if($type[$v['id']] ?? null)
- {
- if(strpos($type[$v['id']],'1') !== false)
- {
- if(empty($source))
- {
- $source = '数字影像云公众号';
- }else{
- $source .= ',数字影像云公众号';
- }
- }
- if(strpos($type[$v['id']],'2') !== false)
- {
- if(empty($source))
- {
- $source = '集成链接';
- }else{
- $source .= ',集成链接';
- }
- }
- if(strpos($type[$v['id']],'3') !== false)
- {
- if(empty($source))
- {
- $source = '推送短信';
- }else{
- $source .= ',推送短信';
- }
- }
- $list[$k]['source'] = $source;
- }
- // $list[$k]['name'] = mb_substr($v['name'],0,1,'utf-8').'***';
- // if(!empty($v['phone']))
- // {
- // $list[$k]['phone'] = substr_replace($v['phone'],'****',3,4);
- // }
- }
- $total = Db::table('exams')->where('id','in',$ids)->where($exam)->count();
- $result = array("total" => $total, "rows" => $list);
- return json($result);
- }
- return $this->view->fetch();
- }
- }
|