ecshop首页调用限时抢购,京东限时抢购效果

2016-07-07 16:03 来源:www.chinab4c.com 作者:ecshop专家



最近按客户的需求开发京东新版模,遇到要在首页调用限时抢购,在百度找到了方法,但不全,要通过修改才能实现效,现整理分享出来,希望对大家有帮助。

1.打开根目录的includes文件夹下的lib_goods.php文件

找到:

  1. $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
复制代码

在他的下面添加

  1. $time = gmtime();
  2. if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date'])
  3. {
  4. $goods[$idx]['gmt_end_time'] = local_date('M d, Y H:i:s',$row['promote_end_date']);
  5. }
  6. else
  7. {
  8. $goods[$idx]['gmt_end_time'] = 0;

  9. }
复制代码



2.然后自己写一个qianggou.lbi的文件

例如:

  1. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  2. <!-- {if $promotion_goods} -->
  3. <script >
  4. var Tday = new Array();
  5. var daysms = 24 * 60 * 60 * 1000
  6. var hoursms = 60 * 60 * 1000
  7. var Secondms = 60 * 1000
  8. var microsecond = 1000
  9. var DifferHour = -1
  10. var DifferMinute = -1
  11. var DifferSecond = -1
  12. function clock(key)
  13. {
  14. var time = new Date()
  15. var hour = time.getHours()
  16. var minute = time.getMinutes()
  17. var second = time.getSeconds()
  18. var timevalue = ""+((hour > 12) ? hour-12:hour)
  19. timevalue +=((minute < 10) ? ":0":":")+minute
  20. timevalue +=((second < 10) ? ":0":":")+second
  21. timevalue +=((hour >12 ) ? " PM":" AM")
  22. var convertHour = DifferHour
  23. var convertMinute = DifferMinute
  24. var convertSecond = DifferSecond
  25. var Diffms = Tday[key].getTime() - time.getTime()
  26. DifferHour = Math.floor(Diffms / daysms)
  27. Diffms -= DifferHour * daysms
  28. DifferMinute = Math.floor(Diffms / hoursms)
  29. Diffms -= DifferMinute * hoursms
  30. DifferSecond = Math.floor(Diffms / Secondms)
  31. Diffms -= DifferSecond * Secondms
  32. var dSecs = Math.floor(Diffms / microsecond)

  33. if(convertHour != DifferHour) a="<b>"+DifferHour+"</b>天";
  34. if(convertMinute != DifferMinute) b="<b>"+DifferMinute+"</b>时";
  35. if(convertSecond != DifferSecond) c="<b>"+DifferSecond+"</b>分"
  36. d="<b>"+dSecs+"</b>秒"
  37. if (DifferHour>0) {a=a}
  38. else {a=''}
  39. document.getElementByIdx_x_x_x("leftTime"+key).innerHTML = a + b + c + d; //显示倒计时信息

  40. }
  41. </script>
  42. <div class="m m2" id="timed">
  43. <div class="mt">
  44. <h2>限时抢购</h2>
  45. <div class="extra"></div>
  46. </div>
  47. <div class="mc">
  48. <ul class="lh">
  49. <!--{foreach from=$promotion_goods key=key item=goods name=name}-->
  50. <!--{if $smarty.foreach.name.index <= 4}-->
  51. <li id="timed1" class="fore1"><div id="leftTime{$key}" class="countdown">剩余<b>00</b>小时<b>00</b>分<b>00</b>秒</div><div class="p-img ld"><a title="{$goods.name|escape:html}" target="_blank" href="{$goods.url}"><img width="130" height="130" alt="{$goods.name|escape:html}" data-img="1" src="{$goods.thumb}"/></a></div><div class="p-name"><a target="_blank" title="{$goods.name|escape:html}" href="{$goods.url}">{$goods.name|escape:html}</a><br>原价:<font style="text-decoration:line-through; color:#CCCCCC; font-size:12px;">{$goods.shop_price}</font></div><div class="p-price"><span>抢购价:</span><strong><!-- {if $goods.promote_price neq ""} -->
  52. {$goods.promote_price}
  53. <!-- {else}-->
  54. {$goods.shop_price}
  55. <!--{/if}--></strong></div> </li>
  56. <script>
  57. Tday[{$key}] = new Date("{$goods.gmt_end_time}");
  58. window.setInterval(function()
  59. {clock({$key});}, 1000);
  60. </script>
  61. <!--{/if}-->
  62. <!--{/foreach}-->
  63. </ul>
  64. </div>
  65. </div>
  66. <!-- {/if} -->
复制代码


在首页调用qianggou.lbi文件即可。

效果: http://www.ecshopx.com/mb/360buy2012/
ecshopx.jpg

回答:
代码写得挺详细,谢谢分享,不知楼主有没有测试通过呢。

我的时间,{$goods.gmt_end_time}输出来为空,页面上显示NAN,郁闷,调了好久,还是显示这个,无语

感谢分享,我正在找这个呢。

没用无效...

测试通过了吗?

都是经过测试才发上去来的,这里有演示:http://www.ecshopx.com/mb/360buy2012/

好技术~~~

感谢楼主的贡献

测试通过了吗?

如何調用到在你需要要顯示的地方?能說更清楚一點嗎?

顶一下啊! 二次开发还有很长的路要走

DDDDDDDDDDDDDDDDDDDDDD

楼主可以呀,我也弄这个呢

那个商品分类那里怎么弄?可以分享一下经验不?