首页限时抢购,效果不错。

2016-07-07 14:55 来源:www.chinab4c.com 作者:ecshop专家


  1. <!--主体内容右边-->
  2. <div class="gs_right">
  3. <div class="rit_1">
  4. <span class="rit_title"> <b>限时抢购</b><span id="tab_right_promo" style="margin-left: 5px; float: left; display: inline;"><a class="sel_promo_date" id="right_promo_1" onclick="swi_tab(&quot;right_promo&quot;,&quot;sel_promo_date&quot;,1,3)" target="_self" href="javascript:;">06.02</a></span></span>

  5. <ul class="qg_ul" id="right_promo_3_1">

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

  37. if(convertHour != DifferHour) a="剩余<font color=red>"+DifferHour+"</font>天";
  38. if(convertMinute != DifferMinute) b="<font color=red>"+DifferMinute+"</font>时";
  39. if(convertSecond != DifferSecond) c="<font color=red>"+DifferSecond+"</font>分"
  40. d="<font color=red>"+dSecs+"</font>秒"
  41. if (DifferHour>0) {a=a}
  42. else {a=''}
  43. document.getElementById("leftTime"+key).innerHTML = a + b + c + d; //显示倒计时信息

  44. }
  45. </script>
  46. <!--{foreach from=$index_promote_goods key=key item=goods name="promotion_foreach"}-->
  47. {if $smarty.foreach.promotion_foreach.index <= 5}
  48. <li class="no_border"><span class="date"><font id="leftTime{$key}">{$lang.please_waiting}</font></span>
  49. <a title="{$goods.name|escape:html}" target="_blank" href="{$goods.url}"><img src="{$goods.thumb}">{$goods.short_name|escape:html}</a>
  50. <em><span>市场价:</span><b class="hui">{$goods.shop_price}</b></em>
  51. <em><span> 抢购价:</span><b class="red">{$goods.promote_price}</b></em>
  52. <em><span>立省:</span><b class="green">{$goods.sy}</b></em>
  53. </li>

  54. {/if}
  55. <script>
  56. Tday[{$key}] = new Date("{$goods.gmt_end_time}");
  57. window.setInterval(function()
  58. {clock({$key});}, 1000);
  59. </script>
  60. <!--{/foreach}-->
  61. <!--{/if}-->
  62. </ul>
  63. </div><!--抢购-->
复制代码

在lib_goods.php
  1. /**
  2. * 首页促销倒计时商品
  3. *
  4. * @access public
  5. * @return array
  6. */
  7. function index_promote_goods($cats = '')
  8. {
  9. $time = gmtime();
  10. $order_type = $GLOBALS['_CFG']['recommend_order'];

  11. /* 取得促销lbi的数量** */
  12. $num = get_library_number("recommend_promotion");
  13. $sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' .
  14. "IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_price, ".
  15. "promote_start_date, promote_end_date, g.goods_brief, g.goods_thumb, goods_img, b.brand_name, " .
  16. "g.is_best, g.is_new, g.is_hot, g.is_promote, RAND() AS rnd " .
  17. 'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .
  18. 'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' .
  19. "LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp ".
  20. "ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".
  21. 'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' .
  22. " AND g.is_promote = 1 AND promote_start_date <= '$time' AND promote_end_date >= '$time' ";
  23. $sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd';
  24. $sql .= " LIMIT $num ";
  25. $result = $GLOBALS['db']->getAll($sql);

  26. $goods = array();
  27. foreach ($result AS $idx => $row)
  28. {
  29. if ($row['promote_price'] > 0)
  30. {
  31. $promote_price = bargain_price($row['promote_price'], $row['promote_start_date'], $row['promote_end_date']);
  32. $goods[$idx]['promote_price'] = $promote_price > 0 ? price_format($promote_price) : '';
  33. }
  34. else
  35. {
  36. $goods[$idx]['promote_price'] = '';
  37. }

  38. $goods[$idx]['id'] = $row['goods_id'];
  39. $goods[$idx]['name'] = $row['goods_name'];
  40. $goods[$idx]['brief'] = $row['goods_brief'];
  41. $goods[$idx]['brand_name'] = $row['brand_name'];
  42. $goods[$idx]['goods_style_name'] = add_style($row['goods_name'],$row['goods_name_style']);
  43. $goods[$idx]['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ? sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
  44. $goods[$idx]['short_style_name'] = add_style($goods[$idx]['short_name'],$row['goods_name_style']);
  45. $goods[$idx]['market_price'] = price_format($row['market_price']);
  46. $goods[$idx]['shop_price'] = price_format($row['shop_price']);
  47. $goods[$idx]['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);
  48. $goods[$idx]['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
  49. $goods[$idx]['url'] = build_uri('goods', array('gid' => $row['goods_id']), $row['goods_name']);
  50. $goods[$idx]['sy'] =price_format(ceil($row['shop_price']-$row['promote_price']));
  51. /* 促销时间倒计时 */
  52. $time = gmtime();
  53. if ($time >= $row['promote_start_date'] && $time <= $row['promote_end_date'])
  54. {
  55. $goods[$idx]['gmt_end_time'] = local_date('M d, Y H:i:s',$row['promote_end_date']);
  56. }
  57. else
  58. {
  59. $goods[$idx]['gmt_end_time'] = 0;
  60. }

  61. }

  62. return $goods;
  63. }
复制代码


如果不懂得,可以去QQ群咨询群号:129370737

回答:
这个可以有,支持~~

不错,拿走

好东西 拿走

路过 支持一下

多谢分享

嗯,实用的功能,感谢分享!