From db77b3579b3da1aa2edf41e0ec2e7f4d8eeb229e Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Mon, 2 Sep 2024 10:57:12 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8D=AF=E6=96=B9=E7=9B=B8=E5=85=B3=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/index.php | 16 ++++++++-------- model/mCase.php | 7 +++++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/control/index.php b/control/index.php index d32905c..e9f4e9a 100644 --- a/control/index.php +++ b/control/index.php @@ -50,13 +50,13 @@ class index extends publicBase { public function ajax_search() { $content = $this->post('content'); - if(empty($content))$this->ajax_json(false, '非法请求'); + if(empty($content))$this->ajax_json(false, '请输入方名'); - $start = $this->post('start') ? $this->post('start') : 0; - $pagesize = $this->post('pagesize') ? $this->post('pagesize') : 500; + $page_num = $this->post('page_num') ? $this->post('page_num') : 1; + $page_size = $this->post('page_size') ? $this->post('page_size') : 100; - $mCase = new mCase(); - $data = $mCase->getCaseByName($content,$start,$pagesize); + $m_case = new mCase(); + $data = $m_case->getCaseByName($content, $page_num, $page_size); $this->ajax_json(true, '获取成功', $data); } @@ -65,9 +65,9 @@ class index extends publicBase { $id = $this->get('id'); if(empty($id))$this->ajax_json(false, '非法请求'); - $mCase = new mCase(); - $data = $mCase->getCaseInfo($id); - if (empty($data)) $this->ajax_json(false, $mCase->getError()); + $m_case = new mCase(); + $data = $m_case->getCaseInfo($id); + if (!$data) $this->ajax_json(false, $m_case->getError()); $this->ajax_json(true, '获取成功', $data); } diff --git a/model/mCase.php b/model/mCase.php index e22c672..c4f524c 100644 --- a/model/mCase.php +++ b/model/mCase.php @@ -130,10 +130,11 @@ class mCase extends mBase { return $this->obj->selectAll($this->case_herb_tbl, array('sql'=>'`case_id`=?','vals'=>array($case_id)), 'sort asc '); } - public function getCaseByName($name,$start,$pagesize) { + public function getCaseByName($name, $page_num, $page_size) { $sql = " `name` like '%{$name}%'"; - $res = $this->obj->selectAll($this->tbl, array('sql'=>$sql, 'vals'=>array()), 'use_num desc,sort asc ', array($start, $pagesize)); + $offset = ($page_num - 1) * $page_size; + $res = $this->obj->selectAll($this->tbl, array('sql'=>$sql, 'vals'=>array()), 'use_num desc,sort asc ', array($offset, $page_size)); if(empty($res)) return array(); return $res; @@ -143,9 +144,11 @@ class mCase extends mBase { //药方信息 $case = $this->getCaseById($id); if(empty($case)){$this->setError('查询不到此药方');return false;} + //药方药材信息 $case_herb = $this->getCaseHerbByCaseId($case['id']); if(empty($case_herb)){$this->setError('药方药材查询失败');return false;} + //药材名称 $herb_ids = array_column($case_herb,'herb_id'); $herb = $this->getHerbByIds($herb_ids);