ecshop模板常用函数整理总结
发布时间:2019-12-16 11:15:39作者:admin点击:
/**
* 通过goodsid,brandid 获取月售数量
* $type :goods 商店brand
* $date 成交天数 -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']->getOneCached("SELECT sum(og.goods_number) 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']->getOneCached("SELECT sum(og.goods_number) 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 intval($row);
}
/**
* 获取收藏数量
* @param undefined $id
* @param undefined $type goods,brand
*
*/
function get_shoucan_num($id,$type='goods'){
if($type=="goods"){
return $GLOBALS['db']->getOneCached("SELECT COUNT(*) as cnum FROM " . $GLOBALS['ecs']->table('collect_goods') . " where goods_id ='$id' ");
}else{
return $GLOBALS['db']->getOneCached("SELECT COUNT(*) as cnum FROM " . $GLOBALS['ecs']->table('collect_goods_sj') . " where brand_id ='$id' ");
}
}
/**
* goodid 获取 评论星级 ,评论总数
* 2014 12 10 shanmao.me
* 返回 评论总数,星级,星级html
*/
function good_id_re_commavg($goods_id){
$row = $GLOBALS['db']->getRowCached("SELECT COUNT(*) as cnum,IFNULL(AVG(comment_rank), 0) AS crank FROM " . $GLOBALS['ecs']->table('comment') . " where comment_type=0 and id_value ='$goods_id'");
$row['crank'] = ceil($row['crank']) == 0 ? 5 : ceil($row['crank']);
for($i=1;$i<=5;$i++){
if($i<=$row['crank'])
$row['cstar'] .= '';
else
$row['cstar'] .= '';
}
return $row;
}
/**
* 获取评论总数 看是否需要用到上面的! good_id_re_commavg
- 上一篇 : ecshop jquery冲突,美化商品属性选择 IE中js
- 下一篇 : ecshop模板支持php数据运算的代码实例