|
@ -20,12 +20,16 @@ class mCase extends mBase { |
|
|
$this->collect_log_tbl = 'tcm_collect_log'; |
|
|
$this->collect_log_tbl = 'tcm_collect_log'; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function createCase($data, $herbs){ |
|
|
public function createCase($name, $source, $original, $method, $herbs){ |
|
|
$id = $this->obj->insert($this->tbl, $data); |
|
|
if(empty($name)){$this->setError('药方名称不能为空');return false;} |
|
|
if(!$id){ |
|
|
if(empty($source)){$this->setError('药方来源不能为空');return false;} |
|
|
$this->setError('添加失败'); |
|
|
if(empty($original)){$this->setError('药方原方不能为空');return false;} |
|
|
return false; |
|
|
if(empty($method)){$this->setError('药方用法不能为空');return false;} |
|
|
} |
|
|
if(empty($herbs)){$this->setError('药方药材不能为空');return false;} |
|
|
|
|
|
|
|
|
|
|
|
$id = $this->obj->insert($this->tbl, array('name'=>$name, 'source'=>$source, 'original'=>$original, 'method'=>$method)); |
|
|
|
|
|
if(!$id){$this->setError('添加失败');return false;} |
|
|
|
|
|
|
|
|
//格式化药方对应的药材数据 |
|
|
//格式化药方对应的药材数据 |
|
|
$case_herb = $this->formatCaseHerb($id, $herbs); |
|
|
$case_herb = $this->formatCaseHerb($id, $herbs); |
|
|
//创建药方对应的药材 |
|
|
//创建药方对应的药材 |
|
@ -34,12 +38,18 @@ class mCase extends mBase { |
|
|
return $id; |
|
|
return $id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function updateCase($id, $data, $herbs){ |
|
|
public function updateCase($id, $name, $source, $original, $method, $herbs){ |
|
|
|
|
|
if(empty($herbs)){$this->setError('药方药材不能为空');return false;} |
|
|
|
|
|
|
|
|
|
|
|
$data = array(); |
|
|
|
|
|
if(!empty($name)){$data['name']=$name;} |
|
|
|
|
|
if(!empty($source)){$data['source']=$source;} |
|
|
|
|
|
if(!empty($original)){$data['original']=$original;} |
|
|
|
|
|
if(!empty($method)){$data['method']=$method;} |
|
|
|
|
|
|
|
|
$res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=?', 'vals'=>array($id))); |
|
|
$res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=?', 'vals'=>array($id))); |
|
|
if(!$res){ |
|
|
if(!$res){$this->setError('更新失败');return false;} |
|
|
$this->setError('更新失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//格式化药方对应的药材数据 |
|
|
//格式化药方对应的药材数据 |
|
|
$case_herb = $this->formatCaseHerb($id, $herbs); |
|
|
$case_herb = $this->formatCaseHerb($id, $herbs); |
|
|
//更新药方对应的药材 |
|
|
//更新药方对应的药材 |
|
@ -73,19 +83,15 @@ class mCase extends mBase { |
|
|
|
|
|
|
|
|
public function createHerb($info){ |
|
|
public function createHerb($info){ |
|
|
$herb_id = $this->obj->insert($this->herb_tbl, $info); |
|
|
$herb_id = $this->obj->insert($this->herb_tbl, $info); |
|
|
if(empty($herb_id)){ |
|
|
if(empty($herb_id)){$this->setError('添加药材失败');return false;} |
|
|
$this->setError('添加药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return $herb_id; |
|
|
return $herb_id; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function createCaseHerb($info){ |
|
|
public function createCaseHerb($info){ |
|
|
$res = $this->obj->mutiInsert($this->case_herb_tbl, $info); |
|
|
$res = $this->obj->mutiInsert($this->case_herb_tbl, $info); |
|
|
if(!$res){ |
|
|
if(!$res){$this->setError('添加药方药材失败');return false;} |
|
|
$this->setError('添加药方药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
return true; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -100,32 +106,20 @@ class mCase extends mBase { |
|
|
foreach ($old_data as $key => $value) { |
|
|
foreach ($old_data as $key => $value) { |
|
|
if(!isset($new_data[$key])){ |
|
|
if(!isset($new_data[$key])){ |
|
|
$res = $this->obj->delete($this->case_herb_tbl, array('sql'=>'`id`=?', 'vals'=>array($value['id']))); |
|
|
$res = $this->obj->delete($this->case_herb_tbl, array('sql'=>'`id`=?', 'vals'=>array($value['id']))); |
|
|
if(!$res){ |
|
|
if(!$res){$this->setError('删除药方药材失败');return false;} |
|
|
$this->setError('删除药方药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
$res = $this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql'=>'`id`=?', 'vals'=>array($value['id']))); |
|
|
$res = $this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql'=>'`id`=?', 'vals'=>array($value['id']))); |
|
|
if(!$res){ |
|
|
if(!$res){$this->setError('更新药方药材失败');return false;} |
|
|
$this->setError('更新药方药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
}else{ |
|
|
}else{ |
|
|
//需要增加药方对应的药材 |
|
|
//需要增加药方对应的药材 |
|
|
foreach ($new_data as $key => $value) { |
|
|
foreach ($new_data as $key => $value) { |
|
|
if(!isset($old_data[$key])){ |
|
|
if(!isset($old_data[$key])){ |
|
|
$res = $this->obj->insert($this->case_herb_tbl, $value); |
|
|
$res = $this->obj->insert($this->case_herb_tbl, $value); |
|
|
if(!$res){ |
|
|
if(!$res){$this->setError('添加药方药材失败');return false;} |
|
|
$this->setError('添加药方药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
$this->obj->update($this->case_herb_tbl, $value, array('sql'=>'`id`=?', 'vals'=>array($old_data[$key]['id']))); |
|
|
|
|
|
if(!$res){ |
|
|
|
|
|
$this->setError('更新药方药材失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
$res = $this->obj->update($this->case_herb_tbl, $value, array('sql'=>'`id`=?', 'vals'=>array($old_data[$key]['id']))); |
|
|
|
|
|
if(!$res){$this->setError('更新药方药材失败');return false;} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -148,29 +142,20 @@ class mCase extends mBase { |
|
|
public function getCaseInfo($id) { |
|
|
public function getCaseInfo($id) { |
|
|
//药方信息 |
|
|
//药方信息 |
|
|
$case = $this->getCaseById($id); |
|
|
$case = $this->getCaseById($id); |
|
|
if(empty($case)){ |
|
|
if(empty($case)){$this->setError('查询不到此药方');return false;} |
|
|
$this->setError('查询不到此药方'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//药方药材信息 |
|
|
//药方药材信息 |
|
|
$case_herb = $this->getCaseHerbByCaseId($case['id']); |
|
|
$case_herb = $this->getCaseHerbByCaseId($case['id']); |
|
|
if(empty($case_herb)){ |
|
|
if(empty($case_herb)){$this->setError('药方药材查询失败');return false;} |
|
|
$this->setError('药方药材查询失败'); |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
//药材名称 |
|
|
//药材名称 |
|
|
$herb_ids = array_column($case_herb,'herb_id'); |
|
|
$herb_ids = array_column($case_herb,'herb_id'); |
|
|
$herb = $this->getHerbByIds($herb_ids); |
|
|
$herb = $this->getHerbByIds($herb_ids); |
|
|
if(empty($herb)){ |
|
|
if(empty($herb)){$this->setError('药材名称查询失败');return false;} |
|
|
$this->setError('药材名称查询失败'); |
|
|
|
|
|
return false; |
|
|
return array( |
|
|
} |
|
|
|
|
|
$data = array( |
|
|
|
|
|
'case' => $case, |
|
|
'case' => $case, |
|
|
'case_herb' => $case_herb, |
|
|
'case_herb' => $case_herb, |
|
|
'herb' => array_column($herb,null,'id'), |
|
|
'herb' => array_column($herb,null,'id'), |
|
|
); |
|
|
); |
|
|
return $data; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public function getCaseById($id){ |
|
|
public function getCaseById($id){ |
|
@ -188,9 +173,10 @@ class mCase extends mBase { |
|
|
public function updateCaseSearchNum($id){ |
|
|
public function updateCaseSearchNum($id){ |
|
|
$res = $this->obj->increase($this->tbl, array('sql'=>'`id`=?', 'vals'=>array($id)),'use_num'); |
|
|
$res = $this->obj->increase($this->tbl, array('sql'=>'`id`=?', 'vals'=>array($id)),'use_num'); |
|
|
if(!$res){ |
|
|
if(!$res){ |
|
|
$this->setError('药方使用次数更新失败'); |
|
|
|
|
|
$tool_obj = new qTool(); |
|
|
$tool_obj = new qTool(); |
|
|
$tool_obj->trackLog('tcm', $id, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_case_use_num')); |
|
|
$tool_obj->trackLog('tcm', $id, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_case_use_num')); |
|
|
|
|
|
|
|
|
|
|
|
$this->setError('药方使用次数更新失败'); |
|
|
return false; |
|
|
return false; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|