Browse Source

药方列表展示药方详情

pull/1/head
pengda 9 months ago
parent
commit
6729f4f366
  1. 2
      control/index.php
  2. 42
      model/mCase.php

2
control/index.php

@ -72,7 +72,7 @@ class index extends publicBase {
$page_size = $this->post('page_size') ? $this->post('page_size') : 20; $page_size = $this->post('page_size') ? $this->post('page_size') : 20;
$m_case = new mCase(); $m_case = new mCase();
$data = $m_case->getCaseByName($uinfo['uid'], $content, $page_num, $page_size); $data = $m_case->getCaseList($uinfo['uid'], $content, $page_num, $page_size);
$total = $m_case->getCaseByNameTotal($content); $total = $m_case->getCaseByNameTotal($content);
$rdata = array( $rdata = array(
'total' => $total, 'total' => $total,

42
model/mCase.php

@ -207,12 +207,52 @@ class mCase extends mBase {
return $this->obj->selectAll($this->case_herb_tbl, array('sql' => '`case_id`=?', 'vals' => array($case_id)), 'sort asc '); return $this->obj->selectAll($this->case_herb_tbl, array('sql' => '`case_id`=?', 'vals' => array($case_id)), 'sort asc ');
} }
public function getCaseHerbByCaseIds($case_ids) {
return $this->obj->selectIn($this->case_herb_tbl, array('case_id' => $case_ids));
}
public function getCaseByName($uid, $name, $page_num, $page_size) { public function getCaseByName($uid, $name, $page_num, $page_size) {
$offset = ($page_num - 1) * $page_size; $offset = ($page_num - 1) * $page_size;
$sql = "select c.id,c.name,c.source,c.original,c.method,u.use_num,c.sort from {$this->tbl} as c left join {$this->case_use_log_tbl} as u on c.id=u.case_id and u.uid={$uid} where c.`name` like '%{$name}%' order by u.use_num desc,c.sort desc limit {$offset},{$page_size}"; $sql = "select c.id,c.name,c.source,c.original,c.method,u.use_num,c.sort from {$this->tbl} as c left join {$this->case_use_log_tbl} as u on c.id=u.case_id and u.uid={$uid} where c.`name` like '%{$name}%' order by u.use_num desc,c.sort desc limit {$offset},{$page_size}";
return $this->obj->execute($sql, true, true); return $this->obj->execute($sql, true, true);
} }
public function getCaseList($uid, $name, $page_num, $page_size) {
$case = $this->getCaseByName($uid, $name, $page_num, $page_size);
if (empty($case)) {
$this->setError('查询不到此药方');
return false;
}
$case_ids = array();
foreach ($case as &$item){
$item['original'] = json_decode($item['original'], true);
$case_ids[] = $item['id'];
}
//药方药材信息
$case_herbs = $this->getCaseHerbByCaseIds($case_ids);
if (empty($case_herbs)) {
$this->setError('药方药材查询失败');
return false;
}
//药材名称
$herb_ids = array_column($case_herbs, 'herb_id');
$herb = $this->getHerbByIds($herb_ids);
if (empty($herb)) {
$this->setError('药材名称查询失败');
return false;
}
$case_herb = array();
foreach ($case_herbs as $item){
$case_herb[$item['case_id']][] = $item;
}
return array('case' => $case, 'case_herb' => $case_herb, 'herb' => array_column($herb, null, 'id'));
}
public function getCaseByNameTotal($name) { public function getCaseByNameTotal($name) {
$where = array(); $where = array();
if (!empty($name)) { if (!empty($name)) {
@ -246,7 +286,7 @@ class mCase extends mBase {
return false; return false;
} }
return array('case' => $case, 'case_herb' => $case_herb, 'herb' => array_column($herb, null, 'id'),); return array('case' => $case, 'case_herb' => $case_herb, 'herb' => array_column($herb, null, 'id'));
} }
public function getCaseById($id) { public function getCaseById($id) {

Loading…
Cancel
Save