|
在ecshop中,团购是ecshop的一个比较有特色的功能,在前台group_buy.php就是来处理ecshop团购信息的。包括购买行为和团购信息的列表。分析includes/lib_goods.php中的。group_buy_stat()函数,他的格式为下group_buy_stat($group_buy_id, $deposit)。第一个参数表示团购的ID,第二个参数就是保证金。
/* 取得总订单数和总商品数 */
$group_buy_id = intval($group_buy_id);
$sql = "SELECT COUNT(*) AS total_order, SUM(g.goods_number) AS total_goods " .
"FROM " . $GLOBALS['ecs']->table('order_info') . " AS o, " .
$GLOBALS['ecs']->table('order_goods') . " AS g " .
" WHERE o.order_id = g.order_id " .
"AND o.extension_code = 'group_buy' " .
"AND o.extension_id = '$group_buy_id' " .
"AND (order_status = '" . OS_CONFIRMED . "' OR order_status = '" . OS_UNCONFIRMED . "')";
$stat = $GLOBALS['db']->getRow($sql);
if ($stat['total_order'] == 0)
{
$stat['total_goods'] = 0;
}
/* 取得有效订单数和有效商品数 */
$deposit = floatval($deposit);
if ($deposit > 0 && $stat['total_order'] > 0)
{
$sql .= " AND (o.money_paid + o.surplus) >= '$deposit'";
$row = $GLOBALS['db']->getRow($sql);
$stat['valid_order'] = $row['total_order'];
if ($stat['valid_order'] == 0)
{
$stat['valid_goods'] = 0;
}
else
{
$stat['valid_goods'] = $row['total_goods'];
}
}
else
{
$stat['valid_order'] = $stat['total_order'];
$stat['valid_goods'] = $stat['total_goods'];
}
return $stat;
他返回一个数组,其中就有团购商品的一些统计信息,包括购买数量,定单。等。
所以,在首页,我们只需要取的ecshop团购信息的ext_info基本信息,通过unserialize()发放解析,然后通过group_buy_stat函数,就可以把相关的数据得到。而得到的total_goods字段,就是我们要取得的信息,团购商品买出去的总量。 |
|