天天团购——客户需求:抢购时间不到的产品首页显示

二次开发:天天团购开源CMS

需求:使首页的未达到抢购时间的产品显示出来。

分析:天天团购是一款开源的团购系统,应该是采用ThinkPHP框架开发的。首页默认显示正在团购期间的所有产品。其后台设置中有团购开始时间和结束时间,当产品的团购开始时间到了时间,就会自动显示在首页。数据库中的tttuangou_product表分别对应了两个字段:bengintime,overtime。


第一个反应是所有产品应该在tttuangou_product有一个flag的标志在数据表的字段中,通过对比now()并且将结果写入数据库 ,用“1” “0”来控制是否在首页显示。

经过测试和观察,发现tttuangou_product表中并没有其中的字段用来控制。

既然不是通过数据库,那么他们用的方式100%就是用直接获取now()的时间戳在程序中进行对比和判断的方法来做的。

天天团购的首页很奇怪,路径居然是在根目录下templates\html\igos\meituan\,下面的index.html就是其首页。

这种做法一度让我盲目的跟进分析了两个小时,最后无功而返。

最后侥幸找到了模板文件,内牛满面!

打开模板页,映入眼前的是

<div class="m960">
<div class="t_l List">
{loop $product $item}
{eval $icc++}
<div class="t_area_out item m_item" >
<div class="rc_t m_rc_t" ></div>
<div class="t_area_in m_t_area_in" >
<table class="at_jrat">

使用loop标签将$product数组放进自定义变量$tiem中。

好吧,虽然不清楚他们为什么会在如此偏僻的角落里面放下了自己的首页模板,但是index.mod.php这个文件总是默认的入口文件吧!

打开根目录下的modules文件夹,index.mod.php文件里面出现了我们需要的信息。

	function Main()
	{
		$clientUser = get('u', 'int');
		if ( $clientUser != '' )
		{
			handler('cookie')->setVar('finderid', $clientUser);
			handler('cookie')->setVar('findtime', time());
		}
		$data = logic('product')->display();
				$data || header('Location: '.rewrite('?mod=subscribe&code=mail'));
		$product = $data['product'];
		$this->Title = $data['mutiView'] ? '' : $product['name'];
		$data['mutiView'] || mocod('product.view');
		$data['mutiView'] || productCurrentView($product);
				include handler('template')->file($data['file']);
	}

Main函数是这套CMS默认的入口函数。

可以看到入口函数包含了这个一个模板

include handler('template')->file($data['file']);

好吧,这样的话,看看这个模板是在哪儿。

echo handler('template')->file($data['file']);
哦哦?输出结果居然是缓存下面的home.php?搞什么飞机!

………………


后来找到了一个可疑的函数logic,逐个分析,锁定到了product.logic.php,里面有一行判断代码。

function GetList( $cid = -1, $actived = null, $extend = '1' )
	{
		$sql_limit_city = '1';
		if ( $cid > 0 )
		{
			$sql_limit_city = '(p.display = '.PRO_DSP_Global.' OR (p.display = '.PRO_DSP_City.' AND p.city = ' . $cid . ') )';
		}
		$sql_limit_actived = '1';
		$now = time();
		if ( !is_null($actived) )
		{
			if ($actived === PRO_ACV_Yes)
			{
				$sql_limit_actived = 'p.begintime < ' . $now . ' AND p.overtime > ' . $now;
			}
			else
			{
				$sql_limit_actived = 'p.overtime < ' . $now;
			}
		}

这个是主角。。。

我修改后的代码

function GetList( $cid = -1, $actived = null, $extend = '1' )
	{
		$sql_limit_city = '1';
		if ( $cid > 0 )
		{
			$sql_limit_city = '(p.display = '.PRO_DSP_Global.' OR (p.display = '.PRO_DSP_City.' AND p.city = ' . $cid . ') )';
		}
		$sql_limit_actived = '1';
		$now = time();
		if ( !is_null($actived) )
		{
			if ($actived === PRO_ACV_Yes)
			{
				$sql_limit_actived = 'p.begintime < ' . $now . ' AND p.overtime > ' . $now;
				$sql_limit_actived = 'p.overtime > ' . $now;
			}
			else
			{
				$sql_limit_actived = 'p.overtime < ' . $now;
			}
		}

完成了……后续工作其实可以在首页显示出来一行“未开始抢购的产品”,然后整个列出来。不过客户的要求不需要继续开发。so……吃饭去!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值