ecshop月销售量二次开发代码

ecshop月销售量二次开发代码

放到includes/lib_main.php 里面

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

$arr[$row[‘goods_id’]][‘yueshou’]             = yueshou($row[‘goods_id’]);

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

[code lang=”php”]

/**
* 通过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]

 

缓存正确代码如:

[code lang=php]

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;
}

[/code]