首页调用团购购买数量剩余时间【已解决】

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

此方法是参照网络上的修改方法,我也试了很多遍,一直都还是不行,处于:“请稍等,正在载入中…”现研究了好一会儿终于能够正常显示剩余时间,特把解决方法晒出来,帮助有着同样问题无处寻觅答案的童鞋们:

首先修改index.php中的代码:
/**
* 获得最新的团购活动
*
* @accessprivate
* @returnarray
*/


function index_get_group_buy()
{
$time = gmtime();
$limit = get_library_number('group_buy', 'index');
$group_buy_list = array();
if ($limit > 0)
{
$sql = 'SELECT gb.act_id AS group_buy_id, gb.goods_id, gb.ext_info, gb.goods_name, g.goods_thumb, g.goods_img,gb.end_time ' .
'FROM ' . $GLOBALS['ecs']->table('goods_activity') . ' AS gb, ' .
$GLOBALS['ecs']->table('goods') . ' AS g ' .
"WHERE gb.act_type = '" . GAT_GROUP_BUY . "' " .
"AND g.goods_id = gb.goods_id " .
"AND gb.start_time <= '" . $time . "' " .
"AND gb.end_time >= '" . $time . "' " .
"AND g.is_delete = 0 " .
"ORDER BY gb.act_id DESC " .
"LIMIT $limit" ;
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{

$row['goods_img'] = get_image_path($row['goods_id'], $row['goods_img']);
$row['thumb'] = get_image_path($row['goods_id'], $row['goods_thumb'], true);

$ext_info = unserialize($row['ext_info']);
$stat = group_buy_stat($row['group_buy_id'], $ext_info['deposit']);

$price_ladder = $ext_info['price_ladder'];
if (!is_array($price_ladder) || empty($price_ladder))
{
$row['last_price'] = price_format(0);
}
else
{
foreach ($price_ladder AS $amount_price)
{
$price_ladder[$amount_price['amount']] = $amount_price['price'];
}
}
ksort($price_ladder);
//$smarty->assign('now_time',gmtime());// 当前系统时间
$row['gmt_now_date']= $group_buy['end_date'];// 当前时间
//$row['gmt_now_date'] = format_time($row['end_date']);// 当前时间
$row['gmt_end_date'] = $row['end_time'];// 结束时间
$row['vn'] = $stat['valid_goods'];//调用团购信息产品购买人数
$row['last_price'] = price_format(end($price_ladder));
$row['url'] = build_uri('group_buy', array('gbid' => $row['group_buy_id']));
$row['short_name'] = $GLOBALS['_CFG']['goods_name_length'] > 0 ?
sub_str($row['goods_name'], $GLOBALS['_CFG']['goods_name_length']) : $row['goods_name'];
$row['short_style_name'] = add_style($row['short_name'],'');
$group_buy_list[] = $row;
}
}

return $group_buy_list;
}

library/group_buy.lbi

注意这里:原版的lefttime.js是定义的单个ID
<font id="leftTime" class="f1">这里循环了,ID重复一定报错。

这里怎么解决呢?你可以自己从JS文件夹里新复制一个lefttime.js这里我命名为:lefttime1.js;调用:<script type="text/javascript" src="js/lefttime1.js"></script>


<meta http-equiv="Content-Type" content="text/html; charset=gbk">
<script type="text/javascript" src="js/lefttime.js"></script>


<!-- {if $group_buy_goods} -->
<div class="box" style="border:1px solid #e2e2e2; width:198px;">
<h3><span>{$lang.group_buy_goods}</span></h3>
<div class="box_1" style="border:none;">
<div class="boxCenterList clearfix">
<!--{foreach from=$group_buy_goods item=goods}-->
<ul class="clearfix" style="position:relative;">
<li class="goodsimg" style="width:190px; height:190px; margin:0px;"><a style=" margin:0px;width:190px; height:190px;" href="{$goods.url}"><img src="{$goods.thumb}" alt="{$goods.goods_name|escape:html}" class="goodsimg" style=" margin:0;width:190px; height:190px;" /></a></li>
<li style="text-align:center; width:200px; overflow:hidden; font-size:14px; font-weight:bold;"><a href="{$goods.url}" title="{$goods.goods_name|escape:html}">{$goods.short_style_name|escape:html}</a></li>
<li style="width:100%;"><font class="shop_s">{$goods.last_price}</font></li>
<div class="index_group">售出 <strong>{$goods.vn}</strong> 件</div>
剩余时间:<span id="leftTime">结束时间:{$goods.gmt_end_date}</span>
</ul>
<!--{/foreach}-->
</div>

</div>
</div>
<div class="blank"></div>
<!-- {/if} -->

<script type="text/javascript">
var gmt_end_time = "{$goods.gmt_end_date|default:0}";
{foreach from=$lang.goods_js item=item key=key}
var {$key} = "{$item}";
{/foreach}
var now_time = "{$goods.gmt_now_date|default:0}";
<!-- {literal} -->

onload = function()
{
try
{
onload_leftTime();
}
catch (e)
{}
}
<!-- {/literal} -->
</script>