欢迎光临景诺科技软件开发淘宝店

进店请收藏,谢谢

ecshop月销售量二次开发代码

ecshop月销售量二次开发代码

放到includes/lib_main.php 里面

就可以全站调用了。调用如:

$arr[$row['goods_id']]['yueshou']             = yueshou($row['goods_id']);

本方法带有5分钟缓存。详细缓存时间看 includes/cls_mysql.php  这个文件内要去掉两个 limit 1 不然会sql报错。


/**
* 通过goodsid,brandid 获取月售数量
* $type :goods brand // 根据商品id或者品牌店铺查询
* $date 成交天数 -1 为所有 默认成交天数30天,-1为所有成交量
*/
function yueshou($id,$type='goods',$date=30){
 if($date>0) $alltime = " and oi.add_time>UNIX_TIMESTAMP()-86400*".$date;
 if($type=='goods'){
 $row = $GLOBALS['db']->getRowCached("SELECT COUNT(*) as gnum FROM " . $GLOBALS['ecs']->table('order_goods') . " as og left join " . $GLOBALS['ecs']->table('order_info') . " as oi ON oi.order_id=og.order_id where og.goods_id ='$id'".$alltime);
 }else{
 $row = $GLOBALS['db']->getRowCached("SELECT COUNT(*) as gnum FROM " . $GLOBALS['ecs']->table('order_goods') . " as og left join " . $GLOBALS['ecs']->table('order_info') . " as oi ON oi.order_id=og.order_id where og.brandid ='$id'".$alltime);
 }

return $row['gnum'];
}

[/php]

 

缓存正确代码如:

1

function getRowCached($sql, $cached = 'FILEFIRST')
 {
 $sql = trim($sql); //这里去掉了 limit 1

$cachefirst = ($cached == 'FILEFIRST' || ($cached == 'MYSQLFIRST' && $this->platform != 'WINDOWS')) && $this->max_cache_time;
 if (!$cachefirst)
 {
 return $this->getRow($sql, true);
 }
 else
 {
 $result = $this->getSqlCacheData($sql, $cached);
 if (empty($result['storecache']) == true)
 {
 return $result['data'];
 }
 }

$arr = $this->getRow($sql, true);

if ($arr !== false && $cachefirst)
 {
 $this->setSqlCacheData($result, $arr);
 }

return $arr;
 }

更多

本文固定链接: http://shanmao.me/web-system/ecshop-web-system/ecshop-yue-xiao-shou-liang-er-ci-kai-fa-dai-ma | 山猫的博客

该日志由 admin 于2015年04月09日发表在 ECSHOP二次开发 分类下,
原创文章转载请注明: ecshop月销售量二次开发代码 | 山猫的博客