HelperSearch.php 30.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908
<?php

namespace Plugin;
use Plugin\Paging;
/**
 * 搜索辅助类
 */
class HelperSearch
{
    /**
     * 请求时用的所有参数
     */
    public static $params = array();

    //当前页
    public static $page = 1;

    /**
     * 选中的条件
     */
    public static $selected = array();

    /**
     * list分类面包屑
     * @var 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' => $cookieChannel
        );
        self::$listnav[1] = array(
            'href' => '',
            'name' => $initNav
        );
    }
    /**
     * 组织搜索模板数据
     * @param array $data
     * @param array $options
     * @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']);
        $filter = $data['data']['filter'];
        //产品列表
        $result['goods'] = self::getProductList($data['data']['product_list'], $options['imgSize']);
        //总页数
        $result['page_total'] = $data['data']['page_total'];
        //当前页
        $result['page'] = $data['data']['page'];
        self::$page = $result['page'];
        //清除选中
        $result['filters']['checkedConditions']['clearUrl'] = self::current();
        //频道
        $result['filters']['channel'] = self::gender($filter);
        //分类
        $result['filters']['sort'] = array();
        //品牌
        $result['filters']['brand'] = self::brand($filter, $options);
        //价格
        $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'] = ($next = self::next($data['data']['page_total'],$data['data']['filter'])) ? $next['href'] : '';
        $result['hasNextPage'] = self::next($data['data']['page_total']);
        //分类
        $result['leftContent'][]['allSort'] = isset($filter['group_sort']) ? self::groupSort($filter['group_sort'], $options) : array();
        //一周新品上架
        $result['leftContent'][]['newSales'] = isset($filter['recent']) ? self::recentShelve($filter['recent']) : array();
        //全部折扣
        $result['leftContent'][]['allDiscount'] = isset($filter['discount']) ? self::getDiscount($filter['discount']) : array();
        //总记录数
        $result['totalCount'] = $data['data']['total'];
        //分页
        $result['pager'] = self::pager($result['totalCount'],$options['viewNum']);
        //选中条件
        $result['filters']['checkedConditions']['conditions'] = self::getSelected();
        $result['pathNav'] = self::$listnav;
        return $result;
    }

    /**
     * TODO 组织商品列表信息
     * @param $product 接口返回商品列表
     * @author sefon 2015-12-21 17:24:04
     * @return array
     */
    public static function getProductList($product,$imgSize){
        $goods = array();
        foreach($product as $key => $val){
            //NEW
            $isNew = $val['is_new'] == 'Y' ? true : false;
            //限量商品
            $isLimit = isset($val['is_limited']) && $val['is_limited'] === 'Y';
            //即将售罄
            $isFew = $val['is_soon_sold_out'] === 'Y' ? true : false;
            //SALE
            //新品节
            //再到着
            //年终大促
            // 年中大促
            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]);
            }
            $goods[] = array(
                'tags' => array(
                    'isNew' => $isNew,
                    'isLimit' => $isLimit
                ),
                'url' => $goods_list[0]['url'],
                'thumb' => $val['default_images'],
                'name' => $val['product_name'],
                'salePrice' => $val['sales_price'],
                'marketPrice' => $val['market_price'],
                'isFew' => $isFew,
                'skn' => $val['product_skn']
            );
        }
        return $goods;
    }
    /**
     * 版型等其它筛选项
     * @param $filter
     * @return array
     */
    public static function standard($filter) {
        $params = self::$params;
        $result = array();
        foreach ($filter as $key => $val) {
            if (substr_compare($key, 'parameter', 0, 9) != 0) {
                continue;
            }
            if (!isset($val['sub']) || empty($val['sub'])) {
                continue;
            }
            $sub = array();
            foreach ($val['sub'] as $pval) {
                if (isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id']) {
                    $tmpParams = self::$params;
                    unset($tmpParams['parameter_' . $val['standard_id']]);
                    self::$selected['parameter_' . $val['standard_id']] = array(
                        'name' => $pval['standard_name'],
                        'href' => self::buildUrl($tmpParams)
                    );
                }
                $sub[] = array(
                    'name' => $pval['standard_name'],
                    'href' => self::buildUrl(array_merge($params, array(
                        'parameter_' . $val['standard_id'] => $pval['standard_id']
                    ))) ,
                    'selected' => isset(self::$params['parameter_' . $val['standard_id']]) && self::$params['parameter_' . $val['standard_id']] == $pval['standard_id'] ? true : false
                );
            }
            if (!empty($sub) && count($sub) > 1) {
                $result[] = array(
                    'name' => $val['standard_name'],
                    'sub' => $sub
                );
            }
        }
        return $result;
    }

    /**
     * 性别
     * @return array
     */
    public static function gender($filter) {
        if (empty($filter) || !isset($filter['gender']) || empty($filter['gender'])) {
            return array();
        }
        $params = self::$params;
        $gender = isset($params['gender']) ? $params['gender'] : '';
        if (isset($params['gender'])) {
            unset($params['gender']);
        }
        //设置选中
        if ($gender == '1,3' || $gender == '2,3') {
            self::$selected['gender'] = array(
                'name' => $gender == '1,3' ? 'BOYS' : 'GIRLS',
                'href' => self::buildUrl($params)
            );
        }
        $result = array();
        foreach ($filter['gender'] as $key => $val) {
            $result[] = array(
                'name' => $val,
                'href' => self::buildUrl(array_merge($params, array(
                    'gender' => $key
                ))) ,
            );
        }
        return $result;
    }

    /**
     * 组织搜索列表页面的左侧分类
     * @param array $sort
     * @param array $option
     * @return array
     */

    public static function groupSort($sort, $option = array())
    {
        //设置导航
        self::setListNav($option);
        $params = self::$params;
        $result = array(
            'all' => array(
                'name' => '全部品类',
                'href' => self::buildUrl() ,
                'active' => isset($params['msort']) ? false : true,
            ) ,
            'list' => array()
        );
        $sortList = array();
        foreach ($sort as $key => $val) {
            //若参数有分类,设置导航
            if (isset($params['msort']) && $params['msort'] == $val['sort_id']) {
                //是否有品牌
                $navIndex = isset($option['brandName']) && $option['brandName'] ? 2 : 1;
                self::$listnav[$navIndex] = array(
                    'name' => $val['sort_name'],
                    'href' => self::buildUrl(array(
                        'msort' => $val['sort_id'],
                    ))
                );
            }
            unset($params['msort']);
            unset($params['misort']);
            $sortList[$key]['name'] = $val['sort_name'];
            $sortList[$key]['active'] = isset(self::$params['msort']) && self::$params['msort'] == $val['sort_id'] ? true : false;
            $sortList[$key]['childList'][] = array(
                'name' => '全部分类',
                'href' => self::buildUrl(array_merge($params, array('msort'=>$val['sort_id'])))
            );
            if (isset($val['sub']) && !empty($val['sub'])) {
                foreach ($val['sub'] as $k => $v) {
                    $sortList[$key]['childList'][$k+1]['name'] = $v['sort_name'];
                    $sortList[$key]['childList'][$k+1]['href'] = self::buildUrl(array_merge($params, array('msort' => $val['sort_id'], 'misort' => $v['sort_id'])));
                    $sortList[$key]['childList'][$k+1]['childActive'] = isset(self::$params['misort']) && self::$params['misort'] == $v['sort_id'] ? true : false;
                }
            }
        }
        $result['list'] = $sortList;
        return $result;
    }

    /**
     * 品牌,可以多选
     * @param array $filter
     * @param array $options
     * @return array
     */
    public static function brand($filter, $options = array()) {
        //品牌列表返回空
        if (isset($options['brandName'])) {
            return array();
        }
        $result = array(
            'default' => array() ,
            'brandIndex' => array(
                '0~9',
                'A~G',
                'H~N',
                'O~T',
                'U~Z') ,
            'brandsShow' => array()
        );
        $params = self::$params;
        //url中的品牌ids
        $brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
        if (isset($filter['brand']) && !empty($filter['brand'])) {
            $brand = $filter['brand'];
            foreach ($brand as $key => $v) {
                $selectBrandIds = $brandIds;
                //品牌id在提交的参数中,构造url参数去除该品牌id
                if (in_array($v['id'], $brandIds)) {
                    $filterKey = array_search($v['id'], $selectBrandIds);
                    unset($selectBrandIds[$filterKey]);
                    $url = self::buildUrl(array_merge($params, array(
                        'brand' => implode(',', $selectBrandIds)
                    )));
                }
                //该品牌url参数中添加该品牌的id
                else {
                    $selectBrandIds[] = $v['id'];
                    $url = self::buildUrl(array_merge($params, array(
                        'brand' => implode(',', $selectBrandIds)
                    )));
                }
                $this_brand = array(
                    'brand_id' => $v['id'],
                    'name' => $v['brand_name'],
                    'alif' => $v['brand_alif'],
                    'href' => $url,
                    'active' => in_array($v['id'], $brandIds) ? true : false
                );
                //默认品牌
                if (count($result['default']) < 10) {
                    $result['default'][] = $this_brand;
                }
               //品牌列表
                $brandList[$v['brand_alif']][] = $this_brand;
                $brandAll[$v['id']] = $v['brand_name'];
            }
            //清空品牌参数
            unset($params['brand']);
            //设置已选中的品牌
            foreach ($brandIds as $key => $val) {
                $brandParam = $brandIds;
                unset($brandParam[$key]);
                $params['brand'] = implode(',', $brandParam);
                self::$selected['brand'][] = array(
                    'name' => $brandAll[$val],
                    'href' => self::buildUrl($params)
                );
            }
            //品牌列表排序
            ksort($brandList);
            foreach ($brandList as $key => $val) {
                if (is_array($val)) {
                    foreach ($val as $v) {
                        $result['brandsShow'][] = $v;
                     }
                }
            }
            unset($brandList);
        }
        return $result;
    }
    /**
     * 尺码的链接,不能多选
     * @param array $filter
     * @return array
     */
    public static function size($filter) {
        $params = self::$params;
        $sizeId = isset($params['size']) && !empty($params['size']) ? $params['size'] : '';
        if (isset($params['size'])) {
            unset($params['size']);
        }
        $result = array();
        if (isset($filter['size']) && !empty($filter['size'])) {
            $size = $filter['size'];
            foreach ($size as $v) {
                //设置选中
                if ($v['size_id'] == $sizeId) {
                    self::$selected['size'] = array(
                        'name' => $v['size_name'],
                        'href' => self::buildUrl($params)
                    );
                }
                $result[] = array(
                    'name' => $v['size_name'],
                    'href' => self::buildUrl(array_merge($params, array(
                        'size' => $v['size_id']
                    ))) ,
                );
            }
        }
        return $result;
    }

    /**
     * 颜色,不能多选
     * @param array $filter
     * @return array
     */
    public static function color($filter) {
        $params = self::$params;
        $colorId = isset($params['color']) && !empty(self::$params['color']) ? self::$params['color'] : '';
        if (isset($params['color'])) {
            unset($params['color']);
        }
        $result = array();
        $color = $filter['color'];
        foreach ($color as $v) {
            //设置已选中
            if ($v['color_id'] == $colorId) {
                $background = empty($v['color_value']) ? '#' . $v['color_code'] : "url(" . $v['color_value'] . ")";
                self::$selected['color'] = array(
                    'color' =>  $background,
                    'href' => self::buildUrl($params)
                );
            }
            $result[] = array(
                'name' => $v['color_name'],
                'rgb' => empty($v['color_value']) ? '#' . $v['color_code'] : "url({$v['color_value']})",
                'href' => self::buildUrl(array_merge($params, array(
                    'color' => $v['color_id']
                ))) ,
            );
        }
        return $result;
    }

    /**
     * 获取价格,不能多选
     * @param array $filter
     * @return array
     */
    public static function price($filter) {
        $params = self::$params;
        $priceId = isset($params['price']) && !empty(self::$params['price']) ? self::$params['price'] : '';
        if (isset($params['price'])) {
            unset($params['price']);
        }
        $result = array();
        //设置已选中价格
        if (!empty($priceId) && isset($filter['price'][$priceId])) {
            self::$selected['price'] = array(
                'name' => $filter['price'][$priceId],
                'href' => self::buildUrl($params)
            );
        }
        //返回价格条件
        foreach ($filter['price'] as $key => $val) {
            $val = trim($val,'¥');
            $result[] = array(
                'name' => $val,
                'href' => self::buildUrl(array_merge($params, array(
                    'price' => $key
                ))) ,
            );
        }
        return $result;
    }

    /**
     * 风格,可以多选
     * @param array $filter
     * @return array
     */
    public static function style($filter) {
        $params = self::$params;
        $styleIds = isset($params['style']) && !empty($params['style']) ? explode(',', $params['style']) : array();
        if (isset($params['style'])) {
            unset($params['style']);
        }
        $result = array();
        $style = $filter['style'];
        foreach ($style as $v) {
            //选中的筛选条件
            if (in_array($v['style_id'], $styleIds)) {
                $selectedStyle = explode(',', self::$params['style']);
                $selectedKey = array_search($v['style_id'], $selectedStyle);
                unset($selectedStyle[$selectedKey]);
                $selectedParams = $params;
                $selectedParams['style'] = implode(',', $selectedStyle);
                self::$selected['style'][] = array(
                    'name' => $v['style_name'],
                    'href' => self::buildUrl($selectedParams)
                );
            }
            $selectedStyle = isset(self::$params['style']) && !empty(self::$params['style']) ? explode(',', self::$params['style']) : array();
            //风格id在提交的参数中,构造url参数去除该风格id
            if (in_array($v['style_id'], $selectedStyle)) {
                $filterKey = array_search($v['style_id'], $selectedStyle);
                unset($selectedStyle[$filterKey]);
                $url = self::buildUrl(array_merge($params, array(
                    'style' => implode(',', $selectedStyle)
                )));
            }
            //该风格url参数中添加该风格的id
            else {
                $selectedStyle[] = $v['style_id'];
                $url = self::buildUrl(array_merge($params, array(
                    'style' => implode(',', $selectedStyle)
                )));
            }
            $result[] = array(
                'id' => $v['style_id'],
                'name' => $v['style_name'],
                'href' => $url,
            );
        }
        $data[0] = array(
            'attr' => 'style',
            'name' => '风格',
            'showMulti' => true,
            'sub' => $result
        );
        return $data;
    }
    /**
     * 高级选项
     */
    public static function seniorChose($filter)
    {
        $style = self::style($filter);
        $other = self::standard($filter);
        $result = array_merge($style,$other);
        return $result;
    }

    /**
     *  每页显示数量
     */
    public static function viewNum()
    {
        $params = self::$params;
        $viewNum = array(60, 100, 200);
        $result = array();
        foreach ($viewNum as $value) {
            $params['viewNum'] = $value;
            $params['page'] = 1;
            $result[] = array(
                'count' => $value,
                'href' => self::buildUrl($params)
            );
        }
        return $result;
    }

    /**
     *  显示行数
     */
    public static function rowNum($num = 5)
    {
        $params = self::$params;
        $params['rowNum'] = $num;
        return self::buildUrl($params);
    }

    /**
     * 是否特价
     */
    public static function specialoffer()
    {
        $selected = '';
        $params = self::$params;
        if (isset($params['specialoffer']) && !empty($params['specialoffer'])) {
            unset($params['specialoffer']);
            $selected = true;
        }
        else {
            $params['specialoffer'] = 1;
        }
        return array(
            'name' => '打折',
            'href' => self::buildUrl($params) ,
            'checked' => $selected
        );
    }

    /**
     * 是否限量
     */
    public static function limited()
    {
        $selected = '';
        $params = self::$params;
        if (isset($params['limited']) && !empty($params['limited'])) {
            unset($params['limited']);
            $selected = true;
        }
        else {
            $params['limited'] = 'Y';
        }
        return array(
            'name' => '限量',
            'href' => self::buildUrl($params) ,
            'checked' => $selected
        );
    }

    /**
     * 是否新品
     */
    public static function isnew()
    {
        $params = self::$params;
        $selected = '';
        if (isset($params['isNew']) && !empty($params['isNew'])) {
            unset($params['isNew']);
            $selected = true;
        }
        else {
            $params['isNew'] = 'Y';
        }
        return array(
            'name' => '新品',
            'href' => self::buildUrl($params) ,
            'checked' => $selected
        );
    }

    /**
     *  排序是否最新
     */
    public static function orderTime()
    {
        $params = self::$params;
        if (isset($params['order'])) {
            unset($params['order']);
        }
        $result = array(
            'name' => '最新',
            'href' => isset(self::$params['order']) && self::$params['order'] == 's_t_desc' ? self::buildUrl($params) : self::buildUrl(array_merge($params, array(
                'order' => 's_t_asc'
            ))) ,
            'active' => isset(self::$params['order']) && self::$params['order'] == 's_t_asc' ? true : ''
        );
        return $result;
    }

    /**
     *  排序是否默认
     */
    public static function orderDefault()
    {
        $params = self::$params;
        if (isset($params['order'])) {
            unset($params['order']);
        }
        $result = array(
            'name' => '默认',
            'href' => self::buildUrl($params) ,
            'active' => !isset(self::$params['order']) || empty(self::$params['order']) ? true : ''
        );
        return $result;
    }

    /**
     *  价格排序
     */
    public static function orderPrice()
    {
        $params = self::$params;
        if (isset($params['order'])) {
            unset($params['order']);
        }
        if (!isset(self::$params['order']) || empty(self::$params['order']) || !in_array(self::$params['order'], array(
                's_p_asc',
                's_p_desc'
            ))) {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 's_p_asc'
            )));
            $active = '';
            $desc = true;
        }
        else if (self::$params['order'] == 's_p_asc') {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 's_p_desc'
            )));
            $active = true;
            $desc = true;

        }
        else {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 's_p_asc'
            )));
            $desc = '';
            $active = '';
        }
        $result = array(
            'name' => '价格',
            'href' => $url,
            'hasSortOrient' => true,
            'active' => $active,
            'desc' => $desc
        );
        return $result;
    }

    /**
     *  折扣排序
     */
    public static function orderDiscount()
    {
        $params = self::$params;
        if (isset($params['order'])) {
            unset($params['order']);
        }
        if (!isset(self::$params['order']) || empty(self::$params['order']) || !in_array(self::$params['order'], array(
                'p_d_asc',
                'p_d_desc'
            ))) {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 'p_d_asc'
            )));
            $asc = '';
            $desc = '';
        }
        else if (self::$params['order'] == 'p_d_asc') {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 'p_d_desc'
            )));
            $asc = true;
            $desc = '';
        }
        else {
            $url = self::buildUrl(array_merge($params, array(
                'order' => 'p_d_asc'
            )));
            $asc = '';
            $desc = true;
        }
        $result = array(
            'name' => '折扣',
            'hasSortOrient' => true,
            'href' => $url,
            'asc' => $asc,
            'desc' => $desc
        );

        return $result;
    }

    /**
     * 组织参数
     * @param array $params
     * @return string
     */
    private static function buildUrl($params = array())
    {
        if (empty($params)) {
            return self::current();
        }
        $queryPath = explode('?', $_SERVER['REQUEST_URI']);
        $params_arr = array();
        foreach ($params as $key => $val) {
            if (is_array($val) || $val === '') {
                continue;
            }
            $params_arr[] = $key . '=' . $val;
        }
        if (empty($params_arr)) {
            return self::current();
        }
        else {
            return (empty($queryPath[0]) ? '/' : $queryPath[0]) . '?' . implode('&', $params_arr);
        }
    }

    /**
     * 获取选中的条件
     */
    public static function getSelected()
    {
        $result = array();
        $is_array_key = array(
            'brand',
            'style'
        );
        foreach (self::$selected as $key => $val) {
            if (in_array($key, $is_array_key)) {
                foreach ($val as $k => $v) {
                    $result[] = $v;
                }
            }
            else {
                $result[] = $val;
            }
        }
        return $result;
    }

    /**
     * 打折区间
     * @param array $list
     * @return array
     */
    public static function getDiscount(array $list = array())
    {
        $params = self::$params;
        if (empty($list)) {
            return array();
        }
        $query = array();
        $total = 0;
        foreach ($list as $k => $v) {
            $total += $v['count'];
            $query['p_d'] = $k;
            $list[$k]['href'] = self::buildUrl($query);
            $list[$k]['active'] = isset($params['p_d']) && $params['p_d'] == $k ? true : false;
        }
        $result = array(
            'list' => array_values($list)
        );
        return $result;
    }

    /**
     * 最新上架
     */
    public static function recentShelve($list = array())
    {
        if (empty($list)) {
            return array();
        }
        $params = self::$params;
        $query = array();
        $data = array();
        $i = 0;
        foreach ($list as $k => $v) {
            $star_time = strtotime($k);
            $end_time = $star_time+60*60*24;
            $query['shelve_time'] = '';
            $query['shelve_time'] = $star_time.','.$end_time;
            if (isset($params['shelve_time']) && $query['shelve_time'] == $params['shelve_time']) {
                $data[$i]['active'] = true;
            }
            $data[$i]['href'] = self::buildUrl($query);
            $data[$i]['name'] = $k;
            $i++;
        }
        $result = array(
            //'updateNum' => $total,
            'list' => $data
        );
        unset($data);
        unset($query);
        return $result;
    }
    /**
     * 当前页地址
     */
    public static function current(){
        $url =  explode('?', $_SERVER['REQUEST_URI']);
        self::$listnav[0]['href'] = $url[0];
        return $url[0];
    }
    /**
     * 下一页
     */
    public static function next($total){
        $param = self::$params;
        $page = self::$page;
        $next = array();
        if ($page < $total) {
            $page ++;
            $param['page'] = $page;
            $nextUrl = self::buildUrl($param);
            $next = array(
                'href' => $nextUrl,
                'src' => 'http://img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'
            );
        }
        return $next;
    }

    /**
     * 组织产品的图片
     * @param $product
     * @param $options
     * @return array
     */
    public static function getProductPic($product, $options)
    {
        $result = array();
        if (isset($product[0]['goods_list']) && !empty($product[0]['goods_list'])){
            foreach ($product[0]['goods_list'] as $key => $val){
                $result[$key]['coverImg'] = Images::getImageUrl($val['images_url'], $options['imgSize'][0], $options['imgSize'][1]);
                $result[$key]['url'] = Helpers::getUrlBySkc($product[0]['product_id'], $val['goods_id'], $product[0]['cn_alphabet']);
                $result[$key]['src'] = Images::getImageUrl($val['images_url'], $options['imgSize'][0], $options['imgSize'][1]);
            }
        }
        return $result;
    }
    //分页
    public static function pager($total,$viewNum){
        $Paging = new Paging('Yoho');
        return $Paging->setTotal($total)->setSize($viewNum)->view(0);
    }
}