抢购插件 精仿京东商城限时抢购插件
抢购插件+精仿京东商城限时抢购插件2010年11月30日17:24安装方法如下:
1.myget_promote_goods()这个函数拷贝到includes/lib_goods.php中
/*
*获得指定分类促销商品,带倒计时信息
*
*@access public
*@return array
*/
function myget_promote_goods($cats='')
{
$time=gmtime();
$order_type=$GLOBALS['_CFG']['recommend_order'];
/*取得促销lbi的数量限制*/
$num=get_library_number("recommend_promotion");
$sql='SELECT
g.goods_id,g.goods_name,g.goods_number,g.goods_name_style,g.market_pr
ice,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 bON 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;
}
复制代码
2.新建一个文本文档名称为countdown_promote.lbi保存到library文件
目录下内如如下:
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 ahref="{$promotion_goods.url}"target="_blank"
img src="{$promotion_goods.thumb}"//a img class="q"src="
/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(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(time_id).innerHTML="strong"+daysold+"/str
ong"+"天"+"strong"+hrsold+"/strong"+"小时
"+"strong"+minsold+"/strong"+"分"+"strong"+seconds+"/strong"+"秒";
}
else{
document.getElementById(time_id).innerHTML="strong"+daysold+"/str
ong"+"天"+"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));//调用栏目限时抢购商品
复制代码