Remote.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace app\admin\controller\statistics;
  3. use app\admin\model\remote\Order;
  4. use app\common\controller\Backend;
  5. use think\Db;
  6. use think\Env;
  7. /**
  8. *
  9. *
  10. * @icon fa fa-circle-o
  11. */
  12. class Remote extends Backend
  13. {
  14. protected $noNeedRight = ['getPositive'];
  15. /**
  16. * Remote模型对象
  17. * @var \app\admin\model\remote\Remote
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new Order();
  24. }
  25. public function index()
  26. {
  27. //设置过滤方法
  28. $this->request->filter(['strip_tags']);
  29. if ($this->request->isAjax()) {
  30. //如果发送的来源是Selectpage,则转发到Selectpage
  31. if ($this->request->request('keyField')) {
  32. return $this->selectpage();
  33. }
  34. list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields,false);
  35. $join = [
  36. ['remote_order o', 'a.id = o.application_id', 'LEFT'],
  37. ['report r', 'a.id = r.remote_application_id','LEFT'],
  38. ];
  39. $field = [
  40. 'a.name','local_institution_id','local_institution_id','local_institution_name','remote_institution_id',
  41. 'remote_institution_name','a.exam_class','a.exam_id','req_doctor_name','req_date_time','report_status',
  42. 'a.is_urgent','o.status as order_status','a.exam_project',
  43. 'r.report_doctor_name', 'r.review_doctor_name', 'r.review_datetime', 'o.order_money', 'o.pay_way'
  44. ];
  45. $more = [
  46. 'r.type' => '2',
  47. 'a.status' => '0',
  48. ];
  49. // 过滤机构
  50. $my_ins_id = $this->auth->getMyInsId();
  51. if($my_ins_id === false){
  52. $total = model('Remote','model\remote')
  53. ->alias('a')
  54. ->join($join)
  55. ->where($where)
  56. ->where('report_status>3')
  57. ->where($more)
  58. ->order($sort, $order)
  59. ->count();
  60. $list = model('Remote','model\remote')
  61. ->alias('a')
  62. ->join($join)
  63. ->where($where)
  64. ->where('report_status>3')
  65. ->where($more)
  66. ->order($sort, $order)
  67. ->limit($offset, $limit)
  68. ->field($field)
  69. ->select();
  70. } else {
  71. $total = model('Remote','model\remote')
  72. ->alias('a')
  73. ->join($join)
  74. ->where($where)
  75. ->where('report_status>3')
  76. ->where($more)
  77. ->where(function ($query) use ($my_ins_id){
  78. $query->whereIn('local_institution_id', $my_ins_id);
  79. $query->whereIn('remote_institution_id', $my_ins_id,'or');
  80. })
  81. ->order($sort, $order)
  82. ->count();
  83. $list = model('Remote','model\remote')
  84. ->alias('a')
  85. ->join($join)
  86. ->where($where)
  87. ->where('report_status>3')
  88. ->where($more)
  89. ->where(function ($query) use ($my_ins_id){
  90. $query->whereIn('local_institution_id', $my_ins_id);
  91. $query->whereIn('remote_institution_id', $my_ins_id,'or');
  92. })
  93. ->order($sort, $order)
  94. ->limit($offset, $limit)
  95. ->field($field)
  96. ->select();
  97. }
  98. $list = collection($list)->toArray();
  99. $result = array("total" => $total, "rows" => $list);
  100. return json($result);
  101. }
  102. return $this->view->fetch();
  103. }
  104. public function getPositive()
  105. {
  106. list($where) = $this->buildparams($this->searchFields, true);
  107. $record = model('Remote','model\remote')::alias('a')
  108. ->join([
  109. ['report r', 'a.id = r.remote_application_id','LEFT'],
  110. ])
  111. ->where($where)
  112. ->where(function ($query){
  113. $query->where('r.report_result',"1")
  114. ->whereOr('r.report_result',"2");
  115. })
  116. ->column('r.report_result');
  117. $num = 0;
  118. $positive = 0;
  119. foreach ($record as $val){
  120. $positive += $val === '2' ? 1 : 0;
  121. }
  122. if($positive != 0){
  123. $num = round(($positive / count($record)) * 100, 2);
  124. }
  125. $this->success('','',[
  126. 'centage' => $num,
  127. 'positive' => $positive
  128. ]);
  129. }
  130. }