新闻中心

最土团购商品按价格排序实现方法

作者 / 无忧主机 时间 2014-07-29 08:56:43

“小编我的网上商城商品的排序怎么全是乱的呢?”小编一看,原来是最土团购的程序,小编就立马恢复说最土团购想要按照商品价格排序是要收费的。这位朋友不干了,就连这么小的事情都要收费,这是要闹哪样啊!没辙,助人为乐的无忧小编又开始研究了,一是为了帮助朋友们省钱,二也是为了体验下修改的乐趣。确实,最土团购这个程序有点过分了,就连排序都要收费,简单商品按照价格排序不仅是为了方便查找,更是为了让用户有更好的体验乐趣,这时的小编又是红领巾附体,想要通过修改程序代码解决这个问题,小编想到的方法是通过前台带推断出后台代码的实现方法。要想实现按价格排序需要前台有链接,后台然后实现相应的功能即可。 前台代码:\include\template\team_multi.html 这个模板文件,因为我们是开启了首页显示多项团购显示,所以用点的这个team_multi.html这个模板 代码如下:   <div class="filter-by-group-title">按价格:</div> <div class="filter-by-group-id"> <ul class="cates"> <li <!--{if $selector_p == ''}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}">全部</a> </li> <li <!--{if $selector_p == 'p1'}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}&p=p1">10元以下</a> </li> <li <!--{if $selector_p == 'p2'}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}&p=p2">10-50元</a> </li> <li <!--{if $selector_p == 'p3'}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}&p=p3">50-100元</a> </li> <li <!--{if $selector_p == 'p4'}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}&p=p4">100-200元</a> </li> <li <!--{if $selector_p == 'p5'}--> class="current" <!--{/if}--> ><a href="?gid={$_GET['gid']}&areaid={$_GET['areaid']}&p=p5">200元以上</a> </li> </ul> </div> </div>   后台代码:\include\function\common.php index_get_team 函数 修改后的代码 代码如下: function index_get_team($city_id,$group_id=0,$p="") { global $INI; $multi = option_yes('indexmulti'); $city_id = abs(intval($city_id)); /* 是否首页多团,不是则返回当前城市 */ if (!$multi) return current_team($city_id); $now = time(); $size = abs(intval($INI['system']['indexteam'])); /* 侧栏团购数小于1,则返回当前城市数据 */ if ($size<=1) return current_team($city_id); switch ($p) { case "p1": $pp1="team_price < '10'"; $pp2=""; break; case "p2": $pp1="team_price > '10'"; $pp2="team_price < '50'"; break; case "p3": $pp1="team_price > '50'"; $pp2="team_price < '100'"; break; case "p4": $pp1="team_price > '100'"; $pp2="team_price < '200'"; break; case "p5": $pp1="team_price > '200'"; $pp2=""; break; default: $pp1=""; $pp2=""; } $oc = array( 'team_type' => 'normal', "begin_time < '{$now}'", "end_time > '{$now}'", ); if(!empty($pp1)){ array_push($oc,$pp1); } if(!empty($pp2)){ array_push($oc,$pp2); } if($group_id) $oc['group_id']=$group_id; /* 数据库匹配多个城市订单,前者按照多城市搜索,后者兼容旧字段city_id搜索 */ $oc[] = "(city_ids like '%@{$city_id}@%' or city_ids like '%@0@%') or (city_ids = '' and city_id in(0,{$city_id}))"; $teams = DB::LimitQuery('team', array( 'condition' => $oc, 'order' => 'ORDER BY `sort_order` DESC, `id` DESC', 'size' => $size, )); if(count($teams) == 1) return array_pop($teams); return $teams; } 需要在index.php页面中增加一个 $selector_p=$p=addslashes($_GET['p']);方面当前价格的高亮。 以上方法可行,大家快去试试吧,帮大家省钱了,邀请小编吃饭的要排队哦! 希望可以帮助各位站长朋友!

本文地址:https://www.51php.com/zueitu/15129.html

1
1
1
1
1
1
1

客户服务热线

0791-8623-3537

在线客服