ecshop中如何添加限时抢购功能可以看到一个倒计时

ecshop中如何添加限时抢购功能可以看到一个倒计时,第1张

ecshop中如何添加限时抢购功能可以看到一个倒计时

本文主要介绍如何在ecshop中添加限时抢购功能。你可以在页面上看到一个倒计时。下面是详细的实现步骤,适合所有新手朋友。

第1步:在后台admin/templates/goods_info.htm中找到大概164行至173行修改以下代码

复制代码代码如下:
<tr>
<tdclass="label"><labelfor="is_promote">
<inputtype="checkbox"id="is_promote_switch"name="is_promote_switch"{if$goods.is_promote}checked="checked"{/if}onclick="handlePromote(this.checked);"/>是否参加促销</label>
<selectname="is_promote"id="is_promote">
<optionvalue="">请选择</option>
<optionvalue="1"{if$goods.is_promoteeq1}selected="selected"{/if}>{$lang.lab_promote_price}</option>
<optionvalue="2"{if$goods.is_promoteeq2}selected="selected"{/if}>限时价:</option>
<optionvalue="3"{if$goods.is_promoteeq3}selected="selected"{/if}>秒杀价:</option>
</select>
</td>
<tdid="promote_3">
<inputtype="text"id="promote_1"name="promote_price"value="{$goods.promote_price}"size="20"/>
</td>
</tr>
<trid="promote_4">
<tdclass="label"id="promote_5">{$lang.lab_promote_date}</td>
<tdid="promote_6">
<inputname="promote_start_date"type="text"id="promote_start_date"size="15"value='{$goods.promote_start_date}'readonly="readonly"/><inputname="selbtn1"type="button"id="selbtn1"onclick="returnshowCalendar('promote_start_date','%Y-%m-%d%H:%M','24',false,'selbtn1');"value="{$lang.btn_select}"class="button"/>-<inputname="promote_end_date"type="text"id="promote_end_date"size="15"value='{$goods.promote_end_date}'readonly="readonly"/><inputname="selbtn2"type="button"id="selbtn2"onclick="returnshowCalendar('promote_end_date','%Y-%m-%d%H:%M','24',false,'selbtn2');"value="{$lang.btn_select}"class="button"/>
</td>
</tr>

并找到下面js代码中的onload=function()函数将里面的

复制代码代码如下:
handlePromote(document.forms['theForm'].elements['is_promote'].checked);

改为

复制代码代码如下:
handlePromote(document.forms['theForm'].elements['is_promote_switch'].checked);

第2步:把admin下的goods.php改一句话,注释部分为原先部分

复制代码代码如下:
//$is_promote=empty($promote_price)?0:1;
$is_promote=empty($promote_price)?0:$_POST['is_promote'];

第3步:找到admin/includes/lib_goods.php里的goods_list函数,将switch条件里的

复制代码代码如下:
case'is_promote':
$where.="ANDis_promote=1ANDpromote_price>0ANDpromote_start_date<='$today'ANDpromote_end_date>='$today'";
break;

改为

复制代码代码如下:
case'is_promote':
$where.="ANDis_promote>0ANDpromote_price>0ANDpromote_start_date<='$today'ANDpromote_end_date>='$today'";
break;

否则在后台商品列表页搜索功能中的推荐的特价不能用

第4步:在includes/lib_goods.php中添加一个函数方法

复制代码代码如下:
/**
*获得限时商品
*
*@accesspublic
*@returnarray
*/
functionget_time_goods($cats='')
{
$time=gmtime();
$order_type=$GLOBALS['_CFG']['recommend_order'];
/*取得限时lbi的数量限制*/
$num=get_library_number("recommend_promotion");
$sql='SELECTg.goods_id,g.goods_name,g.goods_name_style,g.market_price,g.shop_priceASorg_price,g.promote_price,'.
"IFNULL(mp.user_price,g.shop_price*'$_SESSION[discount]')ASshop_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()ASrnd".
'FROM'.$GLOBALS['ecs']->table('goods').'ASg'.
'LEFTJOIN'.$GLOBALS['ecs']->table('brand').'ASbONb.brand_id=g.brand_id'.
"LEFTJOIN".$GLOBALS['ecs']->table('member_price')."ASmp".
"ONmp.goods_id=g.goods_idANDmp.user_rank='$_SESSION[user_rank]'".
'WHEREg.is_on_sale=1ANDg.is_alone_sale=1ANDg.is_delete=0'.
"ANDg.is_promote=2ANDpromote_start_date<='$time'ANDpromote_end_date>='$time'";
$sql.=$order_type==0?'ORDERBYg.sort_order,g.last_updateDESC':'ORDERBYrnd';
$sql.="LIMIT$num";
$result=$GLOBALS['db']->getAll($sql);
$goods=array();
foreach($resultAS$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]['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']);
/*限时时间倒计时*/
$time=gmtime();
if($time>=$row['promote_start_date']&&$time<=$row['promote_end_date'])
{
$goods[$idx]['gmt_end_time']=local_date('Md,YH:i:s',$row['promote_end_date']);
}
else
{
$goods[$idx]['gmt_end_time']=0;
}
}
return$goods;
}

在index.php中加一句

复制代码代码如下:
$smarty->assign('time_goods',get_time_goods());//限时商品

第5步:在library中新建一个time_limit.lbi,代码如下

复制代码代码如下:
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8">
<!--{if$time_goods}-->
<script>
varTday=newArray();
vardaysms=24*60*60*1000
varhoursms=60*60*1000
varSecondms=60*1000
varmicrosecond=1000
varDifferHour=-1
varDifferMinute=-1
varDifferSecond=-1
functionclock(key)
{
vartime=newDate()
varhour=time.getHours()
varminute=time.getMinutes()
varsecond=time.getSeconds()
vartimevalue=""+((hour>12)?hour-12:hour)
timevalue+=((minute<10)?":0":":")+minute
timevalue+=((second<10)?":0":":")+second
timevalue+=((hour>12)?"PM":"AM")
varconvertHour=DifferHour
varconvertMinute=DifferMinute
varconvertSecond=DifferSecond
varDiffms=Tday[key].getTime()-time.getTime()
DifferHour=Math.floor(Diffms/daysms)
Diffms-=DifferHour*daysms
DifferMinute=Math.floor(Diffms/hoursms)
Diffms-=DifferMinute*hoursms
DifferSecond=Math.floor(Diffms/Secondms)
Diffms-=DifferSecond*Secondms
vardSecs=Math.floor(Diffms/microsecond)
if(convertHour!=DifferHour)a="<fontcolor=red>"+DifferHour+"</font>天";
if(convertMinute!=DifferMinute)b="<fontcolor=red>"+DifferMinute+"</font>时";
if(convertSecond!=DifferSecond)c="<fontcolor=red>"+DifferSecond+"</font>分"
d="<fontcolor=red>"+dSecs+"</font>秒"
if(DifferHour>0){a=a}
else{a=''}
document.getElementById("leftTime"+key).innerHTML=a+b+c+d;//显示倒计时信息
}
</script>
<divid="time_limit">
<divid="time_top">
<divid="time_title"><ahref="../search.php?intro=promotion"target="_blank">限时抢购</a></div>
<divid="time_btn">
<aclass="prev"href="javascript:;"></a>
<aclass="active"href="javascript:;"></a>
<!--{foreachfrom=$time_goodskey=keyitem=goodsname="promotion_foreach"}-->
{if($key+1)%5==0}
{ifcount($time_goods)!=$key+1}
<aclass="index"href="javascript:;"></a>
{/if}
{/if}
<!--{/foreach}-->
<aclass="next"href="javascript:;"></a>
</div>
</div>
<divid="time_nr">
<ul>
<li>
<!--{foreachfrom=$time_goodskey=keyitem=goodsname="promotion_foreach"}-->
<divclass="xsqg">
<divclass="xsqg_top"><ahref="{$goods.url}"target="_blank"><imgsrc="{$goods.thumb}"width="170"height="155"alt="{$goods.name|escape:html}"/></a></div>
<divclass="xsqg_cen"><ahref="{$goods.url}"target="_blank"title="{$goods.name|escape:html}">{$goods.short_name|escape:html}</a></div>
<divclass="xsqg_bot">
<divclass="te">{$goods.promote_price}</div>
<divclass="yuan">{$goods.market_price}</div>
<divclass="remain_time"><fontstyle="color:#666;">剩余</font><fontid="leftTime{$key}">{$lang.please_waiting}</font></div>
<script>
Tday[{$key}]=newDate("{$goods.gmt_end_time}");
window.setInterval(function(){clock({$key});},1000);
</script>
</div>
</div>
<!--{/foreach}-->
</li>
</ul>
</div>
</div>
<!--{/if}-->

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/772279.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-03
下一篇 2022-05-03

发表评论

登录后才能评论

评论列表(0条)

保存