diff --git a/config/define.php b/config/define.php index 469854e..7f04b3c 100644 --- a/config/define.php +++ b/config/define.php @@ -20,6 +20,7 @@ // 小程序获取openid define('MP_APPID',"wxb840b419525a63e2"); // 公众号APPID define('MP_SECRET',"85b9058789a45b6077e8380365ff4bbc"); // 公众号秘钥 + define('MP_GET_OPENID_HREF',"https://api.weixin.qq.com/sns/jscode2session?appid=%s&secret=%s&grant_type=authorization_code&js_code=%s"); define('JWT_KEY','3f8aef32b8b77c6e'); @@ -34,4 +35,6 @@ define('USER_CASE_PDF_PATH', DATACENTER_ROOT.'/tcm_pdf/%d/'); define('USER_CASE_PDF_URL', TCM_DOMAIN.'/case_pdf/%d/%s.pdf'); + define('CODE_LOGIN_EXIPRE', 40002); + diff --git a/control/index.php b/control/index.php index 2f47037..e7c630e 100644 --- a/control/index.php +++ b/control/index.php @@ -47,17 +47,24 @@ class index extends publicBase { } public function ajax_search() { - $content = $this->post('content'); - if (empty($content)) $this->ajax_json(false, '请输入方名'); + $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') : 100; + $page_size = $this->post('page_size') ? $this->post('page_size') : 20; $m_case = new mCase(); $data = $m_case->getCaseByName($content, $page_num, $page_size); $total = $m_case->getCaseByNameTotal($content); + $rdata = array( + 'total'=>$total, + 'per_page' => $page_size, + 'last_page' => ceil($total / $page_size), + 'current_page' => $page_num, + 'data' => $data + ); - $this->ajax_json(true, '获取成功', array('total' => $total, 'current_page' => $page_num, 'total_page' => ceil($total / $page_size), 'list' => $data)); + $this->ajax_json(true, '获取成功', $rdata); } public function ajax_case_detail() { @@ -174,7 +181,7 @@ class index extends publicBase { } public function ajax_login() { - $code = $this->get('code'); + $code = $this->post('code'); if (!$code) $this->ajax_json(false, '非法请求'); $m_user = new mUser(); @@ -186,6 +193,18 @@ class index extends publicBase { $this->ajax_json(true, '登录成功', array('uid' => $user['uid'], 'identifier' => $user['identifier'], 'token' => $token)); } + public function get_user() { + $uid = $this->post('uid'); + $token = $this->post('token'); + if (empty($uid) || empty($token)) $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_EXIPRE)); + + $this->ajax_json(true, '', $uinfo); + } + public function ajax_contact_us() { $this->ajax_json(true, '获取成功', array('img_url' => CONTACT_US_IMG_URL)); } diff --git a/model/mCase.php b/model/mCase.php index c7db222..ae086fc 100644 --- a/model/mCase.php +++ b/model/mCase.php @@ -173,19 +173,27 @@ class mCase extends mBase { } public function getCaseByName($name, $page_num, $page_size) { - $sql = " `name` like '%{$name}%'"; + $where = array(); + if(!empty($name)) { + $sql = " `name` like '%{$name}%'"; + $where = array('sql' => $sql, 'vals' => array()); + } $offset = ($page_num - 1) * $page_size; - $res = $this->obj->selectAll($this->tbl, array('sql' => $sql, 'vals' => array()), 'use_num desc,sort asc ', array($offset, $page_size)); + $res = $this->obj->selectAll($this->tbl, $where, 'use_num desc,sort asc ', array($offset, $page_size)); if (empty($res)) return array(); return $res; } public function getCaseByNameTotal($name) { - $sql = " `name` like '%{$name}%'"; + $where = array(); + if(!empty($name)) { + $sql = " `name` like '%{$name}%'"; + $where = array('sql' => $sql, 'vals' => array()); + } - return $this->obj->count($this->tbl, array('sql' => $sql, 'vals' => array())); + return $this->obj->count($this->tbl, $where); } public function getCaseInfo($id) {