diff --git a/control/index.php b/control/index.php index e3de114..96b865e 100644 --- a/control/index.php +++ b/control/index.php @@ -1,9 +1,10 @@ post('id')+0; + $id = $this->post('id') + 0; $name = trim($this->post('name')); $source = trim($this->post('source')); $original = trim($this->post('original')); @@ -47,7 +48,7 @@ class index extends publicBase { public function ajax_search() { $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_size = $this->post('page_size') ? $this->post('page_size') : 100; @@ -56,11 +57,11 @@ class index extends publicBase { $data = $m_case->getCaseByName($content, $page_num, $page_size); $total = $m_case->getCaseByNameTotal($content); - $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), 'list' => $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() { - $id = $this->get('id')+0; + $id = $this->get('id') + 0; if (empty($id)) $this->ajax_json(false, '非法请求'); $m_case = new mCase(); @@ -73,11 +74,11 @@ class index extends publicBase { public function ajax_save_user_case() { $uid = $this->post('uid'); $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, '非法请求'); $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, '请登录后操作'); $data = array( @@ -96,17 +97,17 @@ class index extends publicBase { $id = $m_user_case->createUserCase($uid, $case_id, $data); if (!$id) $this->ajax_json(false, $m_user_case->getError()); - $this->ajax_json(true, '保存成功',array('id' => $id)); + $this->ajax_json(true, '保存成功', array('id' => $id)); } public function ajax_update_user_case() { $uid = $this->post('uid'); $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, '非法请求'); $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, '请登录后操作'); $data = array( @@ -118,7 +119,7 @@ class index extends publicBase { $res = $m_user_case->updateUserCase($uid, $id, $data); if (!$res) $this->ajax_json(false, $m_user_case->getError()); - $this->ajax_json(true, '保存成功',array('id' => $id)); + $this->ajax_json(true, '保存成功', array('id' => $id)); } public function ajax_user_case_list() { @@ -127,7 +128,7 @@ class index extends publicBase { if (empty($uid) || empty($token)) $this->ajax_json(false, '非法请求'); $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, '请登录后操作'); $page_num = $this->post('page_num') ? $this->post('page_num') : 1; @@ -138,11 +139,7 @@ class index extends publicBase { if (!$data) $this->ajax_json(false, $m_user_case->getError()); $total = $m_user_case->getUserCaseListCount($uid); - $return = array( - 'total' => $total, - 'current_page' => $page_num, - 'total_page' => ceil($total/$page_size) - ); + $return = array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total / $page_size)); $return = array_merge($return, $data); $this->ajax_json(true, '获取成功', $return); @@ -151,11 +148,11 @@ class index extends publicBase { public function ajax_user_case_detail() { $uid = $this->post('uid'); $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, '非法请求'); $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, '请登录后操作'); $m_user_case = new mUserCase(); @@ -173,31 +170,31 @@ class index extends publicBase { $data = $m_case->getCollectLog($page_num, $page_size); $total = $m_case->getCollectLogTotal(); - $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), 'list' => $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() { $code = $this->get('code'); - if (!$code)$this->ajax_json(false, '非法请求'); + if (!$code) $this->ajax_json(false, '非法请求'); $m_user = new mUser(); $uid = $m_user->getUid($code); $token = $m_user->getToken($uid); - $this->ajax_json(true, '登录成功', array('uid' => $uid, 'token'=> $token)); + $this->ajax_json(true, '登录成功', array('uid' => $uid, 'token' => $token)); } - public function ajax_contact_us(){ - $this->ajax_json(true, '获取成功',array('img_url'=> CONTACT_US_IMG_URL)); + public function ajax_contact_us() { + $this->ajax_json(true, '获取成功', array('img_url' => CONTACT_US_IMG_URL)); } - public function export_user_case_list(){ + public function export_user_case_list() { $uid = $this->post('uid'); $token = $this->post('token'); if (empty($uid) || empty($token)) $this->ajax_json(false, '非法请求'); $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, '请登录后操作'); $page_num = $this->post('page_num') ? $this->post('page_num') : 1; @@ -214,17 +211,17 @@ class index extends publicBase { $robj->setex($data_key, 60, json_encode($data)); $pdf_url = $m_user_case->createPdf($uid, $data_key); - $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total/$page_size), '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() { $uid = $this->post('uid'); $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, '非法请求'); $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, '请登录后操作'); $m_user_case = new mUserCase(); @@ -237,26 +234,26 @@ class index extends publicBase { $robj->setex($data_key, 60, json_encode($data)); $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)); } - public function export_pdf(){ + public function export_pdf() { $key = $this->get('key'); $m_user_case = new mUserCase(); $robj = $m_user_case->initRedis(); $data = $robj->get($key); - $this->view['data'] = json_decode($data,true); + $this->view['data'] = json_decode($data, true); } - public function ajax_mail(){ + public function ajax_mail() { $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); + $is_login = $mUser->validateToken($uid, $token); if (!$is_login) $this->ajax_json(false, '请登录后操作'); $email = $this->post('email'); @@ -271,7 +268,7 @@ class index extends publicBase { if ($directory_name != $uid) $this->ajax_json(false, '非法请求'); $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, '发送失败'); $this->ajax_json(true, '发送成功'); diff --git a/model/mCase.php b/model/mCase.php index 5fbd79a..c7db222 100644 --- a/model/mCase.php +++ b/model/mCase.php @@ -2,7 +2,7 @@ /** * */ -include_once(SERVER_ROOT."/model/mBase.php"); +include_once(SERVER_ROOT . "/model/mBase.php"); class mCase extends mBase { @@ -42,7 +42,7 @@ class mCase extends mBase { 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; @@ -63,10 +63,10 @@ class mCase extends mBase { } $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; + 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))); if (!$res) { @@ -82,7 +82,7 @@ class mCase extends mBase { return true; } - public function formatCaseHerb($case_id,$herbs) { + public function formatCaseHerb($case_id, $herbs) { $case_herb = array(); foreach ($herbs as $key => $item) { $temp = array(); @@ -125,13 +125,13 @@ class mCase extends mBase { return true; } - public function compareCaseHerb($id,$new_data) { + public function compareCaseHerb($id, $new_data) { $old_data = $this->getCaseHerbByCaseId($id); $old_num = count($old_data); $new_num = count($new_data); - if ($old_num>=$new_num) { + if ($old_num >= $new_num) { //需要删除药方对应的药材 foreach ($old_data as $key => $value) { if (!isset($new_data[$key])) { @@ -169,14 +169,14 @@ class mCase extends mBase { } 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) { $sql = " `name` like '%{$name}%'"; $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(); return $res; @@ -185,7 +185,7 @@ class mCase extends mBase { public function getCaseByNameTotal($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) { @@ -204,7 +204,7 @@ class mCase extends mBase { } //药材名称 - $herb_ids = array_column($case_herb,'herb_id'); + $herb_ids = array_column($case_herb, 'herb_id'); $herb = $this->getHerbByIds($herb_ids); if (empty($herb)) { $this->setError('药材名称查询失败'); @@ -219,7 +219,7 @@ class mCase extends mBase { } 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) { @@ -231,7 +231,7 @@ class mCase extends mBase { } 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) { $tool_obj = new qTool(); $tool_obj->trackLog('tcm', $id, sprintf(LOG_TRACK_SAVE_PATH, date('Y-m-d'), 'tcm_case_use_num')); diff --git a/model/mUser.php b/model/mUser.php index 0dcc1fd..a389512 100644 --- a/model/mUser.php +++ b/model/mUser.php @@ -2,7 +2,7 @@ /** * */ -include_once(SERVER_ROOT."/model/mBase.php"); +include_once(SERVER_ROOT . "/model/mBase.php"); class mUser extends mBase { @@ -52,7 +52,7 @@ class mUser extends mBase { if (empty($get_openid_res['openid'])) { $this->setError('获取openid失败'); $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')); return false; } @@ -60,7 +60,7 @@ class mUser extends mBase { } 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) { @@ -71,7 +71,7 @@ class mUser extends mBase { } 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) { diff --git a/model/mUserCase.php b/model/mUserCase.php index 7873e9f..451caff 100644 --- a/model/mUserCase.php +++ b/model/mUserCase.php @@ -2,13 +2,14 @@ /** * */ -include_once(SERVER_ROOT."/model/mBase.php"); -include_once(SERVER_ROOT."/vendor/mpdf/mpdf/mpdf.php"); +include_once(SERVER_ROOT . "/model/mBase.php"); +include_once(SERVER_ROOT . "/vendor/mpdf/mpdf/mpdf.php"); class mUserCase extends mBase { private $obj; private $tbl; private $user_herb_tbl; + public function __construct() { $this->obj = new dUserCase(); $this->tbl = 'tcm_user_case'; @@ -25,7 +26,7 @@ class mUserCase extends mBase { 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; @@ -37,7 +38,7 @@ class mUserCase extends mBase { public function formatUserCaseHerbs($uid, $prescribe_herb) { $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; @@ -60,20 +61,20 @@ class mUserCase extends mBase { 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) { - $temp['herb_id'] = 'u_'.$userherb['id']; + $temp['herb_id'] = 'u_' . $userherb['id']; $data[] = $temp; 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; } - $temp['herb_id'] = 'u_'.$user_herb_id; + $temp['herb_id'] = 'u_' . $user_herb_id; $data[] = $temp; } @@ -93,7 +94,7 @@ class mUserCase extends mBase { $this->setError('患者年龄不正确'); return false; } - if ($data['sex']<0) { + if ($data['sex'] < 0) { $this->setError('患者性别不能为空'); return false; } @@ -149,13 +150,13 @@ class mUserCase extends mBase { } 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; } - $prescribe_herb = json_decode($user_case['prescribe_herb'],true); + $prescribe_herb = json_decode($user_case['prescribe_herb'], true); $user_case['prescribe_herb'] = $prescribe_herb; $mCase = new mCase(); @@ -167,8 +168,8 @@ class mUserCase extends mBase { $herb_ids = $user_herb_ids = array(); foreach ($prescribe_herb as $item) { - if (strpos($item['herb_id'],'u_') !== false) { - $user_herb_ids[] = str_replace('u_','',$item['herb_id']); + if (strpos($item['herb_id'], 'u_') !== false) { + $user_herb_ids[] = str_replace('u_', '', $item['herb_id']); continue; } $herb_ids[] = $item['herb_id']; @@ -193,19 +194,19 @@ class mUserCase extends mBase { '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; } public function getUserCaseList($uid, $page_num, $page_size, $get_case_herb = false, $is_format_data = 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)); + $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'); $m_case = new mCase(); $case = $m_case->getCaseByIds($case_ids); @@ -214,19 +215,19 @@ class mUserCase extends mBase { 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(); 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; foreach ($prescribe_herb as $herb_item) { - if (strpos($herb_item['herb_id'],'u_') !== false) { - $user_herb_ids[] = str_replace('u_','',$herb_item['herb_id']); + if (strpos($herb_item['herb_id'], 'u_') !== false) { + $user_herb_ids[] = str_replace('u_', '', $herb_item['herb_id']); continue; } $herb_ids[] = $herb_item['herb_id']; @@ -251,7 +252,7 @@ class mUserCase extends mBase { '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; } @@ -268,27 +269,27 @@ class mUserCase extends mBase { if (isset($data['data'])) { $data['list'][0] = $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) { $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']]; - $item['case_info'] = "选 ".$case['source']." ".$case['name'].":"; + $item['case_info'] = "选 " . $case['source'] . " " . $case['name'] . ":"; $herb_arr = array(); foreach ($item['prescribe_herb'] as $herb) { - if (strpos($herb['herb_id'],'u_') !== false) { - $herb['herb_id'] = str_replace('u_','',$herb['herb_id']); + if (strpos($herb['herb_id'], 'u_') !== false) { + $herb['herb_id'] = str_replace('u_', '', $herb['herb_id']); $herb_name = $data['user_herb_data'][$herb['herb_id']]['name']; - }else{ + } else { $herb_name = $data['herb_data'][$herb['herb_id']]['name']; } - $herb_arr[] = $herb_name.$herb['num']."克"; + $herb_arr[] = $herb_name . $herb['num'] . "克"; } - $herb_str = implode('、',$herb_arr); + $herb_str = implode('、', $herb_arr); $item['case_herb_info'] = $herb_str; } @@ -311,7 +312,7 @@ class mUserCase extends mBase { chgrp($temp_dir, 'nobody'); } - $mpdf->Output($temp_dir . $pdf_name . ".pdf" , 'F'); // D表示下载,I表示在浏览器中查看 + $mpdf->Output($temp_dir . $pdf_name . ".pdf", 'F'); // D表示下载,I表示在浏览器中查看 return sprintf(USER_CASE_PDF_URL, $uid, $pdf_name); }