原文地址:http://bbs.ecshop.com/viewthread.php?tid=115004&page=1
无奈做好事真难,删除图个安心
各位看官请考虑下我免费制作这个效果,并且好心写出教程,无奈网上小人总会以各种方式来说你做得不够,
本人不是来教基础知识的,连基本的模板选择都不会我怎么去教他们做这些功能,反而不教这些基础知识成为了我共享这个功能点的不对的地方。
喜欢这个特效的朋友,可以去下载站点查看:
http://www.belary.com/rpg
需要的朋友我只提供程序包,安装方法不再赘述了。
===重新更新帖子里,把以前的删掉了====
安装方法如下:
1. myget_promote_goods()这个函数拷贝到includes/lib_goods.php中
function myget_promote_goods($cats = '')
{
$time =
gmtime();
$order_type
= $GLOBALS['_CFG']['recommend_order'];
$num =
get_library_number("recommend_promotion");
$sql =
'SELECT g.goods_id, g.goods_name,
g.goods_number,g.goods_name_style, g.market_price, g.shop_price AS
org_price, g.promote_price, ' .
"IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS
shop_price, ".
"promote_start_date, promote_end_date, g.goods_brief,
g.goods_thumb, goods_img, b.brand_name, " .
"g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd "
.
'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g '
.
'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . '
AS b ON b.brand_id = g.brand_id ' .
"LEFT JOIN " .
$GLOBALS['ecs']->table('member_price') . " AS mp
".
"ON mp.goods_id = g.goods_id AND mp.user_rank =
'$_SESSION[user_rank]' ".
'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0
' .
" AND g.is_promote = 1 AND promote_start_date <=
'$time' AND promote_end_date >= '$time' ";
$sql .=
$order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : '
ORDER BY rnd';
$sql .= "
LIMIT $num ";
$result =
$GLOBALS['db']->getAll($sql);
$goods =
array();
foreach
($result AS $idx => $row)
{
if ($row['promote_price'] > 0)
{
$promote_price = bargain_price($row['promote_price'],
$row['promote_start_date'], $row['promote_end_date']);
$goods[$idx]['promote_price'] = $promote_price > 0 ?
price_format($promote_price) : '';
}
else
{
$goods[$idx]['promote_price'] = '';
}
$goods[$idx]['id']
= $row['goods_id'];
$goods[$idx]['name']
= $row['goods_name'];
$goods[$idx]['num']
= $row['goods_number'];
$goods[$idx]['brief']
= $row['goods_brief'];
$goods[$idx]['brand_name'] =
$row['brand_name'];
$goods[$idx]['goods_style_name']
= add_style($row['goods_name'],$row['goods_name_style']);
$goods[$idx]['short_name'] =
$GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length'])
: $row['goods_name'];
$goods[$idx]['short_style_name']
=
add_style($goods[$idx]['short_name'],$row['goods_name_style']);
$goods[$idx]['market_price'] =
price_format($row['market_price']);
$goods[$idx]['shop_price'] =
price_format($row['shop_price']);
$goods[$idx]['thumb']
= get_image_path($row['goods_id'], $row['goods_thumb'],
true);
$goods[$idx]['goods_img']
= get_image_path($row['goods_id'], $row['goods_img']);
$goods[$idx]['url']
= build_uri('goods', array('gid' =>
$row['goods_id']), $row['goods_name']);
//设置时间
if ($time >=
$row['promote_start_date'] && $time
<= $row['promote_end_date'])
{
$goods[$idx]['gmt_end_time'] =
$row['promote_end_date'];
}
else
{
$goods[$idx]['gmt_end_time'] =
0;
}
}
return
$goods;
}
<div class="right_box1_right"
>
<script>
var goodslist=[]
var time_id=[]
</script>
<div>
<h3>限时抢购</h3>
<!--{foreach from=$cats_promote_goods
item=promotion_goods name=lstgood}-->
<script type="text/javascript">
goodslist[goodslist.length] =
{$promotion_goods.gmt_end_time};
time_id[time_id.length]="TimeCounter_{$smarty.foreach.lstgood.index}"
</script>
<div
id="TimeCounter_{$smarty.foreach.lstgood.index}"
class="timeBox">{$lang.please_waiting}</div>
<div class="roduct_List_S3">
<ul>
<li class="first">
<dl>
<dt>
<a href="{$promotion_goods.url}"
target="_blank">
<img
src="{$promotion_goods.thumb}"/></a><img
class="q" src="http://misc.360buyimg.com/skin/df/i/icon_qiang.gif"/>
</dt>
<dd class="p_Name"><a
href="{$promotion_goods.url}"
target="_blank">{$promotion_goods.name|escape:html}<font
color="#ff0000"/></a></dd>
<dd
class="p_Price1">市场价:<em>{$promotion_goods.market_price}</em>
仅剩<strong>{$promotion_goods.num}</strong>件</dd></dd>
<dd
class="p_Price1">抢购价:<strong>{$promotion_goods.promote_price}</strong>
</dd>
</dl>
</li>
</div>
<!--{/foreach}-->
</div>
</div>
<SCRIPT
type="text/javascript">
<!--
function show_date_time_0()
{
setTimeout("show_date_time_0()", 1000);
for (var i=0,j=goodslist.length;i<j;i++)
{
today=new Date();
timeold=goodslist*1000 - today.getTime();
sectimeold=timeold/1000;
secondsold=Math.floor(sectimeold);
msPerDay=24*60*60*1000;
e_daysold=timeold/msPerDay;
daysold=Math.round(e_daysold);
e_hrsold=(e_daysold-daysold)*24;
hrsold=Math.floor(e_hrsold);
e_minsold=(e_hrsold-hrsold)*60;
minsold=Math.floor((e_hrsold-hrsold)*60);
seconds=Math.floor((e_minsold-minsold)*60);
if (daysold<0) {
document.getElementById_x(time_id).innerHTML="逾期,倒计时已经失效";
}
else {
if (daysold<10) {daysold="0"+daysold}
if (daysold<100) {daysold="0"+daysold}
if (hrsold<10 &&
hrsold >1) {hrsold="0"+hrsold}
if (hrsold<1) {hrsold="00"}
if (minsold<10) {minsold="0"+minsold}
if (seconds<10) {seconds="0"+seconds}
if (daysold<3) {
document.getElementById_x(time_id).innerHTML="<strong>"+daysold+"</strong>"+"天"+"<strong>"+hrsold+"</strong>"+"小时"+"<strong>"+minsold+"</strong>"+"分"+"<strong>"+seconds+"</strong>"+"秒";
}
else {
document.getElementById_x(time_id).innerHTML="<strong>"+daysold+"</strong>"+"天"+"<strong>"+hrsold+"</strong>"+"小时"+"<strong>"+minsold+"</strong>"+"分"+"<strong>"+seconds+"</strong>"+"秒";
}
}
}
}
setTimeout("show_date_time_0()", 100);
//-->
</SCRIPT>
3.在你需要显示倒计时的地方引用countdown_promote.lbi即可。 如下:
<!-- #BeginLibraryItem
"/library/countdown_promote.lbi"
--><!-- #EndLibraryItem
-->
并且在index.php中对模板变量进行赋值
- $smarty->assign('cats_promote_goods', myget_promote_goods($cat_id)); // 调用栏目限时抢购商品
4. 再次说明下,这个代码例子是基于我的模板上的每个模板的样式不同,需要自行调整。