model = new \app\admin\model\messages\MessagesModel; } /** * 查看 */ 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, true); $join = [ ['doctors d','m.doctor_id = d.id','LEFT'], ['institution i','m.institution_id = i.id','LEFT'], ['department de','m.department_id = de.id','LEFT'], ]; $field = ['m.*','d.realname as doctor_name','i.name as institution_name','de.department_name']; // 过滤机构 $childInsIds = $this->auth->getMyInsId(); if($childInsIds == false){ $more = false; } else { $more = ['m.institution_id' => ['in', $childInsIds]]; } $total = $this->model->alias('m') ->join($join) ->where($more) ->where($where) ->order($sort, $order) ->count(); $list = $this->model->alias('m') ->join($join) ->where($more) ->where($where) ->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 del($ids = "") { if ($ids) { $pk = $this->model->getPk(); $adminIds = $this->getDataLimitAdminIds(); if (is_array($adminIds)) { $this->model->where($this->dataLimitField, 'in', $adminIds); } $list = $this->model->where($pk, 'in', $ids)->select(); $count = 0; Db::startTrans(); try { $update = [ 'status' => '1' ]; foreach ($list as $k => $v) { $count += $v->where('id',$v['id'])->update($update); } Db::commit(); } catch (PDOException $e) { Db::rollback(); $this->error($e->getMessage()); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($count) { $this->success(); } else { $this->error(__('No rows were deleted')); } } $this->error(__('Parameter %s can not be empty', 'ids')); } }