调用购买评价:
$goods[$id]['num'] = get_buy_sum($row['goods_id']);//购买
$goods[$id]['pingjia'] = get_comment_num($row['goods_id'],1,5);//评价
$goods_list[$key]['goods_thumb'] = $val["goods_thumb"];//取出商品图片
php页面方法:
//ecshop实现销售多少件的功能
function get_buy_sum($goods_id){
$sql = 'SELECT IFNULL(SUM(g.goods_number), 0) ' .
'FROM ' . $GLOBALS['ecs']->table('order_info') . ' AS o, ' .
$GLOBALS['ecs']->table('order_goods') . ' AS g ' .
"WHERE o.order_id = g.order_id " .
//"AND o.order_status = '" . OS_CONFIRMED . "' " . //订单状态
//"AND o.shipping_status " . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . //配送状态
//" AND o.pay_status " . db_create_in(array(PS_PAYED, PS_PAYING)) . //支付状态
" AND g.goods_id = '$goods_id'";
return $GLOBALS['db']->getOne($sql);
}
//取出评论总数
function get_comment_num($goods_id,$num1,$num2)
{
$sql= "select count(*) from ".$GLOBALS['ecs']->table('comment')." where id_value='".$goods_id."' AND status = 1 AND comment_rank>=".$num1." AND comment_rank<=".$num2."";
return $GLOBALS['db']->getOne($sql);
}
//根绝订单参数 取出商品图片
$goods_list = order_goods($order_id);
foreach ($goods_list AS $key => $value)
{
$goods_list[$key]['market_price'] = price_format($value['market_price'], false);
$goods_list[$key]['goods_price'] = price_format($value['goods_price'], false);
//通过订单循环取出ID,通过循环ID获取商品图片
$goods_list[$key]['subtotal'] = price_format($value['subtotal'], false);
$arr = get_img($value['goods_id']);
foreach($arr as $k=>$val)
{
$goods_list[$key]['goods_thumb'] = $val["goods_thumb"];
}
}
function get_img($gid)
{
$sql="select goods_thumb from " . $GLOBALS['ecs']->table('goods') . " where goods_id=".$gid;
$res=$GLOBALS['db']->getAll($sql);
return $res;
}
PHP页面调取:
1.如果是在单品页面调用:$smarty->assign('buy_num',get_buy_sum($goods_id));
2.如果是取出多个商品,因为要传ID给方法,所以要跟随数据库循环取出:
while($row = $GLOBALS['db']->fetchRow($result)){
$catelist[$row['goods_id']]['num'] = get_buy_sum($row['goods_id']);//循环取出购买记录
}
DWT页面展示:
1.单品调用:已 售 出:{$buy_num}件
2.循环调用:已 售 出:{$goods.num}件