ecshop首页推荐的分类也能倒计时

2009-11-16 09:32 来源:www.chinab4c.com 作者:ecshop专家

1:cat_goods.lbi中修改成以下
<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<div class="box">
 <div class="box_1">
  <h3><span><a href="{$goods_cat.url}" class="f6">{$goods_cat.name|escape:html}</a></span></h3>
    <div class="centerPadd">
    <div class="clearfix goodsBox" style="border:none;">
 <script>
var DifferHour = -1
var DifferMinute = -1
var DifferSecond = -1
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
 <!--{foreach from=$cat_goods item=goods key = key}-->
{if $goods.promote_end_date}
var Tday{$goods.id} = new Date("{$goods.promote_end_date}");//循环出结束时间
{/if}
{/foreach}
</script>
      <!--{foreach from=$cat_goods item=goods key=key}-->
   {if $goods.promote_end_date}
   <script>
   function clock{$goods.id}()//动态生成数组
  {  
   var time = new Date()
   var hour = time.getHours()
   var minute = time.getMinutes()
   var second = time.getSeconds()
   var timevalue = ""+((hour > 12) ? hour-12:hour)
   timevalue +=((minute < 10) ? ":0":":")+minute
   timevalue +=((second < 10) ? ":0":":")+second
   timevalue +=((hour >12 ) ? " PM":" AM")
   var convertHour = DifferHour
   var convertMinute = DifferMinute
   var convertSecond = DifferSecond
   var Diffms = Tday{$goods.id}.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
   var dSecs = Math.floor(Diffms / microsecond)
   
   if(convertHour != DifferHour) a="<font color=red>"+DifferHour+"</font>天";
   if(convertMinute != DifferMinute) b="<font color=red>"+DifferMinute+"</font>时";
   if(convertSecond != DifferSecond) c="<font color=red>"+DifferSecond+"</font>分"
     d="<font color=red>"+dSecs+"</font>秒"
   document.getElementById("leftTime{$goods.id}").innerHTML = "剩余:"+a + b + c + d; 
  
  setTimeout("clock{$goods.id}()",1000)
  
  
  }
   </script>
   {/if}
      <div class="goodsItem">
           <a href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.name|escape:html}" class="goodsimg" /></a><br />
           <p><a href="{$goods.url}" title="{$goods.name|escape:html}">{$goods.short_name|escape:html}</a>
<br>{if $goods.promote_end_date}<div id="leftTime{$goods.id}">数据加载..</div>{/if}</p>
           <!-- {if $goods.promote_price neq ""} -->
          <font class="shop_s">{$goods.promote_price}</font>
          <!-- {else}-->
          <font class="shop_s">{$goods.shop_price}</font>
          <!--{/if}-->
        </div>
      <!--{/foreach}-->
    </div>
    </div>
 </div>
</div>
<div class="blank5"></div>
<script>

    {foreach from=$cat_goods item=goods key=key}
  {if $goods.promote_end_date}
  clock{$goods.id}()
  {/if}
   {/foreach}
 
 

</script>


2:includes/lib_goods.php
assign_cat_goods()函数中
sql语句中增加g.promote_end_date,
数组中增加
$goods[$idx]['promote_end_date'] = local_date('Y/m/d H:i',$row['promote_end_date']);