@ -15,7 +15,7 @@ class index extends publicBase {
}
}
$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, '参数错误', array('code' => CODE_LOGIN_EXIPRE));
if ($uid < 0 | | ! $ token ) $ this- > ajax_json(false, '参数错误', array('code' => CODE_LOGIN_EXIPRE));
$m_user = new mUser();
$m_user = new mUser();
$is_login = $m_user->validateToken($uid, $token);
$is_login = $m_user->validateToken($uid, $token);
@ -28,8 +28,34 @@ class index extends publicBase {
return $uinfo;
return $uinfo;
}
}
public function login() {
$name = $this->get('name');
$password = $this->get('password');
$m_user = new mUser();
$robj = $m_user->initRedis();
$user_info = $robj->get(_QR_ADMIN_USER_INFO);
if (!empty($name) & & !empty($password)) {
$user_info = json_decode($user_info, true);
if ($user_info['name'] == $name & & $user_info['password'] == $password) {
//设置登录状态
$robj->setex(_QR_ADMIN_LOGIN_USER_INFO, 12 * 60 * 60, json_encode(array('uid' => 0, 'token' => $m_user->getToken(0))));
header('Location: /index/home');
}
}
if (empty($user_info)) {
$robj->setex(_QR_ADMIN_USER_INFO, 12 * 60 * 60, json_encode(array('name' => 'admin', 'password' => bin2hex(openssl_random_pseudo_bytes(8)))));
}
}
public function home() {
public function home() {
$mformula = new mFormula();
$mformula = new mFormula();
$robj = $mformula->initRedis();
$user_info = $robj->get(_QR_ADMIN_LOGIN_USER_INFO);
$user_info = json_decode($user_info, true);
if (empty($user_info)) header('Location: /index/login');
$is_all = $this->get('is_all') + 0;
$is_all = $this->get('is_all') + 0;
$name = trim($this->get('name'));
$name = trim($this->get('name'));
@ -60,6 +86,15 @@ class index extends publicBase {
}
}
public function formula_add() {
public function formula_add() {
$mformula = new mFormula();
$robj = $mformula->initRedis();
$user_info = $robj->get(_QR_ADMIN_LOGIN_USER_INFO);
$user_info = json_decode($user_info, true);
if (empty($user_info)) header('Location: /index/login');
$this->view['uid'] = $user_info['uid'];
$this->view['token'] = $user_info['token'];
$id = $this->get('id');
$id = $this->get('id');
if ($id) {
if ($id) {
$mformula = new mFormula();
$mformula = new mFormula();
@ -110,13 +145,20 @@ class index extends publicBase {
public function ajax_user_formula() {
public function ajax_user_formula() {
$uinfo = $this->_check_login();
$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_num = $this->post('page_num') ? $this->post('page_num') : 1;
$page_size = $this->post('page_size') ? $this->post('page_size') : 20;
$page_size = $this->post('page_size') ? $this->post('page_size') : 20;
//新增药方
$mformula = new mFormula();
$mformula = new mFormula();
$list = $mformula->getUserFormulaList($uinfo['uid'], $page_num, $page_size);
$total = $mformula->getUserFormulaTotal($uinfo['uid']);
$condition = array();
$condition['uid'] = $uinfo['uid'];
if ($content) $condition['name'] = $content;
$list = $mformula->getAllFormulaList($condition, $page_num, $page_size);
$total = $mformula->getAllFormulaTotal($condition);
$rdata = array(
$rdata = array(
'total' => $total,
'total' => $total,