/** * 获得购物车中商品的总重量、总价格、总数量 * * @access public * @param int $type 类型:默认普通商品 * @return array */ function cart_weight_price($type = CART_GENERAL_GOODS) { $package_row['weight'] = 0; $package_row['amount'] = 0; $package_row['number'] = 0; $packages_row['free_shipping'] = 1; /* 获得购物车中非超值礼包商品的总重量 */ $sql = 'SELECT SUM(g.goods_weight * c.goods_number) AS weight, ' . 'SUM(c.goods_price * c.goods_number) AS amount, ' . 'SUM(c.goods_number) AS number ' . 'FROM ' . $this->pre . 'cart AS c ' . 'LEFT JOIN ' . $this->pre . 'goods AS g ON g.goods_id = c.goods_id ' . "WHERE c.session_id = '" . SESS_ID . "' " . "AND rec_type = '{$type}' AND g.is_shipping = 0"; $row = $this->row($sql); $packages_row['weight'] = floatval($row['weight']) + $package_row['weight']; $packages_row['amount'] = floatval($row['amount']) + $package_row['amount']; $packages_row['number'] = intval($row['number']) + $package_row['number']; /* 格式化重量 */ $packages_row['formated_weight'] = formated_weight($packages_row['weight']); return $packages_row; }
/** * 获得购物车中商品的总重量、总价格、总数量 * * @access public * @param int $type 类型:默认普通商品 * @return array */ function cart_weight_price($type = CART_GENERAL_GOODS) { $package_row['weight'] = 0; $package_row['amount'] = 0; $package_row['number'] = 0; $packages_row['free_shipping'] = 1; /* 计算超值礼包内商品的相关配送参数 */ $sql = 'SELECT goods_id, goods_number, goods_price FROM ' . $GLOBALS['ecs']->table('cart') . " WHERE extension_code = 'package_buy' AND session_id = '" . SESS_ID . "'"; $row = $GLOBALS['db']->getAll($sql); if ($row) { $packages_row['free_shipping'] = 0; $free_shipping_count = 0; foreach ($row as $val) { // 如果商品全为免运费商品,设置一个标识变量 $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('package_goods') . ' AS pg, ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "WHERE g.goods_id = pg.goods_id AND g.is_shipping = 0 AND pg.package_id = '" . $val['goods_id'] . "'"; $shipping_count = $GLOBALS['db']->getOne($sql); if ($shipping_count > 0) { // 循环计算每个超值礼包商品的重量和数量,注意一个礼包中可能包换若干个同一商品 $sql = 'SELECT SUM(g.goods_weight * pg.goods_number) AS weight, ' . 'SUM(pg.goods_number) AS number FROM ' . $GLOBALS['ecs']->table('package_goods') . ' AS pg, ' . $GLOBALS['ecs']->table('goods') . ' AS g ' . "WHERE g.goods_id = pg.goods_id AND g.is_shipping = 0 AND pg.package_id = '" . $val['goods_id'] . "'"; $goods_row = $GLOBALS['db']->getRow($sql); $package_row['weight'] += floatval($goods_row['weight']) * $val['goods_number']; $package_row['amount'] += floatval($val['goods_price']) * $val['goods_number']; $package_row['number'] += intval($goods_row['number']) * $val['goods_number']; } else { $free_shipping_count++; } } $packages_row['free_shipping'] = $free_shipping_count == count($row) ? 1 : 0; } /* 获得购物车中非超值礼包商品的总重量 */ $sql = 'SELECT SUM(g.goods_weight * c.goods_number) AS weight, ' . 'SUM(c.goods_price * c.goods_number) AS amount, ' . 'SUM(c.goods_number) AS number ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = c.goods_id ' . "WHERE c.session_id = '" . SESS_ID . "' " . "AND rec_type = '{$type}' AND g.is_shipping = 0 AND c.extension_code != 'package_buy'"; $row = $GLOBALS['db']->getRow($sql); $packages_row['weight'] = floatval($row['weight']) + $package_row['weight']; $packages_row['amount'] = floatval($row['amount']) + $package_row['amount']; $packages_row['number'] = intval($row['number']) + $package_row['number']; /* 格式化重量 */ $packages_row['formated_weight'] = formated_weight($packages_row['weight']); return $packages_row; }
/** * 获得购物车中商品的总重量、总价格、总数量 * * @access public * @param int $type 类型:默认普通商品 * @return array */ function cart_weight_price($type = CART_GENERAL_GOODS) { /* 获得购物车中商品的总重量 */ $sql = 'SELECT SUM(g.goods_weight * c.goods_number) AS weight, ' . 'SUM(c.goods_price * c.goods_number) AS amount, ' . 'SUM(c.goods_number) AS number ' . 'FROM ' . $GLOBALS['ecs']->table('cart') . ' AS c ' . 'LEFT JOIN ' . $GLOBALS['ecs']->table('goods') . ' AS g ON g.goods_id = c.goods_id ' . "WHERE c.session_id = '" . SESS_ID . "' " . "AND rec_type = '{$type}'"; $row = $GLOBALS['db']->getRow($sql); $row['weight'] = floatval($row['weight']); $row['amount'] = floatval($row['amount']); $row['number'] = intval($row['number']); /* 格式化重量 */ $row['formated_weight'] = formated_weight($row['weight']); return $row; }