Wechat.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace app\admin\controller\statistics;
  3. use app\common\controller\Backend;
  4. use think\Db;
  5. /**
  6. * 公众号访问报告详情
  7. *
  8. * @icon fa fa-circle-o
  9. */
  10. class Wechat extends Backend
  11. {
  12. /**
  13. * Wechat模型对象
  14. * @var \app\admin\model\statistics\Wechat
  15. */
  16. protected $model = null;
  17. protected $noNeedRight = ['visitLink'];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\statistics\Wechat;
  22. }
  23. /**
  24. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  25. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  26. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  27. */
  28. /**
  29. * 查看
  30. */
  31. public function index()
  32. {
  33. //设置过滤方法
  34. $this->request->filter(['strip_tags']);
  35. if ($this->request->isAjax()) {
  36. //如果发送的来源是Selectpage,则转发到Selectpage
  37. if ($this->request->request('keyField')) {
  38. return $this->selectpage();
  39. }
  40. $childInsIds = $this->auth->getMyInsId();
  41. if($childInsIds == false){
  42. $more = false;
  43. } else {
  44. $more = ['institution_id' => ['in', $childInsIds]];
  45. }
  46. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  47. $filter = $this->request->get("filter", '');
  48. $op = $this->request->get("op", '', 'trim');
  49. $filter = (array)json_decode($filter, true);
  50. $having = '';
  51. if($filter['t'] ?? null)
  52. {
  53. $t = $filter['t'];
  54. $having = "t='$t'";
  55. }
  56. $where = '';
  57. if($filter['institution_id'] ?? null)
  58. {
  59. $where = ['institution_id'=>$filter['institution_id']];
  60. $more = false;
  61. }
  62. $all = $this->model
  63. ->where($where)
  64. ->where($more)
  65. ->group("institution_id,t")
  66. ->field("count(distinct(exam_id)) as c,institution_id,DATE_FORMAT(createdAt,'%Y-%m-%d') as t")
  67. ->having($having)
  68. ->select();
  69. $total = count($all);
  70. $list = $this->model
  71. ->where($where)
  72. ->where($more)
  73. ->group("institution_id,t")
  74. ->field("count(distinct(exam_id)) as c,institution_id,institution_id as id,DATE_FORMAT(createdAt,'%Y-%m-%d') as t")
  75. ->having($having)
  76. ->order('t desc,institution_id')
  77. ->limit($offset, $limit)
  78. ->select();
  79. $ins = Db::table('institution')->column('id,name');
  80. foreach ($list as $k=>$v)
  81. {
  82. if($ins[$v['institution_id']])
  83. {
  84. $list[$k]['institution_name'] = $ins[$v['institution_id']];
  85. }else{
  86. $list[$k]['institution_name'] = '';
  87. }
  88. }
  89. $list = collection($list)->toArray();
  90. $result = array("total" => $total, "rows" => $list);
  91. return json($result);
  92. }
  93. return $this->view->fetch();
  94. }
  95. public function visitList($ids)
  96. {
  97. $this->view->assign("id", $ids);
  98. return $this->view->fetch();
  99. }
  100. public function visitLink()
  101. {
  102. set_time_limit(0);
  103. if ($this->request->isAjax())
  104. {
  105. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  106. $ins = $this->request->param('ins');
  107. $institution = ['institution_id'=>$ins];
  108. $filter = $this->request->get("filter", '');
  109. $filter = (array)json_decode($filter, true);
  110. if($filter['createdAt'] ?? null)
  111. {
  112. $time = explode(' - ',$filter['createdAt']);
  113. $time1 = $time[0];
  114. $time2 = $time[1];
  115. }else{
  116. $time = date('Y-m-d');
  117. $time1 = $time.' 00:00:00';
  118. $time2 = $time.' 23:59:59';
  119. }
  120. $exam = [];
  121. if($filter['exam_class'] ?? null)
  122. {
  123. $exam = ['exam_class'=>$filter['exam_class']];
  124. }
  125. $visit = $this->model
  126. ->whereTime('createdAt',[$time1,$time2])
  127. ->where($institution)
  128. ->select();
  129. $ids = [];
  130. $cTime = [];
  131. $type = [];
  132. foreach ($visit as $k=>$v)
  133. {
  134. $ids[] = $v['exam_id'];
  135. $cTime[$v['exam_id']] = $v['createdAt'];
  136. if($type[$v['exam_id']] ?? null)
  137. {
  138. $type[$v['exam_id']] = $type[$v['exam_id']].','.$v['source'];
  139. }else{
  140. $type[$v['exam_id']] = $v['source'];
  141. }
  142. }
  143. $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();
  144. foreach ($list as $k=>$v)
  145. {
  146. $list[$k]['createdAt'] = $cTime[$v['id']];
  147. $source = '';
  148. if($type[$v['id']] ?? null)
  149. {
  150. if(strpos($type[$v['id']],'1') !== false)
  151. {
  152. if(empty($source))
  153. {
  154. $source = '数字影像云公众号';
  155. }else{
  156. $source .= ',数字影像云公众号';
  157. }
  158. }
  159. if(strpos($type[$v['id']],'2') !== false)
  160. {
  161. if(empty($source))
  162. {
  163. $source = '集成链接';
  164. }else{
  165. $source .= ',集成链接';
  166. }
  167. }
  168. if(strpos($type[$v['id']],'3') !== false)
  169. {
  170. if(empty($source))
  171. {
  172. $source = '推送短信';
  173. }else{
  174. $source .= ',推送短信';
  175. }
  176. }
  177. $list[$k]['source'] = $source;
  178. }
  179. // $list[$k]['name'] = mb_substr($v['name'],0,1,'utf-8').'***';
  180. // if(!empty($v['phone']))
  181. // {
  182. // $list[$k]['phone'] = substr_replace($v['phone'],'****',3,4);
  183. // }
  184. }
  185. $total = Db::table('exams')->where('id','in',$ids)->where($exam)->count();
  186. $result = array("total" => $total, "rows" => $list);
  187. return json($result);
  188. }
  189. return $this->view->fetch();
  190. }
  191. }