Printsync.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 Printsync extends Backend
  11. {
  12. /**
  13. * Printsync模型对象
  14. * @var \app\admin\model\statistics\Printsync
  15. */
  16. protected $model = null;
  17. protected $noNeedRight = ['getAllTimes'];
  18. public function _initialize()
  19. {
  20. parent::_initialize();
  21. $this->model = new \app\admin\model\statistics\Printsync;
  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. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  41. $childInsIds = $this->auth->getMyInsId();
  42. if($childInsIds == false){
  43. $more = false;
  44. } else {
  45. $more = ['institution_id' => ['in', $childInsIds]];
  46. }
  47. $list = $this->model
  48. ->where($more)
  49. ->where($where)
  50. ->field("COUNT(*) as times,code,name,DATE_FORMAT(print_time,'%Y-%m-%d') as c,institution_id")
  51. ->limit($offset, $limit)
  52. ->group("code,name,DATE_FORMAT(print_time,'%Y-%m-%d'),institution_id")
  53. ->select();
  54. $all = $this->model
  55. ->where($more)
  56. ->where($where)
  57. ->field("COUNT(*) as times,code,name,DATE_FORMAT(print_time,'%Y-%m-%d') as c,institution_id")
  58. ->group("code,name,DATE_FORMAT(print_time,'%Y-%m-%d'),institution_id")
  59. ->select();
  60. $total = count($all);
  61. $list = collection($list)->toArray();
  62. $institution = Db::table('institution')->column('id,name');
  63. foreach ($list as $k=>$v)
  64. {
  65. if(isset($institution[$v['institution_id']]))
  66. {
  67. $list[$k]['ins_name'] = $institution[$v['institution_id']];
  68. }else{
  69. $list[$k]['ins_name'] = '';
  70. }
  71. }
  72. $result = array("total" => $total, "rows" => $list);
  73. return json($result);
  74. }
  75. return $this->view->fetch();
  76. }
  77. public function getAllTimes()
  78. {
  79. $filter = $this->request->get("filter", '');
  80. $filter = (array)json_decode($filter, true);
  81. $ins_where = [];
  82. if(isset($filter['institution_id']) && !empty($filter['institution_id']))
  83. {
  84. $ins_where = ['institution_id' =>$filter['institution_id']];
  85. }else{
  86. $this->error('需要选择医院或者先进行搜索在点击查看');
  87. }
  88. $time_where = [];
  89. if(isset($filter['print_time']) && !empty($filter['print_time']))
  90. {
  91. $print_time = explode(',',$filter['print_time']);
  92. $time_where = "print_time between '$print_time[0]' and '$print_time[1]'";
  93. }
  94. $childInsIds = $this->auth->getMyInsId();
  95. if($childInsIds == false){
  96. $more = false;
  97. } else {
  98. $more = ['institution_id' => ['in', $childInsIds]];
  99. }
  100. $times = Db::table('print_sync')->where($more)->where($time_where)->where($ins_where)->fetchSql(false)->sum('times');
  101. $this->success('','',$times);
  102. }
  103. }