|
|
|
<?php
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
include_once(dirname(dirname(__FILE__))."/library/publicBase.php");
|
|
|
|
|
|
|
|
class index extends publicBase {
|
|
|
|
public function home() {
|
|
|
|
$id = $this->get('id');
|
|
|
|
|
|
|
|
$mCase = new mCase();
|
|
|
|
$data = $mCase->getCaseInfo($id);
|
|
|
|
|
|
|
|
$this->view['data'] = $data;
|
|
|
|
|
|
|
|
$this->setViewFormat('html');
|
|
|
|
$this->setViewTpl('index/home.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_save_case() {
|
|
|
|
$name = $this->post('name');
|
|
|
|
$source = $this->post('source');
|
|
|
|
$original = $this->post('original');
|
|
|
|
$method = $this->post('method');
|
|
|
|
$herbs = $this->post('herbs');
|
|
|
|
|
|
|
|
//新增药方
|
|
|
|
$m_case = new mCase();
|
|
|
|
$id = $m_case->createCase($name, $source, $original, $method, $herbs);
|
|
|
|
if (!$id) $this->ajax_json(false, $m_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '添加成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
$herbs = $this->post('herbs');
|
|
|
|
|
|
|
|
$m_case = new mCase();
|
|
|
|
$res = $m_case->updateCase($id, $name, $source, $original, $method, $herbs);
|
|
|
|
if (!$res) $this->ajax_json(false, $m_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '保存成功');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_search() {
|
|
|
|
$content = $this->post('content');
|
|
|
|
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;
|
|
|
|
|
|
|
|
$m_case = new mCase();
|
|
|
|
$data = $m_case->getCaseByName($content, $page_num, $page_size);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_case_detail() {
|
|
|
|
$id = $this->get('id');
|
|
|
|
if(empty($id))$this->ajax_json(false, '非法请求');
|
|
|
|
|
|
|
|
$m_case = new mCase();
|
|
|
|
$data = $m_case->getCaseInfo($id);
|
|
|
|
if(!$data)$this->ajax_json(false, $m_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_save_user_case() {
|
|
|
|
$uid = $this->post('uid');
|
|
|
|
$token = $this->post('token');
|
|
|
|
$case_id = $this->post('case_id')+0;
|
|
|
|
if(empty($uid) || empty($token) || empty($case_id))$this->ajax_json(false, '非法请求');
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'name' => trim($this->post('name')),
|
|
|
|
'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 = $m_user_case->createUserCase($uid, $token, $case_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() {
|
|
|
|
$uid = $this->post('uid');
|
|
|
|
$token = $this->post('token');
|
|
|
|
$id = $this->post('id')+0;
|
|
|
|
if(empty($uid) || empty($token) || 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($uid, $token, $id, $data);
|
|
|
|
if(!$res)$this->ajax_json(false, $m_user_case->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '保存成功',array('id' => $id));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_user_case() {
|
|
|
|
$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;
|
|
|
|
|
|
|
|
$mUserCase = new mUserCase();
|
|
|
|
|
|
|
|
$id = $this->post('id');
|
|
|
|
if($id){
|
|
|
|
$data = $mUserCase->getUserCaseInfo($id, $uid);
|
|
|
|
if(!$data)$this->ajax_json(false, $mUserCase->getError());
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
$data = $mUserCase->getUserCaseList($uid, $start, $pagesize);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_collect_log() {
|
|
|
|
$start = $this->get('start') ? $this->get('start') : 0;
|
|
|
|
$pagesize = $this->get('pagesize') ? $this->get('pagesize') : 500;
|
|
|
|
|
|
|
|
$mCase = new mCase();
|
|
|
|
$data = $mCase->getCollectLog($start,$pagesize);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_login(){
|
|
|
|
$code = $this->get('code');
|
|
|
|
if(!$code)$this->ajax_json(false, '非法请求');
|
|
|
|
|
|
|
|
$mUser = new mUser();
|
|
|
|
|
|
|
|
$openid = $mUser->getOpenid($code);
|
|
|
|
if(!$openid)$this->ajax_json(false, $mUser->getError());
|
|
|
|
|
|
|
|
$user = $mUser->getUserByOpenid($openid);
|
|
|
|
if($user){
|
|
|
|
$data = array(
|
|
|
|
'uid' => $user['uid'],
|
|
|
|
'token'=> $mUser->getToken($user['uid']),
|
|
|
|
);
|
|
|
|
$this->ajax_json(true, '登录成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
//获取唯一uid串
|
|
|
|
$uid = $mUser->createUniqueUid($openid);
|
|
|
|
$user = $mUser->getUserByUid($uid);
|
|
|
|
if($user)$this->ajax_json(false, 'uid生成失败');
|
|
|
|
|
|
|
|
$id = $mUser->createUser(array('uid'=>$uid,'openid'=>$openid));
|
|
|
|
if(!$id)$this->ajax_json(false, '用户创建失败');
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'uid' => $uid,
|
|
|
|
'token'=> $mUser->getToken($uid),
|
|
|
|
);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '登录成功', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_contact_us(){
|
|
|
|
$this->ajax_json(true, '获取成功',array('img_url'=> CONTACT_US_IMG_URL));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function ajax_pdf_url(){
|
|
|
|
$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, '请登录后操作');
|
|
|
|
|
|
|
|
$mUserCase = new mUserCase();
|
|
|
|
|
|
|
|
$id = $this->post('id');
|
|
|
|
if($id){
|
|
|
|
$data = $mUserCase->getUserCaseInfo($id, $uid);
|
|
|
|
if (!$data) $this->ajax_json(false, $mUserCase->getError());
|
|
|
|
|
|
|
|
$pdf_url = $mUserCase->createUserCasePdf($uid, $data);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url));
|
|
|
|
}
|
|
|
|
|
|
|
|
//如果id不存在默认保存前500个医案
|
|
|
|
$start = $this->post('start') ? $this->post('start') : 0;
|
|
|
|
$pagesize = $this->post('pagesize') ? $this->post('pagesize') : 500;
|
|
|
|
|
|
|
|
$data = $mUserCase->getUserCaseList($uid, $start, $pagesize, true);
|
|
|
|
if (!$data) $this->ajax_json(false, $mUserCase->getError());
|
|
|
|
|
|
|
|
$pdf_url = $mUserCase->createUserCasePdf($uid, $data);
|
|
|
|
|
|
|
|
$this->ajax_json(true, '获取成功',array('pdf_url'=> $pdf_url));
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if(!$is_login)$this->ajax_json(false, '请登录后操作');
|
|
|
|
|
|
|
|
$email = $this->post('email');
|
|
|
|
if(empty($email))$this->ajax_json(false, '邮箱地址不能为空');
|
|
|
|
if(!filter_var($email, FILTER_VALIDATE_EMAIL))$this->ajax_json(false, '邮箱地址无效');
|
|
|
|
|
|
|
|
$pdf_url = $this->post('pdf_url');
|
|
|
|
if(empty($pdf_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));
|
|
|
|
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));
|
|
|
|
if(!$res)$this->ajax_json(true, '发送失败');
|
|
|
|
|
|
|
|
$this->ajax_json(true, '发送成功');
|
|
|
|
}
|
|
|
|
}
|