以下函数会获取订单状态为已完成的订单中该商品的销量,此函数放在lib_goods.php文件中即可调用
/**
* 获取商品销量
*
* @access public
* @param string $goods_id
* @return int
*/
function selled_count($goods_id)
{
$sql = 'SELECT SUM(og.goods_number) as count ' .
'FROM ' . $GLOBALS['ecs']->table('order_goods') . ' AS og ' .
'LEFT JOIN ' .$GLOBALS['ecs']->table('order_info') . ' AS o ' .
"ON og.order_id = o.order_id " .
"WHERE (o.order_status = '" . OS_CONFIRMED . "' OR o.order_status = '" . OS_SPLITED . "') " .
"AND (o.pay_status = '" . PS_PAYED . "' OR o.pay_status = '" . PS_PAYING . "') " .
"AND (o.shipping_status = '" . SS_SHIPPED . "' OR o.shipping_status = '" . SS_RECEIVED . "') " .
"AND og.goods_id ='" .$goods_id . "'";
$res = $GLOBALS['db']->getOne($sql);
if($res>0)
{
return $res;
}
else
{
return('0');
}
}