Authored by 周少峰

添加分页,helpsearch代码优化

<?php
namespace Plugin;
use Plugin\Images;
use Plugin\Paging;
/**
* 搜索辅助类
*/
... ... @@ -10,11 +10,10 @@ class HelperSearch
/**
* 请求时用的所有参数
*/
private static $params = array();
public static $params = array();
//当前页面
private static $current_url = '';
private static $page = 1;
//当前页
public static $page = 1;
/**
* 选中的条件
... ... @@ -25,140 +24,109 @@ class HelperSearch
* list分类面包屑
* @var array
*/
public static $listnav = array(
array(
public static $listnav = array();
//设置导航
private static function setListNav($option = array())
{
$cookieChannel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
if (isset($option['brandName']) && !empty($option['brandName'])) {
$initNav = $option['brandName'];
}else{
$initNav = '列表';
}
self::$listnav[0] = array(
'href' => '',
'name' => '首页'
),
array(
'name' => $cookieChannel
);
self::$listnav[1] = array(
'href' => '',
'name' => '列表'
)
);
'name' => $initNav
);
}
/**
* 组织搜索模板数据
* @param array $data
* @param array $options
* @return array
*/
public static function getList($data = array() , $options = array()) {
if (empty($data)) {
return array();
}
public static function getList($data = array() , $options = array())
{
$result = array();
self::$params = $_GET;
unset(self::$params['/']);
unset(self::$params['page']);
unset(self::$params['/sale']);
unset(self::$params['sale']);
$result = array();
if (!isset($data['data']) || !isset($data['data']['product_list']) || !is_array($data['data']['product_list'])) {
return array();
}
$result['product_list'] = self::getProductList($data['data']['product_list'], $options['imgSize'], $options['minImgSize'], $options['gender']);
$filter = $data['data']['filter'];
//产品列表
$result['goods'] = self::getProductList($data['data']['product_list'], $options['imgSize']);
//总页数
$result['page_total'] = $data['data']['page_total'];
$result['total'] = $data['data']['total'];
//当前页
$result['page'] = $data['data']['page'];
//设置当前页
self::$page = $result['page'];
//搜索条件
if (isset($data['data']['filter']) && !empty($data['data']['filter'])) {
$filter = $data['data']['filter'];
$result['filter']['left_sort'] = isset($filter['minsort']) ? self::minsort($filter['minsort']) : array();
$result['filter']['group_sort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
$result['filter']['size'] = self::size($filter);
$result['filter']['color'] = self::color($filter);
$result['filter']['price'] = self::price($filter);
$result['filter']['brand'] = self::brand($filter);
$result['filter']['parameters'] = self::standard($filter);
$result['filter']['rowNum4'] = self::rowNum();
$result['filter']['rowNum6'] = self::rowNum(6);
$result['filter']['viewNum'] = self::viewNum();
$result['filter']['priceSubmit'] = self::priceSubmit();
$result['filter']['gender'] = self::gender($filter);
$result['filter']['selected'] = self::getSelected();
$result['filter']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
$result['filter']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
$result['filter']['clear'] =self::current();
$result['filter']['next'] = self::next($data['data']['page_total'],$data['data']['filter']);
$result['filter']['listnav'] = self::$listnav;
$result['filter']['discount'] = self::getDiscount($filter['discount']);
$result['filter']['recent'] = self::recentShelve($filter['recent']);
$result['filter']['seniorChose'] = self::seniorChose($filter);
}
//清除选中
$result['filters']['checkedConditions']['clearUrl'] = self::current();
//频道
$result['filters']['channel'] = self::gender($filter);
//分类
$result['filters']['sort'] = array();
//品牌
$result['filters']['brand'] = self::brand($filter);
//价格
$result['filters']['price'] = self::price($filter);
//颜色
$result['filters']['color'] = self::color($filter);
//尺寸
$result['filters']['size'] = self::size($filter);
//高级选项
$result['filters']['seniorChose'] = self::seniorChose($filter);
//排序方式
$result['opts']['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
//特殊:新品、特价、限量
$result['opts']['checks'] = array(self::isnew(),self::specialoffer(),self::limited());
//每行显示5个产品
$result['opts']['fivePerLine'] = true;
//每行显示6个产品
$result['opts']['sixPerLineHref'] = true;
//每页显示的数量
$result['opts']['countPerPage'] = $options['viewNum'];
//可选每页显示数量
$result['opts']['pageCounts'] = self::viewNum();
$result['opts']['curPage'] = self::$page;
$result['opts']['pageCount'] = $data['data']['page_total'];
$result['opts']['nextHref'] = self::next($data['data']['page_total'],$data['data']['filter']);
$result['hasNextPage'] = array(
'href' => self::next($data['data']['page_total'],$data['data']['filter']),
'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
);
//分类
$result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
//一周新品上架
$result['leftContent'][]['newSales'] = self::recentShelve($filter['recent']);
//全部折扣
$result['leftContent'][]['allDiscount'] = self::getDiscount($filter['discount']);
//总记录数
$result['totalCount'] = $data['data']['total'];
//分页
$result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
//echo $result['pager']; exit;
//选中条件
$result['filters']['checkedConditions']['conditions'] = self::getSelected();
$result['pathNav'] = self::$listnav;
return $result;
}
/**
* 组织列表模板数据
*
*/
public static function getTemplateData($result, $options){
//模板数据
$data = array(
'brandBanner' => array(),
'pathNav' => $result['filter']['listnav'],
'shopEntry' => array(),
'filters' => array(
'checkedConditions' => array(
'conditions' => $result['filter']['selected'],
'clearUrl' => $result['filter']['clear']
),
'channel' => $result['filter']['gender'],
'sort' => array() ,
'brand' => $result['filter']['brand'],
'price' => $result['filter']['price'],
'color' => $result['filter']['color'],
'size' => $result['filter']['size'],
'seniorChose' => $result['filter']['seniorChose']
),
'opts' => array(
'sortType' => $result['filter']['sortType'],
'checks' => $result['filter']['checks'],
'fivePerLine' => true,
'sixPerLineHref' => '',
'countPerPage' => $options['viewNum'],
'pageCounts' => $result['filter']['viewNum'],
'curPage' => $result['page'],
'pageCount' => $result['page_total'],
'nextHref' => $result['filter']['next']
),
'hasNextPage' => array(
'href' => $result['filter']['next'],
'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
),
'goods' => $result['product_list'],
'leftContent' => array(
array(
'allSort' => array(
//'updateNum' => $result['filter']['group_sort']['all']['num'],
'list' => $result['filter']['group_sort']['list']
)
),
array(
'advNav' => array()
),
array(
'advPic' => array()
),
array(
'newSales' => $result['filter']['recent']
),
array('allDiscount' => $result['filter']['discount'])
),
'totalCount' => $result['total'],
);
return $data;
}
/**
* TODO 组织商品列表信息
* @param $product 接口返回商品列表
* @author sefon 2015-12-21 17:24:04
* @return array
*/
public static function getProductList($product,$imgSize){
$result = array();
$goods = array();
foreach($product as $key => $val){
//NEW
$isNew = $val['is_new'] == 'Y' ? true : false;
... ... @@ -171,14 +139,13 @@ class HelperSearch
//再到着
//年终大促
// 年中大促
foreach($val['goods_list'] as $k => $v){
$goods_list[$k]['url'] = Helpers::getUrlBySkc($val['product_id'], $v['goods_id'], $val['cn_alphabet']);
}
if (!empty($val['default_images'])) {
$val['default_images'] = Images::getImageUrl($val['default_images'],$imgSize[0],$imgSize[1]);
}
$result[] = array(
$goods[] = array(
'tags' => array(
'isNew' => $isNew,
'isLimit' => $isLimit
... ... @@ -192,7 +159,7 @@ class HelperSearch
'skn' => $val['product_skn']
);
}
return $result;
return $goods;
}
/**
* 版型等其它筛选项
... ... @@ -284,6 +251,7 @@ class HelperSearch
* @return array
*/
public static function groupSort($sort, $option = array()) {
self::setListNav();
$params = self::$params;
$gender = isset($params['gender']) ? $params['gender'] : '';
... ... @@ -385,16 +353,18 @@ class HelperSearch
/**
* 品牌,可以多选
* @param array $brand
* @param array $options
* @return array
*/
public static function brand($filter) {
public static function brand($filter, $options = array()) {
if (isset($options['brandName'])) {
return array();
}
$params = self::$params;
$brand_ids = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
if (isset($params['brand'])) {
unset($params['brand']);
}
$result = array(
'default' => array() ,
'brandIndex' => array(
... ... @@ -412,14 +382,11 @@ class HelperSearch
'U~Z' => array() ,
)
);
$brand_keys = array_reverse(array_keys($result['list']));
if (isset($filter['brand']) && !empty($filter['brand'])) {
//有商品结果时
$brand = $filter['brand'];
foreach ($brand as $v) {
if (!isset($v['brand_alif']) && isset($v['brand_name_en'])) {
$v['brand_alif'] = substr($v['brand_name_en'], 0, 1);
}
... ... @@ -429,7 +396,6 @@ class HelperSearch
if (!isset($v['brand_domain'])) {
$v['brand_domain'] = '';
}
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
... ... @@ -442,9 +408,7 @@ class HelperSearch
'href' => self::buildurl($selected_params)
);
}
$selected_brand = isset(self::$params['brand']) && !empty(self::$params['brand']) ? explode(',', self::$params['brand']) : array();
if (empty($selected_brand)) {
$url = self::buildurl(array_merge($params, array(
'brand' => $v['id']
... ... @@ -463,7 +427,6 @@ class HelperSearch
'brand' => implode(',', $selected_brand)
)));
}
$this_brand = array(
'brand_id' => $v['id'],
'name' => $v['brand_name'],
... ... @@ -471,7 +434,6 @@ class HelperSearch
'href' => $url,
'active' => in_array($v['id'], $brand_ids) ? true : false
);
if (count($result['default']) < 10) {
$result['default'][] = $this_brand;
}
... ... @@ -493,11 +455,9 @@ class HelperSearch
}
}
else if (isset($filter['paramNames']) && isset($filter['paramNames']['brand'])) {
//无商品结果时且选择了品牌
$brand = $filter['paramNames']['brand'];
foreach ($brand as $v) {
//选中的筛选条件
if (in_array($v['id'], $brand_ids)) {
$selected_brand = explode(',', self::$params['brand']);
... ... @@ -764,7 +724,8 @@ class HelperSearch
/**
* 高级选项
*/
public static function seniorChose($filter){
public static function seniorChose($filter)
{
$style = self::style($filter);
$other = self::standard($filter);
$result = array_merge($style,$other);
... ... @@ -774,9 +735,9 @@ class HelperSearch
/**
* 每页显示数量
*/
public static function viewNum() {
public static function viewNum()
{
$params = self::$params;
$view_num = array(
60,
100,
... ... @@ -797,8 +758,9 @@ class HelperSearch
/**
* 显示行数
*/
public static function rowNum($num = 5) {
$params = self::$params;
public static function rowNum($num = 5)
{
$params = self::$params;
$params['rowNum'] = $num;
... ... @@ -808,7 +770,8 @@ class HelperSearch
/**
* 是否特价
*/
public static function specialoffer() {
public static function specialoffer()
{
$params = self::$params;
if (isset($params['specialoffer']) && !empty($params['specialoffer'])) {
unset($params['specialoffer']);
... ... @@ -829,7 +792,8 @@ class HelperSearch
/**
* 是否限量
*/
public static function limited() {
public static function limited()
{
$params = self::$params;
if (isset($params['limited']) && !empty($params['limited'])) {
unset($params['limited']);
... ... @@ -849,7 +813,8 @@ class HelperSearch
/**
* 是否新品
*/
public static function isnew() {
public static function isnew()
{
$params = self::$params;
if (isset($params['isNew']) && !empty($params['isNew'])) {
... ... @@ -870,7 +835,8 @@ class HelperSearch
/**
* 排序是否最新
*/
public static function orderTime() {
public static function orderTime()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -888,7 +854,8 @@ class HelperSearch
/**
* 排序是否默认
*/
public static function orderDefault() {
public static function orderDefault()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -904,7 +871,8 @@ class HelperSearch
/**
* 价格排序
*/
public static function orderPrice() {
public static function orderPrice()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -946,7 +914,8 @@ class HelperSearch
/**
* 折扣排序
*/
public static function orderDiscount() {
public static function orderDiscount()
{
$params = self::$params;
if (isset($params['order'])) {
unset($params['order']);
... ... @@ -988,7 +957,8 @@ class HelperSearch
/**
* 获取自定义价格要提交的地址
*/
public static function priceSubmit() {
public static function priceSubmit()
{
$params = self::$params;
$price = array();
if (isset($params['price'])) {
... ... @@ -1030,7 +1000,8 @@ class HelperSearch
* @param array $params
* @return string
*/
private static function buildurl($params) {
private static function buildurl($params)
{
if (empty($params)) {
return self::current();
}
... ... @@ -1054,7 +1025,8 @@ class HelperSearch
/**
* 获取选中的条件
*/
public static function getSelected() {
public static function getSelected()
{
$result = array();
$is_array_key = array(
'brand',
... ... @@ -1078,7 +1050,8 @@ class HelperSearch
* @param array $list
* @return array
*/
public static function getDiscount(array $list = array()) {
public static function getDiscount(array $list = array())
{
$params = self::$params;
if (empty($list)) {
... ... @@ -1105,7 +1078,7 @@ class HelperSearch
}
$result = array(
//'updateNum' => $total,
'list' => $list
'list' => array_values($list)
);
return $result;
}
... ... @@ -1113,7 +1086,8 @@ class HelperSearch
/**
* 最新上架
*/
public static function recentShelve($list = array()){
public static function recentShelve($list = array())
{
if (empty($list)) {
return array();
}
... ... @@ -1153,11 +1127,7 @@ class HelperSearch
*/
public static function current(){
$url = explode('?', $_SERVER['REQUEST_URI']);
self::$current_url = $url[0];
self::$listnav[0] = array(
'href' => '$url[0]',
'name' => '首页'
);
self::$listnav[0]['href'] = $url[0];
return $url[0];
}
/**
... ... @@ -1175,7 +1145,7 @@ class HelperSearch
}
/**
* 组织产品
* 组织产品的图片
* @param $product
* @param $options
* @return array
... ... @@ -1192,4 +1162,9 @@ class HelperSearch
}
return $result;
}
//分页
public static function pager($total,$view_num){
$Paging = new Paging('Yoho');
return $Paging->setTotal($total)->setSize($view_num)->view(0);
}
}
... ...
<?php
namespace Plugin;
use \Hood\Paging as HPage;
class Paging extends HPage
{
/**
* 路径
*
* @var String
*/
private $path = '';
/**
* 查询参数
* String or Array
* @var mixed
*/
private $query;
/**
* 分页集尺寸
*
* @var Integer
*/
private $pageSetSize = 11;
/**
* 子串
*
* @var String
*/
private $substring = '?';
/**
* 连接符号
*
* @var String
*/
private $sign = '=';
/**
* 对符
*
* @var String
*/
private $pairs = '&';
/**
* 模板路径
*
* @var String
*/
private $templatePath = '';
/**
* jsName
* @var String
*/
private $jsFName = '';
/**
* 废弃参数
* @var String
*/
private $disuse = null;
/**
* 设置分页链接中的关键字
*
* @var String
*/
private $keyword = 'page';
/**
* 是否开启rewrite url
*
* @var bool
*/
private $rewrite = false;
/**
* 附加参数
* @var string
*/
private $appendParam = '';
/**
* 分页中代码当前页码的常量
*
*/
const PAGER_VARIABLE_STRING = "%{PAGE_NO}";
public function __construct($file)
{
$this->templatePath = __DIR__ . '/Paging/' . ucfirst($file) . '.php';
}
/**
* 新的获取当前偏移
* @return Integer
*/
public function getNewCurrent()
{
if ($this->currentPage > 1) {
return min($this->currentPage, $this->getPageNum());
}
$pageNo = !isset($_GET[$this->keyword]) ? 0 : (int)(intval($_GET[$this->keyword]) * $this->getSize()) - $this->getSize();
return (int)($pageNo < 0 ? 0 : $pageNo);
}
/**
* 重载当前页方法
* @return Integer
*/
public function getCurrent()
{
if ($this->currentPage > 1) {
return min($this->currentPage, $this->getPageNum());
}
$pageNo = isset($_GET[$this->keyword]) ? (int)intval($_GET[$this->keyword]) : 1;
if ($pageNo <= 0) {
$pageNo = 1;
}
$this->currentPage = min($pageNo, $this->getPageNum());
return $this->currentPage;
}
/**
* 获取关键词
* @return String
*/
public function getKeyword()
{
return $this->keyword;
}
/**
* 设置关键词
*
* @param String $keyword
* @return QLib_Paging
*/
public function setKeyword($keyword)
{
if (!empty($keyword)) {
$this->keyword = $keyword;
}
return $this;
}
/**
* 设置js名字
* @param String $name
* @return Q_Page_Abstract
*/
public function setFJs($name)
{
if (!empty($name)) {
$this->jsFName = $name;
}
return $this;
}
/**
* 设置附加参数
* @param string $param
* @return Q_Page_Abstract
*/
public function setAppendParam($param)
{
$this->appendParam = $param;
return $this;
}
/**
* 获取附加参数
* @return string
*/
public function getAppendParam()
{
return $this->appendParam;
}
/**
* 获取分页js名字
* @return String
*
*/
public function getFJs()
{
return $this->jsFName;
}
/**
*
* 设置链接的路径
*
* @param String $path
* @return QLib_Paging
*/
public function setPath($path)
{
if (!empty($path)) {
$this->path = trim($path);
}
return $this;
}
/**
* 设置连续Url
*
* @param bool $seo
* @return QLib_Paging
*/
public function rewrite($rw = true)
{
if ($rw == true) {
$this->substring = '';
$this->sign = '/';
$this->pairs = '/';
$this->rewrite = true;
}
return $this;
}
/**
* 取得程序路径
* @return String
*/
public function getPath()
{
return $this->path;
}
/**
* 设置分页集尺寸
*
* @param integer $num 大于1
* @return QLib_Paging
*/
public function setPageSetSize($num)
{
$this->pageSetSize = (int)intval($num);
return $this;
}
/**
* 取得分页集尺寸
*
* @return integer
*/
public function getPageSetSize()
{
return (int)$this->pageSetSize;
}
/**
* 获取查询参数
* @return String
*/
public function getQuery()
{
$query = $this->query;
if (empty($this->query)) {
$this->query = $this->autoUrl();
}
if (is_array($this->query) && count($this->query) > 0) {
$_query = array();
foreach ($this->query as $key => $value) {
if($key == '_pjax'){
break;
}
if ($key == $this->getKeyword()) {
continue;
}
if (is_array($value)) {
foreach ($value as $k => $val) {
$_query[] = "{$key}[]" . $this->sign . $val;
}
} else {
$_query[] = "{$key}" . $this->sign . $value;
}
}
$this->query = $this->pairs . implode($this->pairs, $_query);
}
return $this->query ? $this->query : '';
}
/**
* 获取URL
*
* @param Integer $pageNo
* @return String
*/
public function getUrl($pageNo)
{
$query = $this->getQuery();
if (strstr($query, self::PAGER_VARIABLE_STRING) && is_string($query)) {
$query = str_replace(self::PAGER_VARIABLE_STRING, $pageNo, $query);
} else {
if (empty($query)) {
$query = $this->getKeyword() . $this->sign . $pageNo;
} else {
$query = $this->getKeyword() . $this->sign . $pageNo . $query;
}
}
$url = $this->getPath() . $this->substring . $query;
if ($this->getFJs()) {
$url = $query;
}
return $url;
}
/**
* 设置查询参数
*
* @param mixed $query String or Array
* @return QLib_Paging
*/
public function setQuery($query)
{
$this->query = $query;
return $this;
}
/**
* 设置模板路径
*
* @param String $path
* @return QLib_Paging
*/
public function setTemplate($path)
{
$this->templatePath = $path;
return $this;
}
/**
* 输出模板
*/
public function view($print = true)
{
if ($this->getTotal() > 0) {
include($this->templatePath);
if($print){
print $html;
}else{
return $html;
}
}
return '';
}
/**
* 自动组织 URL
* @return Array
*/
private function autoUrl()
{
$queryOpt = $_SERVER['REQUEST_URI'];
$queryArg = parse_url($queryOpt);
$queryOpt = isset($queryArg['query']) ? explode('&', $queryArg['query']) : array();
$query = array();
foreach ($queryOpt as $key => $val) {
$strTmp = explode('=', $val);
if (count($strTmp) < 2 || empty($strTmp[0]) || $strTmp[1] == '' || $strTmp[0] == $this->getKeyword()) {
continue;
}
if (is_array($this->disuse)) {
if (in_array($strTmp[1], $this->disuse) || in_array($strTmp[0], $this->disuse)) {
continue;
}
} else {
if ($strTmp[1] == $this->disuse || $strTmp[0] == $this->disuse) {
continue;
}
}
$query[$strTmp[0]] = $strTmp[1];
}
return $query;
}
/**
* set废弃参数
* @param mixed $disuse
* @return QLib_Paging
*/
public function setDisuse($disuse = null)
{
$this->disuse = $disuse;
return $this;
}
}
\ No newline at end of file
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '';
if($current > 1)
{
$html .= '<a href="' . $this->getUrl($current - 1) . '" title="上一页"><span class="ifont10"><</span></a>';
}
if ($pageNum > 1) {
if($pageNum > 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}
else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" class="page_next" title="下一页"><span class="ifont10">></span></a>';
}
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '<div class="left"><span class="rgb9">'.$startNum.' - '.$endNum.' / 共'.$total.'件商品</span></div><div class="goods-page right">';
if ($current > 1) {
$html .= '<a href="' . $this->getUrl($current - 1) . '" class="page_pre" title="上一页"><span class="ifont10"><</span>上一页</a>';
}
if ($pageNum > 1) {
if($pageNum > 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" title="下一页">下一页<span class="ifont10">></span></a>';
}
$html .= '</div>';
... ...
<?php
$pages = array();
$pageNum = $this->getPageNum(); #总分页数
$current = $this->getCurrent(); #当前页
$size = $this->getSize(); #每页显示数
$total = $this->getTotal(); #获取总数
$pageSetNum = $this->getPageSetSize(); #分页集数
$start = $end = 0;
if($current <= 4){
$start = 1;
$end = $start + 4;
}elseif(($pageNum - $current - 2) > 1)
{
$start = $current - 2 < 1 ? 1 : $current - 2;
$end = $current + 2;
}else{
$start = $current - 2;
$end = $pageNum;
}
if($end > $pageNum)
{
$end = $pageNum;
}
$startNum = $size * ($current - 1) + 1;
$endNum = min($size * $current, $total);
$html = '<div class="left"></div><div class="list-page right">';
if ($current > 1) {
$html .= '<a href="' . $this->getUrl($current - 1) . '" class="page_pre" title="上一页"><span class="ifont10"><</span>上一页</a>';
}
if ($pageNum > 1) {
if($pageNum >= 5 && $current > 4){
$html .= '<a href="' . $this->getUrl(1) . '"><span>' . 1 . '</span></a>';
$html .= '<a><span>...</span></a>';
$start = $current - 2;
$end = $pageNum - $current <= 3 ? $pageNum : $current + 2;
}
for ($i = $start; $i <= $end; ++$i) {
$_start = $size * ($i - 1) + 1;
$_end = min($size * $i, $total);
if ($i != $current) {
$html .= '<a href="' . $this->getUrl($i) . '"><span>' . $i . '</span></a>';
}else {
$html .= '<a href="'. $this->getUrl($i) .'" class="cur"><span>' . $i . '</span></a>';
}
}
if($pageNum > 5 && $pageNum - $current > 3){
$html .= '<a><span>...</span></a>';
$html .= '<a href="' . $this->getUrl($pageNum) . '"><span>' . $pageNum . '</span></a>';
}
}
if ($current < $pageNum) {
$html .= '<a href="' . $this->getUrl($current + 1) . '" title="下一页">下一页<span class="ifont10">></span></a>';
}
$html .= '</div>';
\ No newline at end of file
... ...
... ... @@ -2,6 +2,7 @@
namespace Product;
use Configs\CacheConfig;
use Plugin\HelperSearchNew;
use Plugin\Images;
use Plugin\Cache;
use Plugin\HelperSearch;
... ... @@ -28,33 +29,38 @@ class SearchModel
* @author sefon 2015-12-17 16:12:18
* @return array
*/
public static function getSearchData($condition, $options,$classes)
public static function getSearchData($condition, $options)
{
$data = array();
// 调用接口查询商品数据
$result = SearchData::searchElasticByCondition($condition);
// 调用分类信息
$category = SearchData::getClassesData($classes);
if (isset($category['code']) && $category['code'] === 200) {
$result['data']['filter']['group_sort'] = $category['data']['sort'];
}
// 调用折扣区间
$discount = SearchData::getDiscount();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['discount'] = $discount['data']['discount'];
}
// 调用最新上架
$recent = SearchData::recentShelve();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['recent'] = $recent['data']['recent'];
}
// 组织模板数据
if (isset($result['code']) && $result['code'] === 200) {
$res = HelperSearch::getList($result, $options);
$list = HelperSearch::getTemplateData($res, $options);
// 调用分类信息
$category = SearchData::getClassesData();
if (isset($category['code']) && $category['code'] === 200) {
$result['data']['filter']['group_sort'] = $category['data']['sort'];
}
// 调用折扣区间
$discount = SearchData::getDiscount();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['discount'] = $discount['data']['discount'];
}
// 调用最新上架
$recent = SearchData::recentShelve();
if (isset($discount['code']) && $discount['code'] === 200) {
$result['data']['filter']['recent'] = $recent['data']['recent'];
}
// 组织模板数据
$list = HelperSearch::getList($result, $options);
$data = array(
'productListPage' => true, //初始化js
//初始化js
'productListPage' => true,
'list' => $list
);
}else{
//接口异常,调用二级缓存
$data = array();
}
return $data;
}
... ... @@ -68,8 +74,6 @@ class SearchModel
*/
public static function getProductPic($product_sn, $options)
{
$data = array();
$condition['query'] = $product_sn;
$condition['query'] = $product_sn;
//返回搜索条件
$condition['needFilter'] = 0;
... ...
... ... @@ -81,7 +81,6 @@ class ListController extends WebAction
$params = $condition + $_GET;
$params = array_filter($params);
$data = SearchModel::getSearchData($params,$options);
// print_r($data); exit;
$cate = array('boys','girls','kids','lifestyle');
$this->setWebNavHeader($cate[$gender-1]);
$this->_view->display('list', $data);
... ...