Browse Source

分页相关优化

pull/1/head
pengda 9 months ago
parent
commit
f5bc2c0166
  1. 59
      control/index.php
  2. 10
      model/mCase.php
  3. 64
      model/mUserCase.php

59
control/index.php

@ -57,8 +57,9 @@ class index extends publicBase {
$m_case = new mCase(); $m_case = new mCase();
$data = $m_case->getCaseByName($content, $page_num, $page_size); $data = $m_case->getCaseByName($content, $page_num, $page_size);
$total = $m_case->getCaseByNameTotal($content);
$this->ajax_json(true, '获取成功', $data); $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), 'list' => $data));
} }
public function ajax_case_detail() { public function ajax_case_detail() {
@ -78,6 +79,10 @@ class index extends publicBase {
$case_id = $this->post('case_id')+0; $case_id = $this->post('case_id')+0;
if(empty($uid) || empty($token) || empty($case_id))$this->ajax_json(false, '非法请求'); if(empty($uid) || empty($token) || empty($case_id))$this->ajax_json(false, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$data = array( $data = array(
'name' => trim($this->post('name')), 'name' => trim($this->post('name')),
'patient_name' => trim($this->post('patient_name')), 'patient_name' => trim($this->post('patient_name')),
@ -91,7 +96,7 @@ class index extends publicBase {
); );
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$id = $m_user_case->createUserCase($uid, $token, $case_id, $data); $id = $m_user_case->createUserCase($uid, $case_id, $data);
if(!$id)$this->ajax_json(false, $m_user_case->getError()); if(!$id)$this->ajax_json(false, $m_user_case->getError());
$this->ajax_json(true, '保存成功',array('id' => $id)); $this->ajax_json(true, '保存成功',array('id' => $id));
@ -103,13 +108,17 @@ class index extends publicBase {
$id = $this->post('id')+0; $id = $this->post('id')+0;
if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求'); if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$data = array( $data = array(
'name' => trim($this->post('name')), 'name' => trim($this->post('name')),
'feedback' => trim($this->post('feedback')), 'feedback' => trim($this->post('feedback')),
); );
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$res = $m_user_case->updateUserCase($uid, $token, $id, $data); $res = $m_user_case->updateUserCase($uid, $id, $data);
if(!$res)$this->ajax_json(false, $m_user_case->getError()); if(!$res)$this->ajax_json(false, $m_user_case->getError());
$this->ajax_json(true, '保存成功',array('id' => $id)); $this->ajax_json(true, '保存成功',array('id' => $id));
@ -120,14 +129,26 @@ class index extends publicBase {
$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, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$page_num = $this->post('page_num') ? $this->post('page_num') : 1; $page_num = $this->post('page_num') ? $this->post('page_num') : 1;
$page_size = $this->post('page_size') ? $this->post('page_size') : 100; $page_size = $this->post('page_size') ? $this->post('page_size') : 100;
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseList($uid, $token, $page_num, $page_size); $data = $m_user_case->getUserCaseList($uid, array(), $page_num, $page_size);
if(!$data)$this->ajax_json(false, $m_user_case->getError()); if(!$data)$this->ajax_json(false, $m_user_case->getError());
$total = $m_user_case->getUserCaseListCount($uid);
$this->ajax_json(true, '获取成功', $data); $return = array(
'total' => $total,
'current_page' => $page_num,
'total_page' => ceil($total/$page_size)
);
$return = array_merge($return, $data);
$this->ajax_json(true, '获取成功', $return);
} }
public function ajax_user_case_detail() { public function ajax_user_case_detail() {
@ -136,8 +157,12 @@ class index extends publicBase {
$id = $this->post('id')+0; $id = $this->post('id')+0;
if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求'); if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseInfo($uid, $token, $id); $data = $m_user_case->getUserCaseInfo($uid, $id);
if(!$data)$this->ajax_json(false, $m_user_case->getError()); if(!$data)$this->ajax_json(false, $m_user_case->getError());
$this->ajax_json(true, '获取成功', $data); $this->ajax_json(true, '获取成功', $data);
@ -149,8 +174,9 @@ class index extends publicBase {
$m_case = new mCase(); $m_case = new mCase();
$data = $m_case->getCollectLog($page_num, $page_size); $data = $m_case->getCollectLog($page_num, $page_size);
$total = $m_case->getCollectLogTotal();
$this->ajax_json(true, '获取成功', $data); $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), 'list' => $data));
} }
public function ajax_login(){ public function ajax_login(){
@ -188,20 +214,25 @@ class index extends publicBase {
$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, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$page_num = $this->post('page_num') ? $this->post('page_num') : 1; $page_num = $this->post('page_num') ? $this->post('page_num') : 1;
$page_size = $this->post('page_size') ? $this->post('page_size') : 100; $page_size = $this->post('page_size') ? $this->post('page_size') : 100;
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseList($uid, $token, $page_num, $page_size, true, true); $data = $m_user_case->getUserCaseList($uid, array(), $page_num, $page_size, true, true);
if(!$data)$this->ajax_json(false, $m_user_case->getError()); if(!$data)$this->ajax_json(false, $m_user_case->getError());
$total = $m_user_case->getUserCaseListCount($uid);
$data_key = sprintf(RQ_USER_CASE_DATA, $uid, 0); $data_key = sprintf(RQ_USER_CASE_DATA, $uid, 0);
$robj = $m_user_case->initRedis(); $robj = $m_user_case->initRedis();
$robj->setex($data_key,60,json_encode($data)); $robj->setex($data_key, 60, json_encode($data));
$pdf_url = $m_user_case->createPdf($uid, $data_key); $pdf_url = $m_user_case->createPdf($uid, $data_key);
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url)); $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), 'pdf_url' => $pdf_url));
} }
public function export_user_case(){ public function export_user_case(){
@ -210,14 +241,18 @@ class index extends publicBase {
$id = $this->post('id')+0; $id = $this->post('id')+0;
if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求'); if(empty($uid) || empty($token) || empty($id))$this->ajax_json(false, '非法请求');
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作');
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseInfo($uid, $token, $id, true); $data = $m_user_case->getUserCaseInfo($uid, $id, true);
if(!$data)$this->ajax_json(false, $m_user_case->getError()); if(!$data)$this->ajax_json(false, $m_user_case->getError());
$data_key = sprintf(RQ_USER_CASE_DATA, $uid, $id); $data_key = sprintf(RQ_USER_CASE_DATA, $uid, $id);
$robj = $m_user_case->initRedis(); $robj = $m_user_case->initRedis();
$robj->setex($data_key,60,json_encode($data)); $robj->setex($data_key, 60, json_encode($data));
$pdf_url = $m_user_case->createPdf($uid, $data_key); $pdf_url = $m_user_case->createPdf($uid, $data_key);
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url)); $this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url));

10
model/mCase.php

@ -140,6 +140,12 @@ class mCase extends mBase {
return $res; return $res;
} }
public function getCaseByNameTotal($name) {
$sql = " `name` like '%{$name}%'";
return $this->obj->count($this->tbl, array('sql'=>$sql, 'vals'=>array()));
}
public function getCaseInfo($id) { public function getCaseInfo($id) {
//药方信息 //药方信息
$case = $this->getCaseById($id); $case = $this->getCaseById($id);
@ -191,4 +197,8 @@ class mCase extends mBase {
return $this->obj->selectAll($this->collect_log_tbl, array(), 'collect_time desc ', array($offset, $page_size)); return $this->obj->selectAll($this->collect_log_tbl, array(), 'collect_time desc ', array($offset, $page_size));
} }
public function getCollectLogTotal() {
return $this->obj->count($this->collect_log_tbl, array());
}
} }

64
model/mUserCase.php

@ -15,14 +15,10 @@ class mUserCase extends mBase {
$this->user_herb_tbl = 'tcm_user_herb'; $this->user_herb_tbl = 'tcm_user_herb';
} }
public function updateUserCase($uid, $token, $id, $data){ public function updateUserCase($uid, $id, $data){
if(empty($data['name'])){$this->setError('药方名称不能为空');return false;} if(empty($data['name'])){$this->setError('药方名称不能为空');return false;}
if(empty($data['feedback'])){$this->setError('用药反馈不能为空');return false;} if(empty($data['feedback'])){$this->setError('用药反馈不能为空');return false;}
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login){$this->setError('请登录后操作');return false;}
$res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid))); $res = $this->obj->update($this->tbl, $data, array('sql'=>'`id`=? and `uid`=?', 'vals'=>array($id, $uid)));
if(!$res){$this->setError('更新失败');return false;} if(!$res){$this->setError('更新失败');return false;}
@ -69,7 +65,7 @@ class mUserCase extends mBase {
return json_encode($data); return json_encode($data);
} }
public function createUserCase($uid, $token, $case_id, $data){ public function createUserCase($uid, $case_id, $data){
if($case_id<=0){$this->setError('找不到相关药方');return false;} if($case_id<=0){$this->setError('找不到相关药方');return false;}
if(empty($data['patient_name'])){$this->setError('患者姓名不能为空');return false;} if(empty($data['patient_name'])){$this->setError('患者姓名不能为空');return false;}
if($data['patient_age']<=0){$this->setError('患者年龄不正确');return false;} if($data['patient_age']<=0){$this->setError('患者年龄不正确');return false;}
@ -80,10 +76,6 @@ class mUserCase extends mBase {
if(empty($data['first_diagnosis'])){$this->setError('舌诊脉诊不能为空');return false;} if(empty($data['first_diagnosis'])){$this->setError('舌诊脉诊不能为空');return false;}
if(empty($data['diagnosis'])){$this->setError('诊断不能为空');return false;} if(empty($data['diagnosis'])){$this->setError('诊断不能为空');return false;}
$m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token);
if(!$is_login){$this->setError('请登录后操作');return false;}
$m_case = new mCase(); $m_case = new mCase();
$case = $m_case->getCaseById($case_id); $case = $m_case->getCaseById($case_id);
if(!$case){$this->setError('找不到相关药方');return false;} if(!$case){$this->setError('找不到相关药方');return false;}
@ -104,11 +96,7 @@ class mUserCase extends mBase {
return $id; return $id;
} }
public function getUserCaseInfo($uid, $token, $id, $is_format_data = false){ public function getUserCaseInfo($uid, $id, $is_format_data = false){
$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)){$this->setError('找不到相关医案');return false;} if(empty($user_case)){$this->setError('找不到相关医案');return false;}
@ -135,21 +123,17 @@ class mUserCase extends mBase {
if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;} if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
$data = array( $data = array(
'user_case' => $user_case, 'data' => $user_case,
'case' => $case, 'case_data' => $case,
'herb' => array_column($herb,null,'id'), 'herb_data' => array_column($herb,null,'id'),
'user_herb' => array_column($user_herb,null,'id'), 'user_herb_data' => array_column($user_herb,null,'id'),
); );
if($is_format_data)return $this->formatUserCaseData($data); if($is_format_data)return $this->formatUserCaseData($data);
return $data; return $data;
} }
public function getUserCaseList($uid, $token, $page_num, $page_size, $get_case_herb = false, $is_format_data = false){ public function getUserCaseList($uid, $where, $page_num, $page_size, $get_case_herb = false, $is_format_data = 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; $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)); $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;} if(empty($user_case)){$this->setError('找不到相关医案');return false;}
@ -162,7 +146,7 @@ class mUserCase extends mBase {
$case = array_column($case,null,'id'); $case = array_column($case,null,'id');
if(!$get_case_herb)return array('user_case_list' => $user_case, 'case_list' => $case); if(!$get_case_herb)return array('list' => $user_case, 'case_data' => $case);
//获取医案开药详情 //获取医案开药详情
$herb_ids = $user_herb_ids = array(); $herb_ids = $user_herb_ids = array();
@ -185,43 +169,47 @@ class mUserCase extends mBase {
if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;} if(empty($herb) && empty($user_herb)){$this->setError('找不到相关药材');return false;}
$data = array( $data = array(
'user_case_list' => $user_case, 'list' => $user_case,
'case_list' => $case, 'case_data' => $case,
'herb' => array_column($herb,null,'id'), 'herb_data' => array_column($herb,null,'id'),
'user_herb' => array_column($user_herb,null,'id'), 'user_herb_data' => array_column($user_herb,null,'id'),
); );
if($is_format_data)return $this->formatUserCaseData($data); if($is_format_data)return $this->formatUserCaseData($data);
return $data; return $data;
} }
public function getUserCaseListCount($uid, $where=array()){
return $this->obj->count($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid)));
}
public function getUserHerbByIds($ids){ public function getUserHerbByIds($ids){
return $this->obj->selectIn($this->user_herb_tbl, array('id'=>$ids)); return $this->obj->selectIn($this->user_herb_tbl, array('id'=>$ids));
} }
public function formatUserCaseData($data){ public function formatUserCaseData($data){
//兼容单个医案导出pdf //兼容单个医案导出pdf
if(isset($data['user_case'])){ if(isset($data['data'])){
$data['user_case_list'][0] = $data['user_case']; $data['list'][0] = $data['data'];
unset($data['user_case']); unset($data['data']);
$data['case_list'][$data['case']['id']] = $data['case']; $data['list'][$data['case_data']['id']] = $data['case_data'];
unset($data['case']); unset($data['case_data']);
} }
foreach ($data['user_case_list'] as &$item){ foreach ($data['list'] as &$item){
$item['patient_sex'] = $item['patient_sex']==0?'男':'女'; $item['patient_sex'] = $item['patient_sex']==0?'男':'女';
$item['case_time'] = date('Y年m月d日',strtotime($item['case_time'])); $item['case_time'] = date('Y年m月d日',strtotime($item['case_time']));
$case = $data['case_list'][$item['case_id']]; $case = $data['case_data'][$item['case_id']];
$item['case_info'] = "选&nbsp;".$case['source']."&nbsp;".$case['name'].":"; $item['case_info'] = "选&nbsp;".$case['source']."&nbsp;".$case['name'].":";
$herb_arr = array(); $herb_arr = array();
foreach ($item['prescribe_herb'] as $herb){ foreach ($item['prescribe_herb'] as $herb){
if(strpos($herb['herb_id'],'u_')!==false){ if(strpos($herb['herb_id'],'u_')!==false){
$herb['herb_id'] = str_replace('u_','',$herb['herb_id']); $herb['herb_id'] = str_replace('u_','',$herb['herb_id']);
$herb_name = $data['user_herb'][$herb['herb_id']]['name']; $herb_name = $data['user_herb_data'][$herb['herb_id']]['name'];
}else{ }else{
$herb_name = $data['herb'][$herb['herb_id']]['name']; $herb_name = $data['herb_data'][$herb['herb_id']]['name'];
} }
$herb_arr[] = $herb_name.$herb['num']."克"; $herb_arr[] = $herb_name.$herb['num']."克";
} }

Loading…
Cancel
Save