diff --git a/control/index.php b/control/index.php index b8851d2..0a45067 100644 --- a/control/index.php +++ b/control/index.php @@ -19,10 +19,10 @@ class index extends publicBase { } public function ajax_save_case() { - $name = $this->post('name'); - $source = $this->post('source'); - $original = $this->post('original'); - $method = $this->post('method'); + $name = trim($this->post('name')); + $source = trim($this->post('source')); + $original = trim($this->post('original')); + $method = trim($this->post('method')); $herbs = $this->post('herbs'); //新增药方 @@ -34,11 +34,11 @@ class index extends publicBase { } public function ajax_update_case() { - $id = $this->post('id'); - $name = $this->post('name'); - $source = $this->post('source'); - $original = $this->post('original'); - $method = $this->post('method'); + $id = $this->post('id')+0; + $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(); @@ -62,7 +62,7 @@ class index extends publicBase { } public function ajax_case_detail() { - $id = $this->get('id'); + $id = $this->get('id')+0; if(empty($id))$this->ajax_json(false, '非法请求'); $m_case = new mCase(); @@ -115,29 +115,30 @@ class index extends publicBase { $this->ajax_json(true, '保存成功',array('id' => $id)); } - public function ajax_user_case() { + public function ajax_user_case_list() { $uid = $this->post('uid'); $token = $this->post('token'); if(empty($uid) || empty($token))$this->ajax_json(false, '非法请求'); - $mUser = new mUser(); - $is_login = $mUser->validateToken($uid,$token); - if(!$is_login)$this->ajax_json(false, '请登录后操作'); - - $start = $this->post('start') ? $this->post('start') : 0; - $pagesize = $this->post('pagesize') ? $this->post('pagesize') : 500; + $page_num = $this->post('page_num') ? $this->post('page_num') : 1; + $page_size = $this->post('page_size') ? $this->post('page_size') : 100; - $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'); - if($id){ - $data = $mUserCase->getUserCaseInfo($id, $uid); - if(!$data)$this->ajax_json(false, $mUserCase->getError()); + $this->ajax_json(true, '获取成功', $data); + } - $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); } diff --git a/model/mUserCase.php b/model/mUserCase.php index 0c3cc95..02f3702 100644 --- a/model/mUserCase.php +++ b/model/mUserCase.php @@ -104,22 +104,20 @@ class mUserCase extends mBase { 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))); - if(empty($user_case)){ - $this->setError('找不到相关医案'); - return false; - } + if(empty($user_case)){$this->setError('找不到相关医案');return false;} $prescribe_herb = json_decode($user_case['prescribe_herb'],true); $user_case['prescribe_herb'] = $prescribe_herb; $mCase = new mCase(); $case = $mCase->getCaseById($user_case['case_id']); - if(empty($case)){ - $this->setError('找不到相关药方'); - return false; - } + if(empty($case)){$this->setError('找不到相关药方');return false;} $herb_ids = $user_herb_ids = array(); foreach ($prescribe_herb as $item){ @@ -129,50 +127,41 @@ class mUserCase extends mBase { } $herb_ids[] =$item['herb_id']; } + if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;} $mCase = new mCase(); $herb = $mCase->getHerbByIds($herb_ids); $user_herb = $this->getUserHerbByIds($user_herb_ids); - if(empty($herb) && empty($user_herb)){ - $this->setError('找不到相关药材'); - return false; - } + if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;} - $data = array( + return array( 'user_case' => $user_case, 'case' => $case, 'herb' => array_column($herb,null,'id'), 'user_herb' => array_column($user_herb,null,'id'), ); - - return $data; } - public function getUserCaseList($uid, $start, $pagesize, $get_case_herb = false){ - $user_case = $this->obj->selectAll($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid)), 'case_time desc ', array($start, $pagesize)); - if(empty($user_case)){ - $this->setError('找不到相关医案'); - return false; - } + public function getUserCaseList($uid, $token, $page_num, $page_size, $get_case_herb = false){ + $m_user = new mUser(); + $is_login = $m_user->validateToken($uid,$token); + if(!$is_login){$this->setError('请登录后操作');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'); - $mCase = new mCase(); - $case = $mCase->getCaseByIds($case_ids); - if(empty($case)){ - $this->setError('找不到相关药方'); - return false; - } - $case = array_column($case,null,'id'); + $m_case = new mCase(); + $case = $m_case->getCaseByIds($case_ids); + if(empty($case)){$this->setError('找不到相关药方');return false;} - if(!$get_case_herb){ - $data = array( - 'user_case_list' => $user_case, - 'case_list' => $case, - ); + $case = array_column($case,null,'id'); - return $data; - } + if(!$get_case_herb)return array('user_case_list' => $user_case, 'case_list' => $case); + //获取医案开药详情 $herb_ids = $user_herb_ids = array(); foreach ($user_case as &$item){ $prescribe_herb = json_decode($item['prescribe_herb'],true); @@ -186,23 +175,18 @@ class mUserCase extends mBase { $herb_ids[] = $herb_item['herb_id']; } } + if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;} - $mCase = new mCase(); - $herb = $mCase->getHerbByIds($herb_ids); + $herb = $m_case->getHerbByIds($herb_ids); $user_herb = $this->getUserHerbByIds($user_herb_ids); - if(empty($herb) && empty($user_herb)){ - $this->setError('找不到相关药材'); - return false; - } + if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;} - $data = array( + return array( 'user_case_list' => $user_case, 'case_list' => $case, 'herb' => array_column($herb,null,'id'), 'user_herb' => array_column($user_herb,null,'id'), ); - - return $data; } public function getUserHerbByIds($ids){