From 6316b79dad982dda9d24c2750aa7b2433bbaeaba Mon Sep 17 00:00:00 2001 From: pengda <10266652509@qq.com> Date: Wed, 18 Sep 2024 18:38:06 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E6=8B=9F=E8=8D=AF=E6=96=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- control/index.php | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- model/mFormula.php | 4 ++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/control/index.php b/control/index.php index 5cdd82c..02c6e59 100644 --- a/control/index.php +++ b/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, diff --git a/model/mFormula.php b/model/mFormula.php index 606f209..6024160 100644 --- a/model/mFormula.php +++ b/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 "
";
+//        print_r($sql);
+//        exit;
         return $this->obj->execute($sql, true, true);
     }