Browse Source

代码风格

pull/1/head
pengda 9 months ago
parent
commit
537896470f
  1. 71
      control/index.php
  2. 12
      index.php
  3. 173
      model/mCase.php
  4. 12
      model/mUser.php
  5. 186
      model/mUserCase.php

71
control/index.php

@ -47,7 +47,7 @@ class index extends publicBase {
public function ajax_search() { public function ajax_search() {
$content = $this->post('content'); $content = $this->post('content');
if(empty($content))$this->ajax_json(false, '请输入方名'); if (empty($content))$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;
@ -61,11 +61,11 @@ class index extends publicBase {
public function ajax_case_detail() { public function ajax_case_detail() {
$id = $this->get('id')+0; $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();
$data = $m_case->getCaseInfo($id); $data = $m_case->getCaseInfo($id);
if(!$data)$this->ajax_json(false, $m_case->getError()); if (!$data) $this->ajax_json(false, $m_case->getError());
$this->ajax_json(true, '获取成功', $data); $this->ajax_json(true, '获取成功', $data);
} }
@ -74,11 +74,11 @@ class index extends publicBase {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
$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(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login) $this->ajax_json(false, '请登录后操作'); if (!$is_login) $this->ajax_json(false, '请登录后操作');
$data = array( $data = array(
'name' => trim($this->post('name')), 'name' => trim($this->post('name')),
@ -94,7 +94,7 @@ class index extends publicBase {
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$id = $m_user_case->createUserCase($uid, $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,11 +103,11 @@ class index extends publicBase {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
$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(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作'); if (!$is_login) $this->ajax_json(false, '请登录后操作');
$data = array( $data = array(
'name' => trim($this->post('name')), 'name' => trim($this->post('name')),
@ -116,7 +116,7 @@ class index extends publicBase {
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$res = $m_user_case->updateUserCase($uid, $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));
} }
@ -124,18 +124,18 @@ class index extends publicBase {
public function ajax_user_case_list() { 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, '非法请求');
$m_user = new mUser(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login)$this->ajax_json(false, '请登录后操作'); 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, $page_num, $page_size); $data = $m_user_case->getUserCaseList($uid, $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); $total = $m_user_case->getUserCaseListCount($uid);
$return = array( $return = array(
@ -152,15 +152,15 @@ class index extends publicBase {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
$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(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login) $this->ajax_json(false, '请登录后操作'); if (!$is_login) $this->ajax_json(false, '请登录后操作');
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseInfo($uid, $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);
} }
@ -178,14 +178,14 @@ class index extends publicBase {
public function ajax_login(){ public function ajax_login(){
$code = $this->get('code'); $code = $this->get('code');
if(!$code)$this->ajax_json(false, '非法请求'); if (!$code)$this->ajax_json(false, '非法请求');
$m_user = new mUser(); $m_user = new mUser();
$openid = $m_user->getOpenid($code); $openid = $m_user->getOpenid($code);
if(!$openid)$this->ajax_json(false, $m_user->getError()); if (!$openid)$this->ajax_json(false, $m_user->getError());
$user = $m_user->getUserByOpenid($openid); $user = $m_user->getUserByOpenid($openid);
if($user){ if ($user){
$token = $m_user->getToken($user['uid']); $token = $m_user->getToken($user['uid']);
$this->ajax_json(true, '登录成功', array('uid' => $user['uid'], 'token'=> $token)); $this->ajax_json(true, '登录成功', array('uid' => $user['uid'], 'token'=> $token));
} }
@ -193,10 +193,10 @@ class index extends publicBase {
//获取唯一uid串 //获取唯一uid串
$uid = $m_user->createUniqueUid($openid); $uid = $m_user->createUniqueUid($openid);
$user = $m_user->getUserByUid($uid); $user = $m_user->getUserByUid($uid);
if($user)$this->ajax_json(false, 'uid生成失败'); if ($user)$this->ajax_json(false, 'uid生成失败');
$id = $m_user->createUser(array('uid'=>$uid,'openid'=>$openid)); $id = $m_user->createUser(array('uid'=>$uid,'openid'=>$openid));
if(!$id)$this->ajax_json(false, '用户创建失败'); if (!$id)$this->ajax_json(false, '用户创建失败');
$token = $m_user->getToken($user['uid']); $token = $m_user->getToken($user['uid']);
$this->ajax_json(true, '登录成功', array('uid' => $user['uid'], 'token'=> $token)); $this->ajax_json(true, '登录成功', array('uid' => $user['uid'], 'token'=> $token));
@ -209,18 +209,18 @@ class index extends publicBase {
public function export_user_case_list(){ public function export_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, '非法请求');
$m_user = new mUser(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login) $this->ajax_json(false, '请登录后操作'); 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, $page_num, $page_size, true, true); $data = $m_user_case->getUserCaseList($uid, $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); $total = $m_user_case->getUserCaseListCount($uid);
$data_key = sprintf(RQ_USER_CASE_DATA, $uid, 0); $data_key = sprintf(RQ_USER_CASE_DATA, $uid, 0);
@ -236,15 +236,15 @@ class index extends publicBase {
$uid = $this->post('uid'); $uid = $this->post('uid');
$token = $this->post('token'); $token = $this->post('token');
$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(); $m_user = new mUser();
$is_login = $m_user->validateToken($uid,$token); $is_login = $m_user->validateToken($uid,$token);
if(!$is_login) $this->ajax_json(false, '请登录后操作'); if (!$is_login) $this->ajax_json(false, '请登录后操作');
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
$data = $m_user_case->getUserCaseInfo($uid, $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);
@ -255,8 +255,7 @@ class index extends publicBase {
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url)); $this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url));
} }
public function export_pdf() public function export_pdf(){
{
$key = $this->get('key'); $key = $this->get('key');
$m_user_case = new mUserCase(); $m_user_case = new mUserCase();
@ -269,26 +268,26 @@ class index extends publicBase {
public function ajax_mail(){ public function ajax_mail(){
$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(); $mUser = new mUser();
$is_login = $mUser->validateToken($uid,$token); $is_login = $mUser->validateToken($uid,$token);
if(!$is_login) $this->ajax_json(false, '请登录后操作'); if (!$is_login) $this->ajax_json(false, '请登录后操作');
$email = $this->post('email'); $email = $this->post('email');
if(empty($email)) $this->ajax_json(false, '邮箱地址不能为空'); if (empty($email)) $this->ajax_json(false, '邮箱地址不能为空');
if(!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->ajax_json(false, '邮箱地址无效'); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->ajax_json(false, '邮箱地址无效');
$pdf_url = $this->post('pdf_url'); $pdf_url = $this->post('pdf_url');
if(empty($pdf_url)) $this->ajax_json(false, 'pdf地址不能为空'); if (empty($pdf_url)) $this->ajax_json(false, 'pdf地址不能为空');
if(!filter_var($pdf_url, FILTER_VALIDATE_URL)) $this->ajax_json(false, 'pdf地址无效'); if (!filter_var($pdf_url, FILTER_VALIDATE_URL)) $this->ajax_json(false, 'pdf地址无效');
$directory_name = basename(dirname($pdf_url)); $directory_name = basename(dirname($pdf_url));
if($directory_name != $uid) $this->ajax_json(false, '非法请求'); if ($directory_name != $uid) $this->ajax_json(false, '非法请求');
$mUserCase = new mUserCase(); $mUserCase = new mUserCase();
$res = $mUserCase->sendMail(array($email),date('Y年m月d日',time()).'-医案导出','',sprintf(USER_CASE_PDF_PATH, $uid) . basename($pdf_url)); $res = $mUserCase->sendMail(array($email),date('Y年m月d日',time()).'-医案导出','',sprintf(USER_CASE_PDF_PATH, $uid) . basename($pdf_url));
if(!$res) $this->ajax_json(true, '发送失败'); if (!$res) $this->ajax_json(true, '发送失败');
$this->ajax_json(true, '发送成功'); $this->ajax_json(true, '发送成功');
} }

12
index.php

@ -17,7 +17,7 @@
private function checkpara() { private function checkpara() {
$argv = trim(trim($_GET['argv']),'/'); $argv = trim(trim($_GET['argv']),'/');
if(empty($argv)) { if (empty($argv)) {
$this->control_name = 'index'; $this->control_name = 'index';
$this->control_func = 'home'; $this->control_func = 'home';
} else { } else {
@ -27,7 +27,7 @@
} }
// 还原GET // 还原GET
if(!empty($array)) { if (!empty($array)) {
unset($_GET['argv']); unset($_GET['argv']);
unset($array[0]); unset($array[0]);
unset($array[1]); unset($array[1]);
@ -40,7 +40,7 @@
// 如果URI带有常规传参形式,并入$_GET // 如果URI带有常规传参形式,并入$_GET
$pos = strpos($_SERVER['REQUEST_URI'], '?'); $pos = strpos($_SERVER['REQUEST_URI'], '?');
if($pos!==false) { if ($pos!==false) {
$new_uri = substr($_SERVER['REQUEST_URI'], $pos+1); $new_uri = substr($_SERVER['REQUEST_URI'], $pos+1);
$new_uri_arr = explode("&", $new_uri); $new_uri_arr = explode("&", $new_uri);
foreach($new_uri_arr as $v) { foreach($new_uri_arr as $v) {
@ -55,7 +55,7 @@
// 判断控制层文件是否存在 // 判断控制层文件是否存在
$control_path = dirname(__FILE__).'/control/'.$this->control_name.'.php'; $control_path = dirname(__FILE__).'/control/'.$this->control_name.'.php';
if(!file_exists($control_path)) { if (!file_exists($control_path)) {
die('/'.$this->control_name.'.php not exist.'); die('/'.$this->control_name.'.php not exist.');
} }
include_once ($control_path); include_once ($control_path);
@ -76,7 +76,7 @@
die('method '.$this->control_func.' not exist.'); die('method '.$this->control_func.' not exist.');
} }
if($obj->getViewFormat()=='json' && $res===false) { if ($obj->getViewFormat()=='json' && $res===false) {
echo urldecode($obj->getError()); echo urldecode($obj->getError());
exit; exit;
} }
@ -87,7 +87,7 @@
} }
private function display() { private function display() {
if($this->viewFormat=='json') { if ($this->viewFormat=='json') {
$display = new DisplayJson(); $display = new DisplayJson();
} elseif($this->viewFormat=='string') { } elseif($this->viewFormat=='string') {
$display = new DisplayNone(); $display = new DisplayNone();

173
model/mCase.php

@ -20,15 +20,33 @@ class mCase extends mBase {
$this->collect_log_tbl = 'tcm_collect_log'; $this->collect_log_tbl = 'tcm_collect_log';
} }
public function createCase($name, $source, $original, $method, $herbs){ public function createCase($name, $source, $original, $method, $herbs) {
if(empty($name)){$this->setError('药方名称不能为空');return false;} if (empty($name)) {
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;} if (empty($source)) {
$this->setError('药方来源不能为空');
return false;
}
if (empty($original)) {
$this->setError('药方原方不能为空');
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)); $id = $this->obj->insert($this->tbl, array('name'=>$name, 'source'=>$source, 'original'=>$original, 'method'=>$method));
if(!$id){$this->setError('添加失败');return false;} if (!$id) {
$this->setError('添加失败');
return false;
}
//格式化药方对应的药材数据 //格式化药方对应的药材数据
$case_herb = $this->formatCaseHerb($id, $herbs); $case_herb = $this->formatCaseHerb($id, $herbs);
@ -38,17 +56,31 @@ class mCase extends mBase {
return $id; return $id;
} }
public function updateCase($id, $name, $source, $original, $method, $herbs){ public function updateCase($id, $name, $source, $original, $method, $herbs) {
if(empty($herbs)){$this->setError('药方药材不能为空');return false;} if (empty($herbs)) {
$this->setError('药方药材不能为空');
return false;
}
$data = array(); $data = array();
if(!empty($name)){$data['name']=$name;} if (!empty($name)) {
if(!empty($source)){$data['source']=$source;} $data['name']=$name;
if(!empty($original)){$data['original']=$original;} }
if(!empty($method)){$data['method']=$method;} 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){$this->setError('更新失败');return false;} if (!$res) {
$this->setError('更新失败');
return false;
}
//格式化药方对应的药材数据 //格式化药方对应的药材数据
$case_herb = $this->formatCaseHerb($id, $herbs); $case_herb = $this->formatCaseHerb($id, $herbs);
@ -58,107 +90,134 @@ class mCase extends mBase {
return true; return true;
} }
public function formatCaseHerb($case_id,$herbs){ public function formatCaseHerb($case_id,$herbs) {
$case_herb = array(); $case_herb = array();
foreach ($herbs as $key=>$item) { foreach ($herbs as $key => $item) {
$temp = array(); $temp = array();
$temp['case_id']=$case_id; $temp['case_id'] = $case_id;
$temp['num']=$item['num']; $temp['num'] = $item['num'];
$temp['sort']=$key; $temp['sort'] = $key;
$herb = $this->getHerbByName($item['name']); $herb = $this->getHerbByName($item['name']);
if($herb){ if ($herb) {
$temp['herb_id'] = $herb['id']; $temp['herb_id'] = $herb['id'];
}else{ }else{
$temp['herb_id'] = $this->createHerb(array('name'=>$item['name'])); $temp['herb_id'] = $this->createHerb(array('name' => $item['name']));
} }
$case_herb[] = $temp; $case_herb[] = $temp;
} }
return $case_herb; return $case_herb;
} }
public function getHerbByName($name){ public function getHerbByName($name) {
return $this->obj->select($this->herb_tbl, array('sql'=>'`name`=?', 'vals'=>array($name))); return $this->obj->select($this->herb_tbl, array('sql' => '`name`=?', 'vals' => array($name)));
} }
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)){$this->setError('添加药材失败');return false;} if (empty($herb_id)) {
$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){$this->setError('添加药方药材失败');return false;} if (!$res) {
$this->setError('添加药方药材失败');
return false;
}
return true; return true;
} }
public function compareCaseHerb($id,$new_data){ public function compareCaseHerb($id,$new_data) {
$old_data = $this->getCaseHerbByCaseId($id); $old_data = $this->getCaseHerbByCaseId($id);
$old_num = count($old_data); $old_num = count($old_data);
$new_num = count($new_data); $new_num = count($new_data);
if($old_num>=$new_num){ if ($old_num>=$new_num) {
//需要删除药方对应的药材 //需要删除药方对应的药材
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){$this->setError('删除药方药材失败');return false;} if (!$res) {
$this->setError('删除药方药材失败');
return false;
}
}
$res = $this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql' => '`id`=?', 'vals' => array($value['id'])));
if (!$res) {
$this->setError('更新药方药材失败');
return false;
} }
$res = $this->obj->update($this->case_herb_tbl, $new_data[$key], array('sql'=>'`id`=?', 'vals'=>array($value['id'])));
if(!$res){$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){$this->setError('添加药方药材失败');return false;} 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;
} }
$res = $this->obj->update($this->case_herb_tbl, $value, array('sql'=>'`id`=?', 'vals'=>array($old_data[$key]['id'])));
if(!$res){$this->setError('更新药方药材失败');return false;}
} }
} }
return true; return true;
} }
public function getCaseHerbByCaseId($case_id){ public function getCaseHerbByCaseId($case_id) {
return $this->obj->selectAll($this->case_herb_tbl, array('sql'=>'`case_id`=?','vals'=>array($case_id)), 'sort asc '); return $this->obj->selectAll($this->case_herb_tbl, array('sql' => '`case_id`=?','vals' => array($case_id)), 'sort asc ');
} }
public function getCaseByName($name, $page_num, $page_size) { public function getCaseByName($name, $page_num, $page_size) {
$sql = " `name` like '%{$name}%'"; $sql = " `name` like '%{$name}%'";
$offset = ($page_num - 1) * $page_size; $offset = ($page_num - 1) * $page_size;
$res = $this->obj->selectAll($this->tbl, array('sql'=>$sql, 'vals'=>array()), 'use_num desc,sort asc ', array($offset, $page_size)); $res = $this->obj->selectAll($this->tbl, array('sql' => $sql, 'vals'=>array()), 'use_num desc,sort asc ', array($offset, $page_size));
if(empty($res)) return array(); if (empty($res)) return array();
return $res; return $res;
} }
public function getCaseByNameTotal($name) { public function getCaseByNameTotal($name) {
$sql = " `name` like '%{$name}%'"; $sql = " `name` like '%{$name}%'";
return $this->obj->count($this->tbl, array('sql'=>$sql, 'vals'=>array())); 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);
if(empty($case)){$this->setError('查询不到此药方');return false;} if (empty($case)) {
$this->setError('查询不到此药方');
return false;
}
//药方药材信息 //药方药材信息
$case_herb = $this->getCaseHerbByCaseId($case['id']); $case_herb = $this->getCaseHerbByCaseId($case['id']);
if(empty($case_herb)){$this->setError('药方药材查询失败');return false;} if (empty($case_herb)) {
$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)){$this->setError('药材名称查询失败');return false;} if (empty($herb)) {
$this->setError('药材名称查询失败');
return false;
}
return array( return array(
'case' => $case, 'case' => $case,
@ -167,21 +226,21 @@ class mCase extends mBase {
); );
} }
public function getCaseById($id){ public function getCaseById($id) {
return $this->obj->select($this->tbl, array('sql'=>'`id`=?','vals'=>array($id))); return $this->obj->select($this->tbl, array('sql' => '`id`=?','vals' => array($id)));
} }
public function getHerbByIds($ids){ public function getHerbByIds($ids) {
return $this->obj->selectIn($this->herb_tbl, array('id'=>$ids)); return $this->obj->selectIn($this->herb_tbl, array('id' => $ids));
} }
public function getCaseByIds($ids){ public function getCaseByIds($ids) {
return $this->obj->selectIn($this->tbl, array('id'=>$ids)); return $this->obj->selectIn($this->tbl, array('id' => $ids));
} }
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) {
$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'));
@ -198,7 +257,7 @@ class mCase extends mBase {
} }
public function getCollectLogTotal() { public function getCollectLogTotal() {
return $this->obj->count($this->collect_log_tbl, array()); return $this->obj->count($this->collect_log_tbl);
} }
} }

12
model/mUser.php

@ -22,7 +22,7 @@ class mUser extends mBase {
$jsonres = $this->getCUrl($get_openid_url); $jsonres = $this->getCUrl($get_openid_url);
$get_openid_res = json_decode($jsonres, true); $get_openid_res = json_decode($jsonres, true);
if(empty($get_openid_res['openid'])){ if (empty($get_openid_res['openid'])) {
$this->setError('获取openid失败'); $this->setError('获取openid失败');
$tool_obj = new qTool(); $tool_obj = new qTool();
$tool_obj->trackLog('tcm', $get_openid_url . "|" .$jsonres, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_get_openid')); $tool_obj->trackLog('tcm', $get_openid_url . "|" .$jsonres, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_get_openid'));
@ -33,7 +33,7 @@ class mUser extends mBase {
} }
public function getUserByOpenid($openid) { public function getUserByOpenid($openid) {
return $this->obj->select($this->tbl, array('sql'=>'`openid`=?','vals'=>array($openid))); return $this->obj->select($this->tbl, array('sql' => '`openid`=?','vals' => array($openid)));
} }
function createUniqueUid($openid) { function createUniqueUid($openid) {
@ -44,14 +44,14 @@ class mUser extends mBase {
} }
public function getUserByUid($uid) { public function getUserByUid($uid) {
return $this->obj->select($this->tbl, array('sql'=>'`uid`=?','vals'=>array($uid))); return $this->obj->select($this->tbl, array('sql' => '`uid`=?','vals' => array($uid)));
} }
public function createUser($info){ public function createUser($info) {
return $this->obj->insert($this->tbl, $info); return $this->obj->insert($this->tbl, $info);
} }
public function getToken($uid){ public function getToken($uid) {
$secretKey = JWT_KEY; $secretKey = JWT_KEY;
$timestamp = time(); $timestamp = time();
$data = $uid . '|' . $timestamp; $data = $uid . '|' . $timestamp;
@ -59,7 +59,7 @@ class mUser extends mBase {
return base64_encode($data . '|' . $token); return base64_encode($data . '|' . $token);
} }
public function validateToken($uid, $token){ public function validateToken($uid, $token) {
$secretKey = JWT_KEY; $secretKey = JWT_KEY;
$decodedToken = base64_decode($token); $decodedToken = base64_decode($token);
list($valid_uid, $timestamp, $tokenHash) = explode('|', $decodedToken); list($valid_uid, $timestamp, $tokenHash) = explode('|', $decodedToken);

186
model/mUserCase.php

@ -15,48 +15,63 @@ class mUserCase extends mBase {
$this->user_herb_tbl = 'tcm_user_herb'; $this->user_herb_tbl = 'tcm_user_herb';
} }
public function updateUserCase($uid, $id, $data){ public function updateUserCase($uid, $id, $data) {
if(empty($data['name'])){$this->setError('药方名称不能为空');return false;} if (empty($data['name'])) {
if(empty($data['feedback'])){$this->setError('用药反馈不能为空');return false;} $this->setError('药方名称不能为空');
return false;
}
if (empty($data['feedback'])) {
$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;
}
return true; return true;
} }
public function formatUserCaseHerbs($uid, $prescribe_herb){ public function formatUserCaseHerbs($uid, $prescribe_herb) {
$mCase = new mCase(); $mCase = new mCase();
$prescribe_herb = json_decode($prescribe_herb,true); $prescribe_herb = json_decode($prescribe_herb,true);
if(empty($prescribe_herb)){$this->setError('开药详情为空');return false;} if (empty($prescribe_herb)) {
$this->setError('开药详情为空');
return false;
}
$data = array(); $data = array();
foreach ($prescribe_herb as $item){ foreach ($prescribe_herb as $item) {
$temp = array(); $temp = array();
$temp['num'] = $item['num']; $temp['num'] = $item['num'];
if(isset($item['herb_id'])){ if (isset($item['herb_id'])) {
$temp['herb_id'] = $item['herb_id']; $temp['herb_id'] = $item['herb_id'];
$data[] = $temp; $data[] = $temp;
continue; continue;
} }
$herb = $mCase->getHerbByName($item['name']); $herb = $mCase->getHerbByName($item['name']);
if($herb){ if ($herb) {
$temp['herb_id'] = $herb['id']; $temp['herb_id'] = $herb['id'];
$data[] = $temp; $data[] = $temp;
continue; continue;
} }
$userherb = $this->obj->select($this->user_herb_tbl, array('sql'=>'`name`=?', 'vals'=>array($item['name']))); $userherb = $this->obj->select($this->user_herb_tbl, array('sql'=>'`name`=?', 'vals'=>array($item['name'])));
if($userherb){ if ($userherb) {
$temp['herb_id'] = 'u_'.$userherb['id']; $temp['herb_id'] = 'u_'.$userherb['id'];
$data[] = $temp; $data[] = $temp;
continue; continue;
} }
$user_herb_id = $this->obj->insert($this->user_herb_tbl, array('uid' => $uid,'name'=> $item['name'])); $user_herb_id = $this->obj->insert($this->user_herb_tbl, array('uid' => $uid,'name'=> $item['name']));
if(!$user_herb_id){$this->setError('添加自定义药材失败');return false;} if (!$user_herb_id) {
$this->setError('添加自定义药材失败');
return false;
}
$temp['herb_id'] = 'u_'.$user_herb_id; $temp['herb_id'] = 'u_'.$user_herb_id;
$data[] = $temp; $data[] = $temp;
@ -65,31 +80,67 @@ class mUserCase extends mBase {
return json_encode($data); return json_encode($data);
} }
public function createUserCase($uid, $case_id, $data){ public function createUserCase($uid, $case_id, $data) {
if($case_id<=0){$this->setError('找不到相关药方');return false;} if ($case_id <= 0) {
if(empty($data['patient_name'])){$this->setError('患者姓名不能为空');return false;} $this->setError('找不到相关药方');
if($data['patient_age']<=0){$this->setError('患者年龄不正确');return false;} return false;
if($data['sex']<0){$this->setError('患者性别不能为空');return false;} }
if($data['prescribe_num']<=0){$this->setError('开药数量不正确');return false;} if (empty($data['patient_name'])) {
if(empty($data['prescribe_herb'])){$this->setError('开药详情不能为空');return false;} $this->setError('患者姓名不能为空');
if(empty($data['patient_say'])){$this->setError('主诉不能为空');return false;} return false;
if(empty($data['first_diagnosis'])){$this->setError('舌诊脉诊不能为空');return false;} }
if(empty($data['diagnosis'])){$this->setError('诊断不能为空');return false;} if ($data['patient_age'] <= 0) {
$this->setError('患者年龄不正确');
return false;
}
if ($data['sex']<0) {
$this->setError('患者性别不能为空');
return false;
}
if ($data['prescribe_num'] <= 0) {
$this->setError('开药数量不正确');
return false;
}
if (empty($data['prescribe_herb'])) {
$this->setError('开药详情不能为空');
return false;
}
if (empty($data['patient_say'])) {
$this->setError('主诉不能为空');
return false;
}
if (empty($data['first_diagnosis'])) {
$this->setError('舌诊脉诊不能为空');
return false;
}
if (empty($data['diagnosis'])) {
$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;
}
//格式化医案开药详情 //格式化医案开药详情
$prescribe_herb = $this->formatUserCaseHerbs($uid, $data['prescribe_herb']); $prescribe_herb = $this->formatUserCaseHerbs($uid, $data['prescribe_herb']);
if(!$prescribe_herb){$this->setError('医案开药详情不正确');return false;} if (!$prescribe_herb) {
$this->setError('医案开药详情不正确');
return false;
}
$data['prescribe_herb'] = $prescribe_herb; $data['prescribe_herb'] = $prescribe_herb;
$data['case_id'] = $case['id']; $data['case_id'] = $case['id'];
$data['uid'] = $uid; $data['uid'] = $uid;
$id = $this->obj->insert($this->tbl, $data); $id = $this->obj->insert($this->tbl, $data);
if(!$id){$this->setError('医案保存失败');return false;} if (!$id) {
$this->setError('医案保存失败');
return false;
}
//更新药方使用次数 这个后期会增加定时脚本去修正 //更新药方使用次数 这个后期会增加定时脚本去修正
$m_case->updateCaseSearchNum($case_id); $m_case->updateCaseSearchNum($case_id);
@ -97,31 +148,43 @@ class mUserCase extends mBase {
return $id; return $id;
} }
public function getUserCaseInfo($uid, $id, $is_format_data = false){ public function getUserCaseInfo($uid, $id, $is_format_data = 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;
}
$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)){$this->setError('找不到相关药方');return false;} if (empty($case)) {
$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) {
if(strpos($item['herb_id'],'u_')!==false){ if (strpos($item['herb_id'],'u_') !== false) {
$user_herb_ids[] = str_replace('u_','',$item['herb_id']); $user_herb_ids[] = str_replace('u_','',$item['herb_id']);
continue; continue;
} }
$herb_ids[] =$item['herb_id']; $herb_ids[] = $item['herb_id'];
}
if (empty($herb_ids) && empty($user_herb_ids)) {
$this->setError('医案开药详情不正确');
return false;
} }
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)){$this->setError('找不到相关药材');return false;} if (empty($herb) && empty($user_herb)) {
$this->setError('找不到相关药材');
return false;
}
$data = array( $data = array(
'data' => $user_case, 'data' => $user_case,
@ -130,44 +193,56 @@ class mUserCase extends mBase {
'user_herb_data' => 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, $page_num, $page_size, $get_case_herb = false, $is_format_data = false){ public function getUserCaseList($uid, $page_num, $page_size, $get_case_herb = false, $is_format_data = 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;
}
$case_ids = array_column($user_case,'case_id'); $case_ids = array_column($user_case,'case_id');
$m_case = new mCase(); $m_case = new mCase();
$case = $m_case->getCaseByIds($case_ids); $case = $m_case->getCaseByIds($case_ids);
if(empty($case)){$this->setError('找不到相关药方');return false;} if (empty($case)) {
$this->setError('找不到相关药方');
return false;
}
$case = array_column($case,null,'id'); $case = array_column($case,null,'id');
if(!$get_case_herb)return array('list' => $user_case, 'case_data' => $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();
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);
$item['prescribe_herb'] = $prescribe_herb; $item['prescribe_herb'] = $prescribe_herb;
foreach ($prescribe_herb as $herb_item){ foreach ($prescribe_herb as $herb_item) {
if(strpos($herb_item['herb_id'],'u_')!==false){ if (strpos($herb_item['herb_id'],'u_') !== false) {
$user_herb_ids[] = str_replace('u_','',$herb_item['herb_id']); $user_herb_ids[] = str_replace('u_','',$herb_item['herb_id']);
continue; continue;
} }
$herb_ids[] = $herb_item['herb_id']; $herb_ids[] = $herb_item['herb_id'];
} }
} }
if(empty($herb_ids) && empty($user_herb_ids)){$this->setError('医案开药详情不正确');return false;} if (empty($herb_ids) && empty($user_herb_ids)) {
$this->setError('医案开药详情不正确');
return false;
}
$herb = $m_case->getHerbByIds($herb_ids); $herb = $m_case->getHerbByIds($herb_ids);
$user_herb = $this->getUserHerbByIds($user_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( $data = array(
'list' => $user_case, 'list' => $user_case,
@ -176,36 +251,36 @@ class mUserCase extends mBase {
'user_herb_data' => 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){ public function getUserCaseListCount($uid) {
return $this->obj->count($this->tbl, array('sql'=>'`uid`=?', 'vals'=>array($uid))); 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['data'])){ if (isset($data['data'])) {
$data['list'][0] = $data['data']; $data['list'][0] = $data['data'];
unset($data['data']); unset($data['data']);
$data['case_data'] =array_column(array($data['case_data']),null,'id'); $data['case_data'] =array_column(array($data['case_data']),null,'id');
} }
foreach ($data['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_data'][$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_data'][$herb['herb_id']]['name']; $herb_name = $data['user_herb_data'][$herb['herb_id']]['name'];
}else{ }else{
@ -221,8 +296,7 @@ class mUserCase extends mBase {
return $data; return $data;
} }
public function createPdf($uid, $data_key) public function createPdf($uid, $data_key) {
{
$mpdf = new mPDF(); $mpdf = new mPDF();
$htmlContent = file_get_contents(sprintf(RQ_USER_CASE_HTML_URL, $data_key)); $htmlContent = file_get_contents(sprintf(RQ_USER_CASE_HTML_URL, $data_key));
@ -231,7 +305,7 @@ class mUserCase extends mBase {
$pdf_name = md5($data_key); $pdf_name = md5($data_key);
$temp_dir = sprintf(USER_CASE_PDF_PATH, $uid); $temp_dir = sprintf(USER_CASE_PDF_PATH, $uid);
if(!is_dir($temp_dir)) { if (!is_dir($temp_dir)) {
mkdir($temp_dir, 0755, true); mkdir($temp_dir, 0755, true);
chown($temp_dir, 'nobody'); chown($temp_dir, 'nobody');
chgrp($temp_dir, 'nobody'); chgrp($temp_dir, 'nobody');

Loading…
Cancel
Save