Browse Source

获取医案相关优化

pull/1/head
pengda 9 months ago
parent
commit
ae313e4206
  1. 51
      control/index.php
  2. 74
      model/mUserCase.php

51
control/index.php

@ -19,10 +19,10 @@ class index extends publicBase {
} }
public function ajax_save_case() { public function ajax_save_case() {
$name = $this->post('name'); $name = trim($this->post('name'));
$source = $this->post('source'); $source = trim($this->post('source'));
$original = $this->post('original'); $original = trim($this->post('original'));
$method = $this->post('method'); $method = trim($this->post('method'));
$herbs = $this->post('herbs'); $herbs = $this->post('herbs');
//新增药方 //新增药方
@ -34,11 +34,11 @@ class index extends publicBase {
} }
public function ajax_update_case() { public function ajax_update_case() {
$id = $this->post('id'); $id = $this->post('id')+0;
$name = $this->post('name'); $name = trim($this->post('name'));
$source = $this->post('source'); $source = trim($this->post('source'));
$original = $this->post('original'); $original = trim($this->post('original'));
$method = $this->post('method'); $method = trim($this->post('method'));
$herbs = $this->post('herbs'); $herbs = $this->post('herbs');
$m_case = new mCase(); $m_case = new mCase();
@ -62,7 +62,7 @@ class index extends publicBase {
} }
public function ajax_case_detail() { public function ajax_case_detail() {
$id = $this->get('id'); $id = $this->get('id')+0;
if(empty($id))$this->ajax_json(false, '非法请求'); if(empty($id))$this->ajax_json(false, '非法请求');
$m_case = new mCase(); $m_case = new mCase();
@ -115,29 +115,30 @@ class index extends publicBase {
$this->ajax_json(true, '保存成功',array('id' => $id)); $this->ajax_json(true, '保存成功',array('id' => $id));
} }
public function ajax_user_case() { public function ajax_user_case_list() {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
if(empty($uid) || empty($token))$this->ajax_json(false, '非法请求'); if(empty($uid) || empty($token))$this->ajax_json(false, '非法请求');
$mUser = new mUser(); $page_num = $this->post('page_num') ? $this->post('page_num') : 1;
$is_login = $mUser->validateToken($uid,$token); $page_size = $this->post('page_size') ? $this->post('page_size') : 100;
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$start = $this->post('start') ? $this->post('start') : 0;
$pagesize = $this->post('pagesize') ? $this->post('pagesize') : 500;
$mUserCase = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseList($uid, $token, $page_num, $page_size);
if(!$data)$this->ajax_json(false, $m_user_case->getError());
$id = $this->post('id'); $this->ajax_json(true, '获取成功', $data);
if($id){ }
$data = $mUserCase->getUserCaseInfo($id, $uid);
if(!$data)$this->ajax_json(false, $mUserCase->getError());
$this->ajax_json(true, '获取成功', $data); public function ajax_user_case_detail() {
} $id = $this->post('id')+0;
$uid = $this->post('uid');
$token = $this->post('token');
if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求');
$data = $mUserCase->getUserCaseList($uid, $start, $pagesize); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseInfo($uid, $token, $id);
if(!$data)$this->ajax_json(false, $m_user_case->getError());
$this->ajax_json(true, '获取成功', $data); $this->ajax_json(true, '获取成功', $data);
} }

74
model/mUserCase.php

@ -104,22 +104,20 @@ class mUserCase extends mBase {
return $id; return $id;
} }
public function getUserCaseInfo($id, $uid){ public function getUserCaseInfo($uid, $token, $id){
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login){$this->setError('请登录后操作');return false;}
$user_case = $this->obj->select($this->tbl, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid))); $user_case = $this->obj->select($this->tbl, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid)));
if(empty($user_case)){ if(empty($user_case)){$this->setError('找不到相关医案');return false;}
$this->setError('找不到相关医案');
return false;
}
$prescribe_herb = json_decode($user_case['prescribe_herb'],true); $prescribe_herb = json_decode($user_case['prescribe_herb'],true);
$user_case['prescribe_herb'] = $prescribe_herb; $user_case['prescribe_herb'] = $prescribe_herb;
$mCase = new mCase(); $mCase = new mCase();
$case = $mCase->getCaseById($user_case['case_id']); $case = $mCase->getCaseById($user_case['case_id']);
if(empty($case)){ if(empty($case)){$this->setError('找不到相关药方');return false;}
$this->setError('找不到相关药方');
return false;
}
$herb_ids = $user_herb_ids = array(); $herb_ids = $user_herb_ids = array();
foreach ($prescribe_herb as $item){ foreach ($prescribe_herb as $item){
@ -129,50 +127,41 @@ class mUserCase extends mBase {
} }
$herb_ids[] =$item['herb_id']; $herb_ids[] =$item['herb_id'];
} }
if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;}
$mCase = new mCase(); $mCase = new mCase();
$herb = $mCase->getHerbByIds($herb_ids); $herb = $mCase->getHerbByIds($herb_ids);
$user_herb = $this->getUserHerbByIds($user_herb_ids); $user_herb = $this->getUserHerbByIds($user_herb_ids);
if(empty($herb) && empty($user_herb)){ if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
$this->setError('找不到相关药材');
return false;
}
$data = array( return array(
'user_case' => $user_case, 'user_case' => $user_case,
'case' => $case, 'case' => $case,
'herb' => array_column($herb,null,'id'), 'herb' => array_column($herb,null,'id'),
'user_herb' => array_column($user_herb,null,'id'), 'user_herb' => array_column($user_herb,null,'id'),
); );
return $data;
} }
public function getUserCaseList($uid, $start, $pagesize, $get_case_herb = false){ public function getUserCaseList($uid, $token, $page_num, $page_size, $get_case_herb = false){
$user_case = $this->obj->selectAll($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid)), 'case_time desc ', array($start, $pagesize)); $m_user = new mUser();
if(empty($user_case)){ $is_login = $m_user->validateToken($uid,$token);
$this->setError('找不到相关医案'); if(!$is_login){$this->setError('请登录后操作');return false;}
return false;
} $offset = ($page_num - 1) * $page_size;
$user_case = $this->obj->selectAll($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid)), 'case_time desc ', array($offset, $page_size));
if(empty($user_case)){$this->setError('找不到相关医案');return false;}
$case_ids = array_column($user_case,'case_id'); $case_ids = array_column($user_case,'case_id');
$mCase = new mCase(); $m_case = new mCase();
$case = $mCase->getCaseByIds($case_ids); $case = $m_case->getCaseByIds($case_ids);
if(empty($case)){ if(empty($case)){$this->setError('找不到相关药方');return false;}
$this->setError('找不到相关药方');
return false;
}
$case = array_column($case,null,'id');
if(!$get_case_herb){ $case = array_column($case,null,'id');
$data = array(
'user_case_list' => $user_case,
'case_list' => $case,
);
return $data; if(!$get_case_herb)return array('user_case_list' => $user_case, 'case_list' => $case);
}
//获取医案开药详情
$herb_ids = $user_herb_ids = array(); $herb_ids = $user_herb_ids = array();
foreach ($user_case as &$item){ foreach ($user_case as &$item){
$prescribe_herb = json_decode($item['prescribe_herb'],true); $prescribe_herb = json_decode($item['prescribe_herb'],true);
@ -186,23 +175,18 @@ class mUserCase extends mBase {
$herb_ids[] = $herb_item['herb_id']; $herb_ids[] = $herb_item['herb_id'];
} }
} }
if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;}
$mCase = new mCase(); $herb = $m_case->getHerbByIds($herb_ids);
$herb = $mCase->getHerbByIds($herb_ids);
$user_herb = $this->getUserHerbByIds($user_herb_ids); $user_herb = $this->getUserHerbByIds($user_herb_ids);
if(empty($herb) && empty($user_herb)){ if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
$this->setError('找不到相关药材');
return false;
}
$data = array( return array(
'user_case_list' => $user_case, 'user_case_list' => $user_case,
'case_list' => $case, 'case_list' => $case,
'herb' => array_column($herb,null,'id'), 'herb' => array_column($herb,null,'id'),
'user_herb' => array_column($user_herb,null,'id'), 'user_herb' => array_column($user_herb,null,'id'),
); );
return $data;
} }
public function getUserHerbByIds($ids){ public function getUserHerbByIds($ids){

Loading…
Cancel
Save