Browse Source

自拟药方

pull/1/head
pengda 8 months ago
parent
commit
6316b79dad
  1. 50
      control/index.php
  2. 4
      model/mFormula.php

50
control/index.php

@ -15,7 +15,7 @@ class index extends publicBase {
}
$uid = $this->post('uid');
$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();
$is_login = $m_user->validateToken($uid, $token);
@ -28,8 +28,34 @@ class index extends publicBase {
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() {
$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;
$name = trim($this->get('name'));
@ -60,6 +86,15 @@ class index extends publicBase {
}
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');
if ($id) {
$mformula = new mFormula();
@ -110,13 +145,20 @@ class index extends publicBase {
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;
//新增药方
$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(
'total' => $total,

4
model/mFormula.php

@ -37,6 +37,10 @@ class mFormula extends mBase {
}
$sql = "select s.*,COALESCE(SUM(u.use_num), 0) AS use_num from {$this->tbl} as s left join {$this->formula_use_log_tbl} as u on s.id=u.formula_id where {$where} group by s.id order by use_num desc,s.sort desc,s.id desc limit {$offset},{$page_size}";
// echo "<pre>";
// print_r($sql);
// exit;
return $this->obj->execute($sql, true, true);
}

Loading…
Cancel
Save