ecshop 中添加限时抢购功能(倒计时)
第1步:在后台admin / templates / goods_info.htm中找到大概164行至173行修改以下代码
<tr><td class="label"><label for="is_promote">
<input type="checkbox" id="is_promote_switch" name="is_promote_switch" {if $goods.is_promote}checked="checked"{/if} οnclick="handlePromote(this.checked);" /> 是否参加促销</label><select name="is_promote" id="is_promote"><option value="" >请选择</option><option value="1" {if $goods.is_promote eq 1}selected="selected"{/if}>{$lang.lab_promote_price}</option><option value="2" {if $goods.is_promote eq 2}selected="selected"{/if}>限时价:</option><option value="3" {if $goods.is_promote eq 3}selected="selected"{/if}>秒杀价:</option></select></td><td id="promote_3">
<input type="text" id="promote_1" name="promote_price" value="{$goods.promote_price}" size="20" />
</td></tr><tr id="promote_4"><td class="label" id="promote_5">{$lang.lab_promote_date}</td><td id="promote_6"><input name="promote_start_date" type="text" id="promote_start_date" size="15" value='{$goods.promote_start_date}' readonly="readonly" /><input name="selbtn1" type="button" id="selbtn1" οnclick="return showCalendar('promote_start_date', '%Y-%m-%d %H:%M','24', false, 'selbtn1');" value="{$lang.btn_select}" class="button"/> - <input name="promote_end_date" type="text" id="promote_end_date" size="15" value='{$goods.promote_end_date}' readonly="readonly" /><input name="selbtn2" type="button" id="selbtn2" οnclick="return showCalendar('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 .= " AND is_promote = 1 AND promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today'";break;
改为
case 'is_promote':$where .= " AND is_promote > 0 AND promote_price > 0 AND promote_start_date <= '$today' AND promote_end_date >= '$today'";break;
否则在后台商品列表页搜索功能中的推荐的特价不能用
第4步:在includes / lib_goods.php中添加一个函数方法
/*** 获得限时商品** @access public* @return array*/
function get_time_goods($cats = '')
{$time = gmtime();$order_type = $GLOBALS['_CFG']['recommend_order'];/* 取得限时lbi的数量限制 */$num = get_library_number("recommend_promotion");$sql = 'SELECT g.goods_id, g.goods_name, g.goods_name_style, g.market_price, g.shop_price AS org_price, g.promote_price, ' ."IFNULL(mp.user_price, g.shop_price * '$_SESSION[discount]') AS shop_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() AS rnd " .'FROM ' . $GLOBALS['ecs']->table('goods') . ' AS g ' .'LEFT JOIN ' . $GLOBALS['ecs']->table('brand') . ' AS b ON b.brand_id = g.brand_id ' ."LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp "."ON mp.goods_id = g.goods_id AND mp.user_rank = '$_SESSION[user_rank]' ".'WHERE g.is_on_sale = 1 AND g.is_alone_sale = 1 AND g.is_delete = 0 ' ." AND g.is_promote = 2 AND promote_start_date <= '$time' AND promote_end_date >= '$time' ";$sql .= $order_type == 0 ? ' ORDER BY g.sort_order, g.last_update DESC' : ' ORDER BY rnd';$sql .= " LIMIT $num ";$result = $GLOBALS['db']->getAll($sql);$goods = array();foreach ($result AS $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('M d, Y H: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,代码如下
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- {if $time_goods} -->
<script >
var Tday = new Array();
var daysms = 24 * 60 * 60 * 1000
var hoursms = 60 * 60 * 1000
var Secondms = 60 * 1000
var microsecond = 1000
var DifferHour = -1
var DifferMinute = -1
var DifferSecond = -1
function clock(key){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":":")+minutetimevalue +=((second < 10) ? ":0":":")+secondtimevalue +=((hour >12 ) ? " PM":" AM")var convertHour = DifferHourvar convertMinute = DifferMinutevar convertSecond = DifferSecondvar Diffms = Tday[key].getTime() - time.getTime()DifferHour = Math.floor(Diffms / daysms)Diffms -= DifferHour * daysmsDifferMinute = Math.floor(Diffms / hoursms)Diffms -= DifferMinute * hoursmsDifferSecond = Math.floor(Diffms / Secondms)Diffms -= DifferSecond * Secondmsvar 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>秒"if (DifferHour>0) {a=a} else {a=''}document.getElementById("leftTime"+key).innerHTML = a + b + c + d; //显示倒计时信息}
</script>
<div id="time_limit"><div id="time_top"><div id="time_title"><a href="../search.php?intro=promotion" target="_blank">限时抢购</a></div><div id="time_btn"><a class="prev" href="javascript:;"></a> <a class="active" href="javascript:;"></a><!--{foreach from=$time_goods key=key item=goods name="promotion_foreach"}-->{if ($key+1)%5==0}{if count($time_goods)!=$key+1}<a class="index" href="javascript:;"></a>{/if}{/if}<!--{/foreach}--> <a class="next" href="javascript:;"></a></div></div><div id="time_nr"><ul><li><!--{foreach from=$time_goods key=key item=goods name="promotion_foreach"}--><div class="xsqg"><div class="xsqg_top"><a href="{$goods.url}" target="_blank"><img src="{$goods.thumb}" width="170" height="155" alt="{$goods.name|escape:html}"/></a></div><div class="xsqg_cen"><a href="{$goods.url}" target="_blank" title="{$goods.name|escape:html}">{$goods.short_name|escape:html}</a></div><div class="xsqg_bot"><div class="te">{$goods.promote_price}</div><div class="yuan">{$goods.market_price}</div><div class="remain_time"><font style="color:#666;">剩余</font> <font id="leftTime{$key}">{$lang.please_waiting}</font></div><script>Tday[{$key}] = new Date("{$goods.gmt_end_time}"); window.setInterval(function(){clock({$key});}, 1000); </script></div></div><!--{/foreach}--></li></ul></div>
</div>
<!-- {/if} -->
ecshop 中添加限时抢购功能(倒计时)相关推荐
- OAF在打开的新页面中添加按钮,功能是关闭当前页面
OAF在打开的新页面中添加按钮,功能是关闭当前页面 javascript:close()
- python右键弹出菜单编写_python实现应用程序在右键菜单中添加打开方式功能
最近项目组开发的一个小工具想要在右键菜单中添加打开方式,以有道云笔记为例进行了需求拆解和代码编写 1.需求拆解: 如何实现手动添加右键菜单的打开方式: Step1:打开注册表编辑器,Win+R-> ...
- php ECShop form,在ecshop中添加页面并且实现后台管理
在ecshop中添加页面并且实现后台管理 发布时间:2020-03-13 来源:未知 点击: 次 在在ecshop网店系统中中添加页面,并且实现后台管理,ecshop后台一共需要修改下面的四个文件 C ...
- 富文本中添加字体选项功能_扑中的字体功能
富文本中添加字体选项功能 A little extra help for styling your text 样式设置方面的一些额外帮助 I recently learned about a litt ...
- 如何在app应用中添加支付宝支付功能
推广排名q.q①⑨⑨⑦〇⑦④⑥*如何在app应用中添加支付宝支付功能 作为一枚普通的商户,或者 App 的开发人员,如何在对支付完全不了解的情况下,让 App 成功接入支付功能呢? 1)App 想接入 ...
- 如何在App中实现朋友圈功能之四在朋友圈中添加发送图片功能——箭扣科技Arrownock
如何在App中实现朋友圈功能 之四 在朋友圈中添加发送图片功能 实现概念: 当用户在界面点击发送按钮的时候,如果已经有选择好的图片,我们的做法是先上传图片到服务器,再将图片Id作为Post的属性上传. ...
- 在verto_communicator中添加呼叫入会功能
verto_communicator中添加呼叫入会功能 基于FreeSWITCH Version 1.9.0+git~20181001T145919Z~b5624eca20~64bit 一.修改fps ...
- flex html 控制编辑,在富文本编辑器中添加Tab键功能(Flex 3)
我试图在使用事件keyDown的富文本编辑器中添加Tab键功能.只需要清楚,在标签键上,我需要将控件保留在前面带有'\ t'空格的同一个文本框中,而不是跳到下一个对象.我尝试的下面的代码完全适用于te ...
- 在若依项目中添加导入excel功能
无论是电子商务网站,还是办公网站,都免不了要把一些excel导入到数据库中的功能,若依已经为此需求提供了很不错的封装与扩展. 前提: 首先,你需要建一张表,来存储你要导入的数据.本例中表名及实例名为: ...
最新文章
- Perl时间处理函数
- 使用VS2010调试技巧让C指针无处遁形
- 《易学C++(第2版)》——1.4 C++能够做些什么
- hana::detail::variadic::foldr1用法的测试程序
- CF1208F Bits And Pieces(未解决)
- 清新BLOG-CMS博客主题源码
- 有效的MongoDB索引
- git 还原文件到其他版本_如何在Git中还原旧文件版本
- python登录各种网页示例_Python 通过爬虫实现GitHub网页的模拟登录的示例代码
- iOS:界面适配(二)--iPhone/iPad适配(关于xib)
- 50个地理人必备数据库赶紧收藏起来(含气候、地信、地质、卫星遥感、城市经济等)
- 教你轻松创建谷歌账号、谷歌邮箱!
- 2点睡10点起不算熬夜?除非你每天都能执行
- 小象学院python网课值得吗-2018最新小象学院Python数据分析视频教程升级版第2期...
- dubbo之Serialization
- 读取生产环境go语言的最佳实践展示
- 郑州计算机五年大专学校排名,2021年河南十大专科学校排名 河南最好的高职院校...
- 为什么社交APP已经这么多了,他们还要耗巨资做
- Python 将TXT格式转换为手机通讯录格式vcf
- 检查python是否安装成功