public function lists() { $page = isset($_GET['p']) ? $_GET['p'] : 1; $userMdl = D('User'); $filter = array(); //处理搜索问题 $fValue = ''; if (isset($_GET['f']) && in_array($_GET['f'], array('id'))) { $field = $_GET['f']; $fValue = trim(urldecode($_GET['q'])); if ('id' == $field) { $filter['id'] = \Common\Lib\Idhandler::decode($fValue); } elseif ('nickname' == $field) { $filter['nickname'] = array('like', '%' . trim($fValue) . '%'); } } $this->assign('field', $field); $this->assign('fv', $fValue); //处理排序问题 $order = 'updated_at desc'; if (isset($_GET['order']) && $_GET['order']) { $order = str_replace('_', ' ', $_GET['order']); } $orderArr = explode(' ', $order); $this->assign('order', $orderArr); $count = $userMdl->getCount($filter); $utils = new \Common\Lib\Utils(); $pagination = $utils->pagination($count, C('PAGE_LIMIT')); $users = $userMdl->getList($filter, C('PAGE_LIMIT'), $page, $order); foreach ($users as &$user) { $user['id'] = \Common\Lib\Idhandler::encode($user['id']); } $this->assign('count', $count); $this->assign('page', $pagination); $this->assign('users', $users); $this->display(); }
public function lists() { $page = isset($_GET['p']) ? $_GET['p'] : 1; $productMdl = D('Items'); $userMdl = D('User'); $filter = array(); //处理搜索问题 $fValue = ''; if (isset($_GET['f']) && in_array($_GET['f'], array('id', 'tid', 'link'))) { $field = $_GET['f']; $fValue = trim(urldecode($_GET['q'])); switch ($field) { case 'id': $filter['id'] = \Common\Lib\Idhandler::decode($fValue); break; case 'tid': $filter['nid'] = trim($fValue); $filter['platform'] = 'taobao'; break; case 'link': $filter['o_url'] = urldecode(trim($fValue)); break; default: break; } } $this->assign('field', $field); $this->assign('fv', $fValue); //处理排序问题 $order = 'updated_at desc'; if (isset($_GET['order']) && $_GET['order']) { $order = str_replace('_', ' ', $_GET['order']); } $orderArr = explode(' ', $order); $this->assign('order', $orderArr); $count = $productMdl->getCount($filter); $utils = new \Common\Lib\Utils(); $pagination = $utils->pagination($count, C('PAGE_LIMIT')); $products = $productMdl->getList($filter, C('PAGE_LIMIT'), $page, $order); $hosts = C('LOCALHOST'); if ($products) { foreach ($products as &$p) { $p['id'] = \Common\Lib\Idhandler::encode($p['id']); $user = array(); if ($p['uid'] > 0) { $user = $userMdl->getRow(array('id' => $p['uid'])); $user['id'] = \Common\Lib\Idhandler::encode($user['id']); } $p['user'] = $user; $p['product_url'] = $hosts . 'show/' . $p['id']; } } $this->assign('count', $count); $this->assign('page', $pagination); $this->assign('products', $products); $this->display(); }