model = new Order(); } public function index() { //设置过滤方法 $this->request->filter(['strip_tags']); if ($this->request->isAjax()) { //如果发送的来源是Selectpage,则转发到Selectpage if ($this->request->request('keyField')) { return $this->selectpage(); } list($where, $sort, $order, $offset, $limit) = $this->buildparams($this->searchFields,false); $join = [ ['remote_order o', 'a.id = o.application_id', 'LEFT'], ['report r', 'a.id = r.remote_application_id','LEFT'], ]; $field = [ 'a.name','local_institution_id','local_institution_id','local_institution_name','remote_institution_id', 'remote_institution_name','a.exam_class','a.exam_id','req_doctor_name','req_date_time','report_status', 'a.is_urgent','o.status as order_status','a.exam_project', 'r.report_doctor_name', 'r.review_doctor_name', 'r.review_datetime', 'o.order_money', 'o.pay_way' ]; $more = [ 'r.type' => '2', 'a.status' => '0', ]; // 过滤机构 $my_ins_id = $this->auth->getMyInsId(); if($my_ins_id === false){ $total = model('Remote','model\remote') ->alias('a') ->join($join) ->where($where) ->where('report_status>3') ->where($more) ->order($sort, $order) ->count(); $list = model('Remote','model\remote') ->alias('a') ->join($join) ->where($where) ->where('report_status>3') ->where($more) ->order($sort, $order) ->limit($offset, $limit) ->field($field) ->select(); } else { $total = model('Remote','model\remote') ->alias('a') ->join($join) ->where($where) ->where('report_status>3') ->where($more) ->where(function ($query) use ($my_ins_id){ $query->whereIn('local_institution_id', $my_ins_id); $query->whereIn('remote_institution_id', $my_ins_id,'or'); }) ->order($sort, $order) ->count(); $list = model('Remote','model\remote') ->alias('a') ->join($join) ->where($where) ->where('report_status>3') ->where($more) ->where(function ($query) use ($my_ins_id){ $query->whereIn('local_institution_id', $my_ins_id); $query->whereIn('remote_institution_id', $my_ins_id,'or'); }) ->order($sort, $order) ->limit($offset, $limit) ->field($field) ->select(); } $list = collection($list)->toArray(); $result = array("total" => $total, "rows" => $list); return json($result); } return $this->view->fetch(); } public function getPositive() { list($where) = $this->buildparams($this->searchFields, true); $record = model('Remote','model\remote')::alias('a') ->join([ ['report r', 'a.id = r.remote_application_id','LEFT'], ]) ->where($where) ->where(function ($query){ $query->where('r.report_result',"1") ->whereOr('r.report_result',"2"); }) ->column('r.report_result'); $num = 0; $positive = 0; foreach ($record as $val){ $positive += $val === '2' ? 1 : 0; } if($positive != 0){ $num = round(($positive / count($record)) * 100, 2); } $this->success('','',[ 'centage' => $num, 'positive' => $positive ]); } }