|
|
@ -22,7 +22,7 @@ class mCase extends mBase { |
|
|
|
$this->case_use_log_tbl = 'tcm_case_use_log'; |
|
|
|
} |
|
|
|
|
|
|
|
public function createCase($name, $source, $original, $method, $herbs) { |
|
|
|
public function createCase($name, $source, $method, $herbs) { |
|
|
|
if (empty($name)) { |
|
|
|
$this->setError('药方名称不能为空'); |
|
|
|
return false; |
|
|
@ -31,10 +31,6 @@ class mCase extends mBase { |
|
|
|
$this->setError('药方来源不能为空'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (empty($original)) { |
|
|
|
$this->setError('药方原方不能为空'); |
|
|
|
return false; |
|
|
|
} |
|
|
|
if (empty($method)) { |
|
|
|
$this->setError('药方用法不能为空'); |
|
|
|
return false; |
|
|
@ -44,6 +40,9 @@ class mCase extends mBase { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
//保存原方 |
|
|
|
$original = json_encode($herbs, JSON_UNESCAPED_UNICODE); |
|
|
|
|
|
|
|
$id = $this->obj->insert($this->tbl, array('name' => $name, 'source' => $source, 'original' => $original, 'method' => $method)); |
|
|
|
if (!$id) { |
|
|
|
$this->setError('添加失败'); |
|
|
@ -88,21 +87,55 @@ class mCase extends mBase { |
|
|
|
$case_herb = array(); |
|
|
|
foreach ($herbs as $key => $item) { |
|
|
|
$temp = array(); |
|
|
|
$temp['name'] = $item['name']; |
|
|
|
$temp['case_id'] = $case_id; |
|
|
|
$temp['num'] = $item['num']; |
|
|
|
$temp['num'] = $this->convertToNum('汉', $item['num'], $item['name']); |
|
|
|
$temp['sort'] = $key; |
|
|
|
|
|
|
|
$herb = $this->getHerbByName($item['name']); |
|
|
|
if ($herb) { |
|
|
|
$temp['herb_id'] = $herb['id']; |
|
|
|
} else { |
|
|
|
$temp['herb_id'] = $this->createHerb(array('name' => $item['name'])); |
|
|
|
$temp['herb_id'] = $this->createHerb(array('name' => $item['name'], 'desc' => $item['desc'])); |
|
|
|
} |
|
|
|
$case_herb[] = $temp; |
|
|
|
} |
|
|
|
|
|
|
|
return $case_herb; |
|
|
|
} |
|
|
|
|
|
|
|
public function convertToNum($from, $str, $herb_name) { |
|
|
|
$num_list = $GLOBALS['num_list']; |
|
|
|
$num_list_arr = array_merge(array_keys($GLOBALS['num_list']['num']), array_keys($GLOBALS['num_list']['unit'])); |
|
|
|
$weight_list = $GLOBALS['weight_list'][$from]; |
|
|
|
$weight_list_arr = array_keys($GLOBALS['weight_list'][$from]); |
|
|
|
|
|
|
|
$unit = str_replace($num_list_arr, '', $str); |
|
|
|
$weight = isset($weight_list[$unit]) ? $weight_list[$unit] : 0; |
|
|
|
if (isset($weight[$herb_name])) $weight = $weight[$herb_name]; |
|
|
|
|
|
|
|
$num = 0; |
|
|
|
$temp = 0; |
|
|
|
|
|
|
|
$num_str = str_replace($weight_list_arr, '', $str); |
|
|
|
$length = mb_strlen($num_str); |
|
|
|
for ($i = 0; $i < $length; $i++) { |
|
|
|
$char = mb_substr($num_str, $i, 1); |
|
|
|
|
|
|
|
if (isset($num_list['num'][$char])) { |
|
|
|
$temp = $num_list['num'][$char]; |
|
|
|
} elseif (isset($num_list['unit'][$char])) { |
|
|
|
$temp = ($temp == 0 ? 1 : $temp) * $num_list['unit'][$char]; |
|
|
|
$num += $temp; // 将临时结果累加到最终结果中 |
|
|
|
$temp = 0; // 重置临时结果 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$num += $temp; |
|
|
|
|
|
|
|
return $num * $weight; |
|
|
|
} |
|
|
|
|
|
|
|
public function getHerbByName($name) { |
|
|
|
return $this->obj->select($this->herb_tbl, array('sql' => '`name`=?', 'vals' => array($name))); |
|
|
|
} |
|
|
@ -182,7 +215,7 @@ class mCase extends mBase { |
|
|
|
|
|
|
|
public function getCaseByNameTotal($name) { |
|
|
|
$where = array(); |
|
|
|
if(!empty($name)) { |
|
|
|
if (!empty($name)) { |
|
|
|
$sql = " `name` like '%{$name}%'"; |
|
|
|
$where = array('sql' => $sql, 'vals' => array()); |
|
|
|
} |
|
|
@ -213,11 +246,7 @@ class mCase extends mBase { |
|
|
|
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) { |
|
|
|