diff --git a/config/define.php b/config/define.php
index 1add7a2..f2eb18c 100644
--- a/config/define.php
+++ b/config/define.php
@@ -80,19 +80,77 @@
'斤'=>249.6,
'担'=>24960,
'合'=>array(
- '水'=>'',
- '米'=>'',
- '蜂蜜'=>'',
- '酒'=>'',
+ '粳米'=>0,
+ '白蜜'=>0,
+ '人尿'=>0,
+ '猪胆汁'=>0,
+ '半夏'=>0,
+ '芒硝'=>0,
+ '蜀椒'=>0,
+ '食蜜'=>0,
+ '五味子'=>0,
+ '香豉'=>0,
+ ),
+ '升'=>array(
+ '半夏'=>134,
+ '芒硝'=>154,
+ '吴茱萸'=>104,
+ '五味子'=>88,
+ '麦门冬'=>108,
+ '赤小豆'=>150,
+ '小麦'=>0,
+ '杏仁'=>0,
+ '竹茹'=>0,
+ '白酒'=>0,
+ '麻仁'=>0,
+ '酸枣仁'=>0,
+ '粳米'=>0,
+ '饴糖'=>0,
+ '豉'=>0,
+ '地黄汁'=>0,
+ '虻虫'=>0,
+ '蛴螬'=>0,
+ '虫'=>0,
+ '胶饴'=>0,
+ '葶苈'=>0,
+ '大黄'=>0,
+ ),
+ '斗'=>array(
+ '白酒'=>0,
+ ),
+ '个'=>array(
+ '水蛭'=>3.6,
+ '附子'=>12,
+ '虻虫'=>0.16,
+ '杏仁'=>0.33,
+ '桃仁'=>0.34,
+ '大枣'=>4,
+ '栀子'=>0,
+ '瓜蒂'=>0,
+ ),
+ '片'=>array(
+ '鳖甲'=>0,
),
- '升'=>'',
- '斗'=>'',
- '个'=>'',
- '片'=>'',
'味'=>'',
- '把'=>'',
- '枚'=>'',
- '茎'=>'',
+ '把'=>array(
+ '艾叶'=>0,
+ ),
+ '枚'=>array(
+ '瓜蒌实'=>30,
+ '乌头'=>0,
+ '乌头大者'=>0,
+ '枳实'=>0,
+ '栀子'=>0,
+ '蜘蛛'=>0,
+ '大猪胆'=>0,
+ '百合'=>0,
+ '水蛭'=>0,
+ '附子'=>0,
+ '附子大者'=>0,
+ ),
+ '茎'=>array(
+ '葱白'=>0,
+ ),
'少许'=>'',
),
);
diff --git a/control/index.php b/control/index.php
index 82221c9..13ba6ba 100644
--- a/control/index.php
+++ b/control/index.php
@@ -36,13 +36,12 @@ class index extends publicBase {
public function ajax_save_case() {
$name = trim($this->post('name'));
$source = trim($this->post('source'));
- $original = trim($this->post('original'));
$method = trim($this->post('method'));
$herbs = $this->post('herbs');
//新增药方
$m_case = new mCase();
- $id = $m_case->createCase($name, $source, $original, $method, $herbs);
+ $id = $m_case->createCase($name, $source, $method, $herbs);
if (!$id) $this->ajax_json(false, $m_case->getError());
$this->ajax_json(true, '添加成功');
diff --git a/model/mCase.php b/model/mCase.php
index dfb1acb..36fc3a4 100644
--- a/model/mCase.php
+++ b/model/mCase.php
@@ -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) {
diff --git a/view/templates/index/home.html b/view/templates/index/home.html
index f097c50..620b58c 100644
--- a/view/templates/index/home.html
+++ b/view/templates/index/home.html
@@ -10,7 +10,7 @@
{literal}