ecshop在商品列表显示购买记录
时间:2024年02月04日
/来源:网络
/编辑:佚名
遇到这样的需求不用自己写代码,很多都是官方写好的,商品详细页本来就有个购买记录,我们打开goods.php就会看到
------------------------------------------------------------------------------------------------------------------------
$sql = 'SELECT count(*) ' .
'FROM ' . $ecs->table('order_info') . ' AS oi LEFT JOIN ' . $ecs->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $ecs->table('order_goods') . ' AS og ' .
'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;
$count = $db->getOne($sql);
------------------------------------------------------------------------------------------------------------------------
这时候我们修改一下 写成一个函数放到lib_goods.php 这样就可以随便调用了
------------------------------------------------------------------------------------------------------------------------
/**获得购买次数*/
function get_goods_ordernum($goods_id)
{
$sql = 'SELECT count(*) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS
og ' .
'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;
$count = $GLOBALS['db']->getOne($sql);
return $count;
}
------------------------------------------------------------------------------------------------------------------------
函数写好我们下来开始调用。比如我们在最新商品下显示购买记录
在lib_goods.php找到get_recommend_goods这个函数 342行左右加入
$goods[$idx]['order_num'] = get_goods_ordernum($row['goods_id']);
到此程序部分完成
-----------------------------------------------------------------------------------------------------------------------------
模板部分是:<span style="color:#0066FF;">{if $goods.order_num}已经有{$goods.order_num}人购买过{else}暂无人购买{/if}</span>
------------------------------------------------------------------------------------------------------------------------
$sql = 'SELECT count(*) ' .
'FROM ' . $ecs->table('order_info') . ' AS oi LEFT JOIN ' . $ecs->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $ecs->table('order_goods') . ' AS og ' .
'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;
$count = $db->getOne($sql);
------------------------------------------------------------------------------------------------------------------------
这时候我们修改一下 写成一个函数放到lib_goods.php 这样就可以随便调用了
------------------------------------------------------------------------------------------------------------------------
/**获得购买次数*/
function get_goods_ordernum($goods_id)
{
$sql = 'SELECT count(*) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS oi LEFT JOIN ' . $GLOBALS['ecs']->table('users') . ' AS u ON oi.user_id = u.user_id, ' . $GLOBALS['ecs']->table('order_goods') . ' AS
og ' .
'WHERE oi.order_id = og.order_id AND ' . time() . ' - oi.add_time < 2592000 AND og.goods_id = ' . $goods_id;
$count = $GLOBALS['db']->getOne($sql);
return $count;
}
------------------------------------------------------------------------------------------------------------------------
函数写好我们下来开始调用。比如我们在最新商品下显示购买记录
在lib_goods.php找到get_recommend_goods这个函数 342行左右加入
$goods[$idx]['order_num'] = get_goods_ordernum($row['goods_id']);
到此程序部分完成
-----------------------------------------------------------------------------------------------------------------------------
模板部分是:<span style="color:#0066FF;">{if $goods.order_num}已经有{$goods.order_num}人购买过{else}暂无人购买{/if}</span>
新闻资讯 更多
热门文章
- 178Moban源码谈谈免费源码与收费源码的区别
- 2帝国CMS忘记后台登陆用户名、密码、认证码的解决方法
- 3帝国CMS(EmpireCMS) v7.5后台任意代码执行漏洞及具体修复方法
- 4帝国CMS和WordPress 哪个好?哪个适合建站?
- 5如何解决Discuz的密码错误次数过多请15分钟后登陆的问题
- 6帝国cms灵动标签取得内容和栏目链接地址
- 7emlog pro 注册码“开心”教程(如果有一天,emlog官方版 或者 emlog免费版 跑路了,那用户怎么办?)
- 8织梦CMS在nginx下设置伪静态方法(附nginx伪静态规则)
- 9帝国cms后台登录出现”您还未登录”怎么解决?
- 10帝国cms7.5忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法