Browse Source

药方相关接口数据优化

pull/1/head
pengda 9 months ago
parent
commit
7729392f32
  1. 89
      model/mCase.php

89
model/mCase.php

@ -218,39 +218,67 @@ class mCase extends mBase {
} }
public function getCaseList($uid, $name, $page_num, $page_size) { public function getCaseList($uid, $name, $page_num, $page_size) {
$case = $this->getCaseByName($uid, $name, $page_num, $page_size); $case_data = $this->getCaseByName($uid, $name, $page_num, $page_size);
if (empty($case)) { if (empty($case_data)) {
$this->setError('查询不到此药方'); $this->setError('查询不到此药方');
return false; return false;
} }
$case_ids = array(); $case_ids = array_column($case_data, 'id');
foreach ($case as &$item) {
$item['original'] = json_decode($item['original'], true);
$case_ids[] = $item['id'];
}
//药方药材信息 //药方药材信息
$case_herbs = $this->getCaseHerbByCaseIds($case_ids); $case_herbs = $this->getCaseHerbByCaseIds($case_ids);
if (empty($case_herbs)) { if (empty($case_herbs)) {
$this->setError('药方药材查询失败'); $this->setError('药方药材查询失败');
return false; return false;
} }
$herb_ids = array_column($case_herbs, 'herb_id');
//药材名称 //药材名称
$herb_ids = array_column($case_herbs, 'herb_id');
$herb = $this->getHerbByIds($herb_ids); $herb = $this->getHerbByIds($herb_ids);
if (empty($herb)) { if (empty($herb)) {
$this->setError('药材名称查询失败'); $this->setError('药材名称查询失败');
return false; return false;
} }
$herb_list = array_column($herb, null, 'id');
$case_herb = array(); $case_list = array();
foreach ($case_herbs as $v) { foreach ($case_data as $item) {
$case_herb[$v['case_id']][] = $v; $case = array(
'id' => $item['id'],
'name' => $item['name'],
'source' => $item['source'],
'method' => $item['method'],
'use_num' => $item['use_num'],
'sort' => $item['sort'],
'case_herb' => array()
);
$original = json_decode($item['original'], true);
foreach ($case_herbs as $value) {
if ($item['id'] != $value['case_id']) continue;
$temp = array(
'name' => $herb_list[$value['herb_id']]['name'],
'num' => $value['num'],
'org_num' => '',
'desc' => $value['desc'],
'org_desc' => '',
);
foreach ($original as $v) {
if ($temp['name'] == $v['name']) {
$temp['org_num'] = $v['num'];
$temp['org_desc'] = $v['desc'];
}
}
$case['case_herb'][] = $temp;
} }
return array('case' => $case, 'case_herb' => $case_herb, 'herb' => array_column($herb, null, 'id')); $case_list[] = $case;
}
return $case_list;
} }
public function getCaseByNameTotal($name) { public function getCaseByNameTotal($name) {
@ -270,24 +298,49 @@ class mCase extends mBase {
$this->setError('查询不到此药方'); $this->setError('查询不到此药方');
return false; return false;
} }
$case['original'] = json_decode($case['original'], true);
//药方药材信息 //药方药材信息
$case_herb = $this->getCaseHerbByCaseId($case['id']); $case_herb_date = $this->getCaseHerbByCaseId($case['id']);
if (empty($case_herb)) { if (empty($case_herb_date)) {
$this->setError('药方药材查询失败'); $this->setError('药方药材查询失败');
return false; return false;
} }
//药材名称 //药材名称
$herb_ids = array_column($case_herb, 'herb_id'); $herb_ids = array_column($case_herb_date, 'herb_id');
$herb = $this->getHerbByIds($herb_ids); $herb = $this->getHerbByIds($herb_ids);
if (empty($herb)) { if (empty($herb)) {
$this->setError('药材名称查询失败'); $this->setError('药材名称查询失败');
return false; return false;
} }
$herb_list = array_column($herb, null, 'id');
$original = json_decode($case['original'], true);
unset($case['original']);
$case_herb = array();
foreach ($case_herb_date as $item) {
$temp = array(
'name' => $herb_list[$item['herb_id']]['name'],
'num' => $item['num'],
'org_num' => '',
'desc' => $item['desc'],
'org_desc' => '',
);
foreach ($original as $v) {
if ($temp['name'] == $v['name']) {
$temp['org_num'] = $v['num'];
$temp['org_desc'] = $v['desc'];
}
}
$case_herb[] = $temp;
}
$case['case_herb'] = $case_herb;
return array('case' => $case, 'case_herb' => $case_herb, 'herb' => array_column($herb, null, 'id')); return $case;
} }
public function getCaseById($id) { public function getCaseById($id) {

Loading…
Cancel
Save