function widget($args, $instance)
    {
        extract($args);
        global $wp_query, $xt;
        if ($xt->is_shops) {
            echo $before_widget;
            $xt_shops_param = $wp_query->query_vars['xt_param'];
            $xt_shops_param['page_size'] = absint($instance['count']);
            $results = xt_taobaoke_shops_search($xt_shops_param);
            if (is_wp_error($results)) {
                xt_api_error($results);
            } else {
                $shops = $results['shops'];
                $total = $results['total'];
                $filterType = 0;
                if ($xt_shops_param['only_mall']) {
                    $filterType = 1;
                } elseif ($xt_shops_param['start_credit'] == 16 && $xt_shops_param['end_credit'] == 20) {
                    $filterType = 2;
                } elseif ($xt_shops_param['start_credit'] == 11 && $xt_shops_param['end_credit'] == 15) {
                    $filterType = 3;
                }
                $page = $xt_shops_param['page_no'];
                $prev_url = $next_url = '';
                if ($page > 1) {
                    $prev_url = xt_get_shop_search_url(array_merge($xt_shops_param, array('page_no' => $page - 1)));
                }
                if ($page < $total) {
                    $next_url = xt_get_shop_search_url(array_merge($xt_shops_param, array('page_no' => $page + 1)));
                }
                $base = xt_get_shop_search_url(array_merge($xt_shops_param, array('page_no' => '%#%')));
                $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $xt_shops_param['page_size'], $total);
                $pager_bottom = xt_search_pager_bottom($base, $page, $xt_shops_param['page_size'], $total);
                echo '<div class="hd">';
                xt_output_breadcrumbs(true, array('name' => $total . '个店铺', 'url' => ''), false, $pager_top);
                echo '</div>';
                $isFanxian = xt_is_fanxian();
                $urlType = isset($instance['urlType']) ? $instance['urlType'] : 'direct';
                ?>
                    <div class="bd" style="padding-top: 10px;">
                        <div class="xt-filter-box xt-shop-filter form-inline">
                            <label>关键词:</label>
                            <input id="X_Shop-Filter-Keyword" type="text" class="input-small" value="<?php 
                echo esc_attr($xt_shops_param['keyword']);
                ?>
">
                            &nbsp;&nbsp;
                            <select id="X_Shop-Filter-Start-Credit" style="width:80px">
                                <option value="">等级</option>
                                <option value="1">一心</option>
                                <option value="2">两心</option>
                                <option value="3">三心</option>
                                <option value="4">四心</option>
                                <option value="5">五心</option>
                                <option value="6">一钻</option>
                                <option value="7">两钻</option>
                                <option value="8">三钻</option>
                                <option value="9">四钻</option>
                                <option value="10">五钻</option>
                                <option value="11">一皇冠</option>
                                <option value="12">两皇冠</option>
                                <option value="13">三皇冠</option>
                                <option value="14">四皇冠</option>
                                <option value="15">五皇冠</option>
                                <option value="16">一金冠</option>
                                <option value="17">两金冠</option>
                                <option value="18">三金冠</option>
                                <option value="19">四金冠</option>
                                <option value="20">五金冠</option>
                            </select>
                            &nbsp;&nbsp;--&nbsp;&nbsp;
                            <select id="X_Shop-Filter-End-Credit" style="width:80px">
                                <option value="">等级</option>
                                <option value="1">一心</option>
                                <option value="2">两心</option>
                                <option value="3">三心</option>
                                <option value="4">四心</option>
                                <option value="5">五心</option>
                                <option value="6">一钻</option>
                                <option value="7">两钻</option>
                                <option value="8">三钻</option>
                                <option value="9">四钻</option>
                                <option value="10">五钻</option>
                                <option value="11">一皇冠</option>
                                <option value="12">两皇冠</option>
                                <option value="13">三皇冠</option>
                                <option value="14">四皇冠</option>
                                <option value="15">五皇冠</option>
                                <option value="16">一金冠</option>
                                <option value="17">两金冠</option>
                                <option value="18">三金冠</option>
                                <option value="19">四金冠</option>
                                <option value="20">五金冠</option>
                            </select>
                            &nbsp;&nbsp;
                            <button id="X_Shop-Filter-Btn" class="btn btn-small btn-primary" data-url="<?php 
                echo xt_get_shop_search_url(array('keyword' => 'SEARCH', 'start_credit' => 'START', 'end_credit' => 'END'));
                ?>
" data-loading-text="搜索中...">搜索</button>
                        </div>
                        <div class="xt-filter-tab clearfix">
                            <ul>
                                <li class="<?php 
                echo $filterType == 0 ? 'active' : '';
                ?>
"><a href="<?php 
                echo xt_get_shop_search_url();
                ?>
">所有店铺</a></li>
                                <li class="<?php 
                echo $filterType == 1 ? 'active' : '';
                ?>
"><a href="<?php 
                echo xt_get_shop_search_url(array('cid' => $xt_shops_param['cid'], 'only_mall' => 1, 'keyword' => $xt_shops_param['keyword']));
                ?>
">天猫商城</a></li>
                                <li class="<?php 
                echo $filterType == 2 ? 'active' : '';
                ?>
"><a href="<?php 
                echo xt_get_shop_search_url(array('cid' => $xt_shops_param['cid'], 'start_credit' => 16, 'end_credit' => 20, 'keyword' => $xt_shops_param['keyword']));
                ?>
">至尊店铺</a></li>
                                <li class="xt-last <?php 
                echo $filterType == 3 ? 'active' : '';
                ?>
"><a href="<?php 
                echo xt_get_shop_search_url(array('cid' => $xt_shops_param['cid'], 'start_credit' => 11, 'end_credit' => 15, 'keyword' => $xt_shops_param['keyword']));
                ?>
">皇冠店铺</a></li>
                            </ul>
                        </div>
                        <div class="row-fluid clearfix">
                            <?php 
                foreach ($shops as $shop) {
                    $click_url = $shop->click_url;
                    if ($urlType == 'jump') {
                        $click_url = xt_jump_url(array('title' => $shop->shop_title, 'url' => $click_url));
                    }
                    ?>
                                <div class="span6">
                                    <div class="media">
                                        <div class="pull-left">
                                            <a rel="nofollow" data-type="1" data-sellerid="<?php 
                    echo $shop->user_id;
                    ?>
" data-rd="1" data-style="2" data-tmpl="140x190"></a>                                                    
                                        </div>
                                        <div class="media-body">
                                            <h5 class="media-heading"><a rel="nofollow" href="<?php 
                    echo $click_url;
                    ?>
" target="_blank"><?php 
                    echo $shop->shop_title;
                    ?>
</a></h5>
                                            <ul class="unstyled">
                                                <li>店铺掌柜:<?php 
                    echo $shop->seller_nick;
                    ?>
</li>
                                                <li>信用等级:<i class="rank seller-rank-<?php 
                    echo $shop->seller_credit;
                    ?>
"></i></li>
                                                <li>累计销量:<?php 
                    echo $shop->total_auction;
                    ?>
</li>
                                                <li>宝贝数量:<?php 
                    echo $shop->auction_count;
                    ?>
</li>
                                                <?php 
                    if ($isFanxian) {
                        ?>
<li>平均返现:<strong class="text-default"><?php 
                        echo $shop->commission_rate;
                        ?>
%</strong></li><?php 
                    }
                    ?>
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <?php 
                }
                ?>
                        </div>
                        <?php 
                if (!empty($pager_bottom)) {
                    echo '<div id="X_Pagination-Bottom" class="clearfix">';
                    echo '<div class="pagination pagination-large xt-pagination-links">';
                    echo $pager_bottom;
                    echo '</div>';
                    echo '</div>';
                }
                echo '</div>';
            }
            echo $after_widget;
            ?>
                    <script>
                        jQuery(function($){
                            $('#X_Shop-Filter-Start-Credit').val(<?php 
            echo $xt_shops_param['start_credit'];
            ?>
);
                            $('#X_Shop-Filter-End-Credit').val(<?php 
            echo $xt_shops_param['end_credit'];
            ?>
)
                            $('.xt-widget-system-shops .span6').hover(function(){
                                $(this).addClass('hover').siblings().removeClass('hover');
                            },function(){
                                $(this).removeClass('hover');
                            });
                            $('#X_Shop-Filter-Btn').click(function(){
                                var url = ($(this).attr('data-url'));
                                var self=$(this);
                                if(url){
                                    try{
                                        var keyword = $('#X_Shop-Filter-Keyword').val();
                                        var start_credit = $('#X_Shop-Filter-Start-Credit').val();
                                        var end_credit = $('#X_Shop-Filter-End-Credit').val();
                                        if(start_credit&&end_credit){
                                            if(parseInt(end_credit)<parseInt(start_credit)){
                                                alert('结束信用等级不能小于开始信用等级');
                                                return false;
                                            }
                                        }
                                        self.button('loading');
                                        url = url.replace('SEARCH',encodeURIComponent(keyword)).replace('START',start_credit).replace('END',end_credit);
                                        document.location.href = url;
                                    }catch(e){
                                        $(this).button('reset');
                                    }
                                }
                            });
                        })
                    </script>
                    <?php 
        }
    }
Example #2
0
function xt_widget_template_grid($args)
{
    global $wp_query;
    $default = array('breadcrumbs' => 0, 'pager_top' => '', 'pager_bottom' => '', 'total' => 0, 'size' => '', 'count' => '', 'title' => '', 'isHd' => true, 'type' => '', 'items' => array(), 'urlType' => 'direct', 'display' => array('title', 'price', 'volume', 'seller', 'discount'), 'params' => array());
    $args = array_merge($default, $args);
    extract($args);
    $rate = xt_get_rate();
    $span = 'span3';
    switch ($size) {
        case 'big':
            $span = 'span3';
            break;
        case 'normal':
            $span = 'span2-4';
            break;
        case 'small':
            $span = 'span2';
            break;
    }
    global $xt_current_widget;
    if ($xt_current_widget == 'systaobaos') {
        $breadcrumbs = 1;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['page_no'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_taobao_search_url(array_merge($params, array('page_no' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_taobao_search_url(array_merge($params, array('page_no' => $page + 1)));
        }
        $base = xt_get_taobao_search_url(array_merge($params, array('page_no' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total);
    } elseif ($xt_current_widget == 'syspaipais') {
        $breadcrumbs = 1;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['pageIndex'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_paipai_search_url(array_merge($params, array('pageIndex' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_paipai_search_url(array_merge($params, array('pageIndex' => $page + 1)));
        }
        $base = xt_get_paipai_search_url(array_merge($params, array('pageIndex' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total);
    } elseif ($xt_current_widget == 'sysbijias') {
        $breadcrumbs = 1;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['page_no'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_bijia_search_url(array_merge($params, array('page_no' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_bijia_search_url(array_merge($params, array('page_no' => $page + 1)));
        }
        $base = xt_get_bijia_search_url(array_merge($params, array('page_no' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total);
    } elseif ($xt_current_widget == 'systuans') {
        $breadcrumbs = 0;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['page_no'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_tuan_search_url(array_merge($params, array('page_no' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_tuan_search_url(array_merge($params, array('page_no' => $page + 1)));
        }
        $base = xt_get_tuan_search_url(array_merge($params, array('page_no' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total);
    } elseif ($xt_current_widget == 'systemais') {
        $breadcrumbs = 1;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['page_no'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_temai_search_url(array_merge($params, array('page_no' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_temai_search_url(array_merge($params, array('page_no' => $page + 1)));
        }
        $base = xt_get_temai_search_url(array_merge($params, array('page_no' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total, 100);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total, 100);
    } elseif ($xt_current_widget == 'syscoupons') {
        $breadcrumbs = 1;
        $params = $wp_query->query_vars['xt_param'];
        $page = $params['page_no'];
        $prev_url = $next_url = '';
        if ($page > 1) {
            $prev_url = xt_get_coupon_search_url(array_merge($params, array('page_no' => $page - 1)));
        }
        if ($page < $total) {
            $next_url = xt_get_coupon_search_url(array_merge($params, array('page_no' => $page + 1)));
        }
        $base = xt_get_coupon_search_url(array_merge($params, array('page_no' => '%#%')));
        $pager_top = xt_search_pager_top($prev_url, $next_url, $page, $count, $total);
        $pager_bottom = xt_search_pager_bottom($base, $page, $count, $total);
    }
    ?>
    <div class="shop-display">
        <div class="hd">
            <?php 
    if ($breadcrumbs) {
        xt_output_breadcrumbs(true, array('name' => $total . '件宝贝', 'url' => ''), false, $pager_top);
    } else {
        if ($xt_current_widget != 'systuans') {
            ?>
                    <h4 class="xt-bd-l" <?php 
            echo !empty($title) ? '' : 'style="display:none"';
            ?>
><span><?php 
            echo $title;
            ?>
</span></h4>
                    <?php 
        }
    }
    if ($xt_current_widget == 'syspaipais') {
        _xt_widget_template_grid_item_paipai_filter($params);
    } elseif ($xt_current_widget == 'sysbijias') {
        _xt_widget_template_grid_item_bijia_filter($params);
    } elseif ($xt_current_widget == 'systuans') {
        _xt_widget_template_grid_item_tuan_filter($params, $pager_top);
    } elseif ($xt_current_widget == 'systemais') {
        _xt_widget_template_grid_item_temai_filter($params, $pager_top);
    }
    ?>
        </div>
        <div class="bd">
            <?php 
    if (!empty($items)) {
        echo '<ul class="thumbnails thumbnails-' . $span . ' clearfix">';
        $_count = 0;
        if (empty($count)) {
            $count = count($items);
        }
        $fanxianText = '元';
        $platform = '';
        $isJifenbao = false;
        if ($type == 'taobao' || $type == 'coupon' || $type == 'temai') {
            $platform = 'taobao';
        } elseif ($type == 'paipai') {
            $platform = 'paipai';
        }
        if ($platform) {
            if (xt_fanxian_is_jifenbao($platform)) {
                $isJifenbao = true;
                $fanxianText = xt_jifenbao_text();
            }
        }
        foreach ($items as $item) {
            if ($_count >= $count) {
                break;
            }
            switch ($type) {
                case 'taobao':
                    xt_widget_template_grid_item_taobao($span, $rate, $item, $display, $isJifenbao, $fanxianText, $urlType);
                    break;
                case 'paipai':
                    xt_widget_template_grid_item_paipai($span, $rate, $item, $display, $isJifenbao, $fanxianText);
                    break;
                case 'share':
                    xt_widget_template_grid_item_share($span, $rate, $item, $display);
                    break;
                case 'coupon':
                    xt_widget_template_grid_item_coupon($span, $rate, $item, $display, $isJifenbao, $fanxianText, $urlType);
                    break;
                case 'temai':
                    xt_widget_template_grid_item_temai($span, $rate, $item, $display, $isJifenbao, $fanxianText, $urlType);
                    break;
                case 'bijia':
                    xt_widget_template_grid_item_bijia($span, $rate, $item, $display, $urlType);
                    break;
                case 'tuan':
                    xt_widget_template_grid_item_tuan($span, $rate, $item, $display, $urlType);
                    break;
            }
            $_count++;
        }
        echo '</ul>';
        if (!empty($pager_bottom)) {
            echo '<div id="X_Pagination-Bottom" class="clearfix">';
            echo '<div class="pagination pagination-large xt-pagination-links">';
            echo $pager_bottom;
            echo '</div>';
            echo '</div>';
        }
    } else {
        $msg = 'item_not_found';
        switch ($type) {
            case 'taobao':
                $msg = 'item_taobao_not_found';
                break;
            case 'paipai':
                $msg = 'item_paipai_not_found';
                break;
            case 'share':
                $msg = 'share_not_found';
                break;
            case 'coupon':
                $msg = 'item_coupon_not_found';
                break;
            case 'temai':
                $msg = 'item_temai_not_found';
                break;
            case 'bijia':
                $msg = 'item_bijia_not_found';
                break;
            case 'tuan':
                $msg = 'item_tuan_not_found';
                break;
        }
        echo xt_not_found($msg);
    }
    ?>
            <div class="clearfix"></div>
        </div>
    </div>			
    <?php 
}