|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once(dirname(dirname(__FILE__)) . "/library/publicBase.php");
|
|
|
|
|
|
|
|
class index extends publicBase {
|
|
|
|
|
|
|
|
private function _check_login() {
|
|
|
|
$uid = $this->post('uid');
|
|
|
|
$token = $this->post('token');
|
|
|
|
if (empty($uid) || empty($token)) $this->ajax_json(false, '参数错误', array('code' => CODE_LOGIN_EXIPRE));
|
|
|
|
|
|
|
|
$m_user = new mUser();
|
|
|
|
$is_login = $m_user->validateToken($uid, $token);
|
|
|
|
if (!$is_login) $this->ajax_json(false, '未登录或登录已经失效', array('code' => CODE_LOGIN_EXIPRE));
|
|
|
|
|
|
|
|
$obj = new mUser();
|
|
|
|
$uinfo = $obj->getUserByUid($uid);
|
|
|
|
if (empty($uinfo)) $this->ajax_json(false, '用户不存在', array('code' => CODE_LOGIN_USER_NOT_EXIST));
|
|
|
|
|
|
|
|
return $uinfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function home() {
|
|
|
|
$id = $this->get('id');
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$data = $mformula->getFormulaInfo($id);
|
|
|
|
|
|
|
|
$this->view['data'] = $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_save_formula() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$name = trim($this->post('name'));
|
|
|
|
$source = trim($this->post('source'));
|
|
|
|
$method = trim($this->post('method'));
|
|
|
|
$herbs = $this->post('herbs');
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
|
|
|
|
//生成唯一id 防止重复请求
|
|
|
|
$request_id = md5($uinfo['uid'] . $name . $source . $herbs);
|
|
|
|
$request_times = $mformula->requestLimit(sprintf(_QR_REQUEST_LIMIT, $request_id), 1, 60);
|
|
|
|
if (!$request_times) $this->ajax_json(false, $mformula->getError());
|
|
|
|
|
|
|
|
//新增药方
|
|
|
|
$id = $mformula->createFormula($uinfo['uid'], $name, $source, $method, $herbs);
|
|
|
|
if (!$id) $this->ajax_json(false, $mformula->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '添加成功', array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_update_formula() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
$name = trim($this->post('name'));
|
|
|
|
$source = trim($this->post('source'));
|
|
|
|
$method = trim($this->post('method'));
|
|
|
|
$herbs = $this->post('herbs');
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$res = $mformula->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs);
|
|
|
|
if (!$res) $this->ajax_json(false, $mformula->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '保存成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_user_formula() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$page_num = $this->post('page_num') ? $this->post('page_num') : 1;
|
|
|
|
$page_size = $this->post('page_size') ? $this->post('page_size') : 20;
|
|
|
|
|
|
|
|
//新增药方
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$list = $mformula->getUserFormulaList($uinfo['uid'], $page_num, $page_size);
|
|
|
|
$total = $mformula->getUserFormulaTotal($uinfo['uid']);
|
|
|
|
|
|
|
|
$rdata = array(
|
|
|
|
'total' => $total,
|
|
|
|
'per_page' => $page_size,
|
|
|
|
'last_page' => ceil($total / $page_size),
|
|
|
|
'current_page' => $page_num,
|
|
|
|
'list' => $list,
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_user_formula_detail() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
if (!$id) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$data = $mformula->getUserFormulaInfo($id, $uinfo['uid']);
|
|
|
|
if (!$data) $this->ajax_json(false, $mformula->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_search() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$content = trim($this->post('content'));
|
|
|
|
$content = empty($content) ? '' : $content;
|
|
|
|
|
|
|
|
$page_num = $this->post('page_num') ? $this->post('page_num') : 1;
|
|
|
|
$page_size = $this->post('page_size') ? $this->post('page_size') : 20;
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$list = $mformula->getFormulaList($uinfo['uid'], $page_num, $page_size, $content);
|
|
|
|
$total = $mformula->getFormulaTotal($uinfo['uid'], $content);
|
|
|
|
|
|
|
|
$rdata = array(
|
|
|
|
'total' => $total,
|
|
|
|
'per_page' => $page_size,
|
|
|
|
'last_page' => ceil($total / $page_size),
|
|
|
|
'current_page' => $page_num,
|
|
|
|
'list' => $list,
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_formula_detail() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
if (!$id) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$data = $mformula->getFormulaInfo($id, $uinfo['uid']);
|
|
|
|
if (!$data) $this->ajax_json(false, $mformula->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_save_user_case() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$formula_id = $this->post('formula_id') + 0;
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'patient_name' => trim($this->post('patient_name')),
|
|
|
|
'patient_age' => $this->post('patient_age') + 0,
|
|
|
|
'patient_sex' => $this->post('patient_sex') + 0,
|
|
|
|
'patient_say' => trim($this->post('patient_say')),
|
|
|
|
'first_diagnosis' => trim($this->post('first_diagnosis')),
|
|
|
|
'diagnosis' => trim($this->post('diagnosis')),
|
|
|
|
'prescribe_num' => $this->post('prescribe_num') + 0,
|
|
|
|
'prescribe_herb' => $this->post('prescribe_herb'),
|
|
|
|
);
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
|
|
|
|
//生成唯一id 防止重复请求
|
|
|
|
$request_id = md5($uinfo['uid'] . $formula_id . $data['name'] . $data['patient_name']);
|
|
|
|
$request_times = $m_user_case->requestLimit(sprintf(_QR_REQUEST_LIMIT, $request_id), 1, 60);
|
|
|
|
if (!$request_times) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$id = $m_user_case->createUserCase($uinfo['uid'], $formula_id, $data);
|
|
|
|
if (!$id) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '保存成功', array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_update_user_case() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
if (empty($id)) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'name' => trim($this->post('name')),
|
|
|
|
'feedback' => trim($this->post('feedback')),
|
|
|
|
);
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$res = $m_user_case->updateUserCase($uinfo['uid'], $id, $data);
|
|
|
|
if (!$res) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '保存成功', array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_user_case_list() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$page_num = $this->post('page_num') ? $this->post('page_num') : 1;
|
|
|
|
$page_size = $this->post('page_size') ? $this->post('page_size') : 100;
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$data = $m_user_case->getUserCaseList($uinfo['uid'], $page_num, $page_size);
|
|
|
|
$total = $m_user_case->getUserCaseListCount($uinfo['uid']);
|
|
|
|
|
|
|
|
$rdata = array(
|
|
|
|
'total' => $total,
|
|
|
|
'per_page' => $page_size,
|
|
|
|
'last_page' => ceil($total / $page_size),
|
|
|
|
'current_page' => $page_num,
|
|
|
|
'data' => $data
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_user_case_detail() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
if (empty($id)) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$data = $m_user_case->getUserCaseInfo($uinfo['uid'], $id);
|
|
|
|
if (!$data) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_collect_log() {
|
|
|
|
$page_num = $this->post('page_num') ? $this->post('page_num') : 1;
|
|
|
|
$page_size = $this->post('page_size') ? $this->post('page_size') : 100;
|
|
|
|
|
|
|
|
$mformula = new mFormula();
|
|
|
|
$data = $mformula->getCollectLog($page_num, $page_size);
|
|
|
|
$total = $mformula->getCollectLogTotal();
|
|
|
|
|
|
|
|
$rdata = array(
|
|
|
|
'total' => $total,
|
|
|
|
'per_page' => $page_size,
|
|
|
|
'last_page' => ceil($total / $page_size),
|
|
|
|
'current_page' => $page_num,
|
|
|
|
'data' => $data
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $rdata);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_login() {
|
|
|
|
$code = $this->post('code');
|
|
|
|
if (!$code) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$m_user = new mUser();
|
|
|
|
$user = $m_user->getUserInfo($code);
|
|
|
|
if (!$user) $this->ajax_json(false, $m_user->getError());
|
|
|
|
|
|
|
|
$token = $m_user->getToken($user['uid']);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '登录成功', array(
|
|
|
|
'uid' => $user['uid'],
|
|
|
|
'identifier' => $user['identifier'],
|
|
|
|
'token' => $token
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_get_user() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $uinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_contact_us() {
|
|
|
|
$this->ajax_json(true, '获取成功', array('img_url' => CONTACT_US_IMG_URL));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function export_user_case() {
|
|
|
|
$uinfo = $this->_check_login();
|
|
|
|
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
if ($id) {
|
|
|
|
$post_url = USER_CASE_HTML_URL;
|
|
|
|
$data = array(
|
|
|
|
"uid" => $uinfo['uid'],
|
|
|
|
"id" => $id,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$post_url = USER_CASE_LIST_HTML_URL;
|
|
|
|
$data = array(
|
|
|
|
"uid" => $uinfo['uid'],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$return = $m_user_case->postCUrl($post_url, $data);
|
|
|
|
|
|
|
|
$res = json_decode($return, 1);
|
|
|
|
if (isset($res['info'])) $this->ajax_json(false, '未查询到可导出的医案记录');
|
|
|
|
|
|
|
|
$pdf_name = md5($uinfo['uid'] . $id) . ".pdf";
|
|
|
|
$m_user_case->createPdf($uinfo['uid'], $pdf_name, $return);
|
|
|
|
|
|
|
|
$email = $this->post('email');
|
|
|
|
if (!empty($email)) {
|
|
|
|
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) $this->ajax_json(false, '邮箱地址无效');
|
|
|
|
$res = $m_user_case->sendMail(array($email), date('Y年m月d日', time()) . '-医案导出', '', sprintf(USER_CASE_PDF_PATH, $uinfo['uid']) . $pdf_name);
|
|
|
|
if (!$res) $this->ajax_json(true, '发送失败');
|
|
|
|
$this->ajax_json(true, '发送成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', array('pdf_url' => sprintf(USER_CASE_PDF_URL, $uinfo['uid']) . $pdf_name));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user_case_list() {
|
|
|
|
$uid = $this->post('uid') + 0;
|
|
|
|
if (empty($uid)) $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') : 500;
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$data = $m_user_case->getUserCaseListPdfInfo($uid, $page_num, $page_size);
|
|
|
|
if (!$data) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->view['data'] = $data['user_case'];
|
|
|
|
$this->setViewTpl('index/export_pdf.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function user_case() {
|
|
|
|
$id = $this->post('id') + 0;
|
|
|
|
$uid = $this->post('uid') + 0;
|
|
|
|
if (empty($uid) || empty($id)) $this->ajax_json(false, '参数错误');
|
|
|
|
|
|
|
|
$m_user_case = new mUserCase();
|
|
|
|
$data = $m_user_case->getUserCasePdfInfo($uid, $id);
|
|
|
|
if (!$data) $this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->view['data'] = $data['user_case'];
|
|
|
|
$this->setViewTpl('index/export_pdf.html');
|
|
|
|
}
|
|
|
|
}
|