You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							330 lines
						
					
					
						
							11 KiB
						
					
					
				
			
		
		
		
			
			
			
				
					
				
				
					
				
			
		
		
	
	
							330 lines
						
					
					
						
							11 KiB
						
					
					
				
								<?php
							 | 
						|
								
							 | 
						|
								/**
							 | 
						|
								 *
							 | 
						|
								 */
							 | 
						|
								
							 | 
						|
								include_once(dirname(dirname(__FILE__)) . "/library/publicBase.php");
							 | 
						|
								include_once(SERVER_ROOT . "/model/mPage.php");
							 | 
						|
								
							 | 
						|
								class index extends publicBase {
							 | 
						|
								
							 | 
						|
								    private function _check_login() {
							 | 
						|
								        $uid = $this->post('uid');
							 | 
						|
								        $token = $this->post('token');
							 | 
						|
								        if ($uid < 0 || !$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() {
							 | 
						|
								        $this->ajax_json(false, 'hello world');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function ajax_save_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();
							 | 
						|
								
							 | 
						|
								        //生成唯一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->saveFormula($uinfo['uid'], $id, $name, $source, $method, $herbs);
							 | 
						|
								        if (!$id) $this->ajax_json(false, $mformula->getError());
							 | 
						|
								
							 | 
						|
								        $this->ajax_json(true, '请求成功', array('id' => $id));
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function ajax_delete_formula() {
							 | 
						|
								        $uinfo = $this->_check_login();
							 | 
						|
								
							 | 
						|
								        $id = $this->post('id') + 0;
							 | 
						|
								        $is_delete = $this->post('is_delete') + 0;
							 | 
						|
								
							 | 
						|
								        $mformula = new mFormula();
							 | 
						|
								        $id = $mformula->deleteFormula($uinfo['uid'], $id, $is_delete);
							 | 
						|
								        if (!$id) $this->ajax_json(false, $mformula->getError());
							 | 
						|
								
							 | 
						|
								        $this->ajax_json(true, '请求成功');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function ajax_user_formula() {
							 | 
						|
								        $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;
							 | 
						|
								
							 | 
						|
								        $condition = array();
							 | 
						|
								        $condition['uid'] = $uinfo['uid'];
							 | 
						|
								        $condition['is_delete'] = 0;
							 | 
						|
								        if ($content) $condition['name'] = $content;
							 | 
						|
								
							 | 
						|
								        $mformula = new mFormula();
							 | 
						|
								        $list = $mformula->getUserFormulaList($condition, $page_num, $page_size);
							 | 
						|
								        $total = $mformula->getUserFormulaTotal($condition);
							 | 
						|
								
							 | 
						|
								        $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->getFormulaInfo($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;
							 | 
						|
								
							 | 
						|
								        $condition = array();
							 | 
						|
								        $condition['uid'] = $uinfo['uid'];
							 | 
						|
								        $condition['is_delete'] = 0;
							 | 
						|
								        if ($content) $condition['name'] = $content;
							 | 
						|
								
							 | 
						|
								        $mformula = new mFormula();
							 | 
						|
								        $list = $mformula->searchFormulaList($condition, $page_num, $page_size);
							 | 
						|
								        $total = $mformula->searchFormulaTotal($condition);
							 | 
						|
								
							 | 
						|
								        $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'] . $data['prescribe_herb']);
							 | 
						|
								        $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->saveUserCase($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') : 20;
							 | 
						|
								
							 | 
						|
								        $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') : 20;
							 | 
						|
								
							 | 
						|
								        $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;
							 | 
						|
								        $start_date = $this->post('start_date');
							 | 
						|
								        //if (empty($start_date)) $this->ajax_json(false, '请选择导出开始时间');
							 | 
						|
								        $end_date = $this->post('end_date');
							 | 
						|
								        //if (empty($end_date)) $this->ajax_json(false, '请选择导出结束时间');
							 | 
						|
								
							 | 
						|
								        $m_user_case = new mUserCase();
							 | 
						|
								        $pdf_info = $m_user_case->getPdf($uinfo['uid'], $id, $start_date, $end_date);
							 | 
						|
								
							 | 
						|
								        $email = $this->post('email');
							 | 
						|
								        if (!empty($email)) {
							 | 
						|
								            //生成唯一id 防止重复请求
							 | 
						|
								            $request_id = md5($email . $pdf_info['pdf_path']);
							 | 
						|
								            $request_times = $m_user_case->requestLimit(sprintf(_QR_REQUEST_LIMIT, $request_id), 1, 7200);
							 | 
						|
								            if (!$request_times) $this->ajax_json(false, "医案记录已发送至您的邮箱,请查收邮件");
							 | 
						|
								
							 | 
						|
								            $res = $m_user_case->sendPdf($email, $pdf_info['pdf_path']);
							 | 
						|
								            if (!$res) $this->ajax_json(false, $m_user_case->getError());
							 | 
						|
								
							 | 
						|
								            $this->ajax_json(true, '发送成功');
							 | 
						|
								        }
							 | 
						|
								
							 | 
						|
								        $this->ajax_json(true, '获取成功', array('pdf_url' => $pdf_info['pdf_url']));
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function user_case_list() {
							 | 
						|
								        $uid = $this->post('uid') + 0;
							 | 
						|
								        $start_date = $this->post('start_date');
							 | 
						|
								        $end_date = $this->post('end_date');
							 | 
						|
								        $page_num = 1;
							 | 
						|
								        $page_size = 500;
							 | 
						|
								
							 | 
						|
								        $m_user_case = new mUserCase();
							 | 
						|
								        $data = $m_user_case->getUserCaseListPdfInfo($uid, $page_num, $page_size, $start_date, $end_date);
							 | 
						|
								
							 | 
						|
								        $this->view['data'] = $data;
							 | 
						|
								        $this->setViewTpl('index/export_pdf.html');
							 | 
						|
								    }
							 | 
						|
								
							 | 
						|
								    public function user_case() {
							 | 
						|
								        $id = $this->post('id') + 0;
							 | 
						|
								        $uid = $this->post('uid') + 0;
							 | 
						|
								
							 | 
						|
								        $m_user_case = new mUserCase();
							 | 
						|
								        $data = $m_user_case->getUserCasePdfInfo($uid, $id);
							 | 
						|
								
							 | 
						|
								        $this->view['data'] = array($data);
							 | 
						|
								        $this->setViewTpl('index/export_pdf.html');
							 | 
						|
								    }
							 | 
						|
								}
							 | 
						|
								
							 |