ECShop 增加收藏商品排行榜功能
时间:2024年01月31日
/来源:网络
/编辑:佚名
关于这个函数的说明:
这个函数可以放在 /includes/lib_goods.php 或
/includes/lib_main.php 文件中,本人更喜欢放在前者。
关于这个函数的默认值:
时间:三个月(收藏商品统计时间);
获取数据的条数:5条;
如果这两个在后台修改的话,可自行在
ECShop 后台 ‘商店设置’ =》 ‘显示设置’中添加这个两选项。
/**
*
收藏商品排行榜
* @author Seven2
* @license
* @version v.10
*
@since 2010-08-19
* @access public
*
@return array
*/
function get_collect_goods()
{
switch
($GLOBALS['_CFG']['collect_time'])
{
case 1: // 一年
$base_where = '`c`.`add_time` >= "' . (gmtime() - 365 * 86400) . '"
';
break;
case 2: // 半年
$base_where
= '`c`.`add_time` >= "' . (gmtime() - 180 * 86400) . '" ';
break;
case 3: // 三个月
$base_where =
'`c`.`add_time` >= "' . (gmtime() - 90 * 86400) . '" ';
break;
case 4: // 一个月
$base_where =
'`c`.`add_time` >= "' . (gmtime() - 30 * 86400) . '" ';
break;
default:
$base_where = '`c`.`add_time`
>= "' . (gmtime() - 90 * 86400) . '" ';
}
$row =
array();
$arr = array();
$limit_num =
isset($GLOBALS['_CFG']['collect_number']) ? (int)
$GLOBALS['_CFG']['collect_number'] : 5;
$sql = 'SELECT `c`.`goods_id`,
COUNT(`c`.`goods_id`) AS `total`, `g`.`cat_id`, ' .
'`g`.`goods_name`, `g`.`shop_price`, `g`.`goods_thumb` FROM ' .
$GLOBALS['ecs']->table('collect_goods') . ' AS `c` LEFT JOIN ' .
$GLOBALS['ecs']->table('goods') . ' AS `g` ON `c`.`goods_id` =
`g`.`goods_id` ' .
'WHERE ' . $base_where . 'AND `g`.`is_on_sale`
= "1" AND ' .
'`g`.`is_alone_sale` = "1" AND `g`.`is_delete` = "0"
GROUP BY `c`.`goods_id` ' .
'ORDER BY `total` DESC LIMIT '
. $limit_num;
$res = $GLOBALS['db']->query($sql);
while
($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['total'] = $row['total'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['shop_price'] = $row['shop_price'];
$arr[$row['goods_id']]['format_shop_price'] =
price_format($row['shop_price']);
$arr[$row['goods_id']]['goods_thumb'] = $row['goods_thumb'];
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'
=> $row['goods_id']), $row['goods_name']);
}
return
$arr;
}
这个函数可以放在 /includes/lib_goods.php 或
/includes/lib_main.php 文件中,本人更喜欢放在前者。
关于这个函数的默认值:
时间:三个月(收藏商品统计时间);
获取数据的条数:5条;
如果这两个在后台修改的话,可自行在
ECShop 后台 ‘商店设置’ =》 ‘显示设置’中添加这个两选项。
/**
*
收藏商品排行榜
* @author Seven2
* @license
* @version v.10
*
@since 2010-08-19
* @access public
*
@return array
*/
function get_collect_goods()
{
switch
($GLOBALS['_CFG']['collect_time'])
{
case 1: // 一年
$base_where = '`c`.`add_time` >= "' . (gmtime() - 365 * 86400) . '"
';
break;
case 2: // 半年
$base_where
= '`c`.`add_time` >= "' . (gmtime() - 180 * 86400) . '" ';
break;
case 3: // 三个月
$base_where =
'`c`.`add_time` >= "' . (gmtime() - 90 * 86400) . '" ';
break;
case 4: // 一个月
$base_where =
'`c`.`add_time` >= "' . (gmtime() - 30 * 86400) . '" ';
break;
default:
$base_where = '`c`.`add_time`
>= "' . (gmtime() - 90 * 86400) . '" ';
}
$row =
array();
$arr = array();
$limit_num =
isset($GLOBALS['_CFG']['collect_number']) ? (int)
$GLOBALS['_CFG']['collect_number'] : 5;
$sql = 'SELECT `c`.`goods_id`,
COUNT(`c`.`goods_id`) AS `total`, `g`.`cat_id`, ' .
'`g`.`goods_name`, `g`.`shop_price`, `g`.`goods_thumb` FROM ' .
$GLOBALS['ecs']->table('collect_goods') . ' AS `c` LEFT JOIN ' .
$GLOBALS['ecs']->table('goods') . ' AS `g` ON `c`.`goods_id` =
`g`.`goods_id` ' .
'WHERE ' . $base_where . 'AND `g`.`is_on_sale`
= "1" AND ' .
'`g`.`is_alone_sale` = "1" AND `g`.`is_delete` = "0"
GROUP BY `c`.`goods_id` ' .
'ORDER BY `total` DESC LIMIT '
. $limit_num;
$res = $GLOBALS['db']->query($sql);
while
($row = $GLOBALS['db']->fetchRow($res))
{
$arr[$row['goods_id']]['goods_id'] = $row['goods_id'];
$arr[$row['goods_id']]['total'] = $row['total'];
$arr[$row['goods_id']]['goods_name'] = $row['goods_name'];
$arr[$row['goods_id']]['shop_price'] = $row['shop_price'];
$arr[$row['goods_id']]['format_shop_price'] =
price_format($row['shop_price']);
$arr[$row['goods_id']]['goods_thumb'] = $row['goods_thumb'];
$arr[$row['goods_id']]['url'] = build_uri('goods', array('gid'
=> $row['goods_id']), $row['goods_name']);
}
return
$arr;
}
新闻资讯 更多
热门文章
- 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忘记登录密码 和忘记登录认证码以及多次登录 失败被锁定解决办法