本文整理匯總了PHP中spec_price函數的典型用法代碼示例。如果您正苦於以下問題:PHP spec_price函數的具體用法?PHP spec_price怎麽用?PHP spec_price使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了spec_price函數的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: get_final_price
/**
* 取得商品最終使用價格
*
* @param string $goods_id 商品編號
* @param string $goods_num 購買數量
* @param boolean $is_spec_price 是否加入規格價格
* @param mix $spec 規格ID的數組或者逗號分隔的字符串
*
* @return 商品最終購買價格
*/
function get_final_price($goods_id, $goods_num = '1', $is_spec_price = false, $spec = array())
{
$final_price = '0';
//商品最終購買價格
$volume_price = '0';
//商品優惠價格
$promote_price = '0';
//商品促銷價格
$user_price = '0';
//商品會員價格
//取得商品優惠價格列表
$price_list = get_volume_price_list($goods_id, '1');
if (!empty($price_list)) {
foreach ($price_list as $value) {
if ($goods_num >= $value['number']) {
$volume_price = $value['price'];
}
}
}
//取得商品促銷價格列表
/* 取得商品信息 */
$sql = "SELECT g.promote_price, g.promote_start_date, g.promote_end_date, " . "IFNULL(mp.user_price, g.shop_price * '" . $_SESSION['discount'] . "') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '" . $_SESSION['user_rank'] . "' " . " WHERE g.goods_id = '" . $goods_id . "'" . " AND g.is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
/* 計算商品的促銷價格 */
if ($goods['promote_price'] > 0) {
$promote_price = bargain_price($goods['promote_price'], $goods['promote_start_date'], $goods['promote_end_date']);
} else {
$promote_price = 0;
}
//取得商品會員價格列表
$user_price = $goods['shop_price'];
//比較商品的促銷價格,會員價格,優惠價格
if (empty($volume_price) && empty($promote_price)) {
//如果優惠價格,促銷價格都為空則取會員價格
$final_price = $user_price;
} elseif (!empty($volume_price) && empty($promote_price)) {
//如果優惠價格為空時不參加這個比較。
$final_price = min($volume_price, $user_price);
} elseif (empty($volume_price) && !empty($promote_price)) {
//如果促銷價格為空時不參加這個比較。
$final_price = min($promote_price, $user_price);
} elseif (!empty($volume_price) && !empty($promote_price)) {
//取促銷價格,會員價格,優惠價格最小值
$final_price = min($volume_price, $promote_price, $user_price);
} else {
$final_price = $user_price;
}
//如果需要加入規格價格
if ($is_spec_price) {
if (!empty($spec)) {
$spec_price = spec_price($spec);
$final_price += $spec_price;
}
}
//返回商品最終購買價格
return $final_price;
}
示例2: addto_cart
/**
* 添加商品到購物車
*
* @access public
* @param integer $goods_id 商品編號
* @param integer $num 商品數量
* @param array $spec 規格值對應的id數組
* @param integer $parent 基本件
* @return boolean
*/
function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0)
{
$GLOBALS['err']->clean();
$_parent_id = $parent;
/* 取得商品信息 */
$sql = "SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, g.is_shipping, g.free_more, g.amount_desc, " . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
if (empty($goods)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 如果是作為配件添加到購物車的,需要先檢查購物車裏麵是否已經有基本件 */
if ($parent > 0) {
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id='{$parent}' AND " . get_cart_cond() . " AND extension_code <> 'package_buy'";
if ($GLOBALS['db']->getOne($sql) == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['no_basic_goods'], ERR_NO_BASIC_GOODS);
return false;
}
}
/* 是否正在銷售 */
if ($goods['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
/* 不是配件時檢查是否允許單獨銷售 */
if (empty($parent) && $goods['is_alone_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['cannt_alone_sale'], ERR_CANNT_ALONE_SALE);
return false;
}
//TODO 取消規格相關邏輯
/* 如果商品有規格則取規格商品信息 配件除外 */
/*$sql = "SELECT * FROM " .$GLOBALS['ecs']->table('products'). " WHERE goods_id = '$goods_id' LIMIT 0, 1";
$prod = $GLOBALS['db']->getRow($sql);
if (is_spec($spec) && !empty($prod))
{
$product_info = get_products_info($goods_id, $spec);
}
if (empty($product_info))
{
$product_info = array('product_number' => '', 'product_id' => 0);
}*/
/* 檢查:庫存 */
if ($GLOBALS['_CFG']['use_storage'] == 1) {
//檢查:商品購買數量是否大於總庫存
if ($num > $goods['goods_number']) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $goods['goods_number']), ERR_OUT_OF_STOCK);
return false;
}
//商品存在規格 是貨品 檢查該貨品庫存
if (is_spec($spec) && !empty($prod)) {
if (!empty($spec)) {
/* 取規格的貨品庫存 */
if ($num > $product_info['product_number']) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $product_info['product_number']), ERR_OUT_OF_STOCK);
return false;
}
}
}
}
/* 計算商品的促銷價格 */
$spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, $num, true, $spec);
$goods['market_price'] += $spec_price;
//商品規格
$goods_attr_id = join(',', $spec);
$goods_attr = get_goods_attr_info($spec);
if (empty($goods_attr)) {
$goods_attr = $goods['amount_desc'];
} else {
$goods_attr = $goods['amount_desc'] . "\n" . $goods_attr;
}
// 初始化要插入購物車的基本件數據
$parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'product_id' => $product_info['product_id'], 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'free_more' => $goods['free_more'], 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'extension_code' => $goods['extension_code'], 'is_gift' => 0, 'is_shipping' => $goods['is_shipping'], 'add_time' => time(), 'rec_type' => CART_GENERAL_GOODS);
// 如果該配件在添加為基本件的配件時,所設置的“配件價格”比原價低,即此配件在價格上提供了優惠,
// 則按照該配件的優惠價格賣,但是每一個基本件隻能購買一個優惠價格的“該配件”,多買的“該配件”不享
// 受此優惠
//TODO: 取消配件邏輯
/*$basic_list = array();
$sql = "SELECT parent_id, goods_price " .
"FROM " . $GLOBALS['ecs']->table('group_goods') .
" WHERE goods_id = '$goods_id'" .
" AND goods_price < '$goods_price'" .
" AND parent_id = '$_parent_id'" .
" ORDER BY goods_price";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res))
{
$basic_list[$row['parent_id']] = $row['goods_price'];
}
//.........這裏部分代碼省略.........
示例3: addto_cart
/**
* 添加商品到購物車
*
* @access public
* @param integer $goods_id 商品編號
* @param integer $num 商品數量
* @param array $spec 規格值對應的id數組
* @param integer $parent 基本件
* @return boolean
*/
function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0)
{
$GLOBALS['err']->clean();
$_parent_id = $parent;
/*ccx 2015-03-03 判斷該商品是否已經通過自動下架功能 start*/
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('auto_manage') . " WHERE item_id = {$goods_id} AND type = 'goods' ";
$autodb = $GLOBALS['db']->getRow($sql);
//print_r($autodb);exit;
if ($autodb) {
$where = " WHERE goods_id = '{$goods_id}'";
if ($autodb['endtime'] < gmtime() && $autodb['endtime'] > 0) {
$sql = "UPDATE " . $GLOBALS['ecs']->table('goods') . " SET is_on_sale = 0 {$where}";
$GLOBALS['db']->query($sql);
$sql_1 = "DELETE FROM " . $GLOBALS['ecs']->table('auto_manage') . "WHERE item_id = '{$goods_id}' AND type = 'goods'";
$GLOBALS['db']->query($sql_1);
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
//var_dump($up);
}
/*ccx 2015-03-03 end*/
/* 取得商品信息 */
$sql = "SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, g.is_shipping," . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
if (empty($goods)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 如果是作為配件添加到購物車的,需要先檢查購物車裏麵是否已經有基本件 */
if ($parent > 0) {
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id='{$parent}' AND session_id='" . SESS_ID . "' AND extension_code <> 'package_buy'";
if ($GLOBALS['db']->getOne($sql) == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['no_basic_goods'], ERR_NO_BASIC_GOODS);
return false;
}
}
/* 是否正在銷售 */
if ($goods['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
/* 不是配件時檢查是否允許單獨銷售 */
if (empty($parent) && $goods['is_alone_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['cannt_alone_sale'], ERR_CANNT_ALONE_SALE);
return false;
}
/* 如果商品有規格則取規格商品信息 配件除外 */
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
$prod = $GLOBALS['db']->getRow($sql);
if (is_spec($spec) && !empty($prod)) {
$product_info = get_products_info($goods_id, $spec);
}
if (empty($product_info)) {
$product_info = array('product_number' => '', 'product_id' => 0);
}
/* 檢查:庫存 */
/* 2014-12-18 ccx 把購物的時候, 把檢查庫存這塊屏蔽了, 不做庫存判斷
if ($GLOBALS['_CFG']['use_storage'] == 1)
{
//檢查:商品購買數量是否大於總庫存
if ($num > $goods['goods_number'])
{
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $goods['goods_number']), ERR_OUT_OF_STOCK);
return false;
}
//商品存在規格 是貨品 檢查該貨品庫存
if (is_spec($spec) && !empty($prod))
{
if (!empty($spec))
{
// 取規格的貨品庫存
if ($num > $product_info['product_number'])
{
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $product_info['product_number']), ERR_OUT_OF_STOCK);
return false;
}
}
}
}
*/
/* 計算商品的促銷價格 */
$spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, $num, true, $spec);
$goods['market_price'] += $spec_price;
$goods_attr = get_goods_attr_info($spec);
$goods_attr_id = join(',', $spec);
/* 初始化要插入購物車的基本件數據 */
//.........這裏部分代碼省略.........
示例4: get_combo_goods_info
/**
* 獲取商品的原價、配件價、庫存(配件組合) by mike
* 返回數組
*/
function get_combo_goods_info($goods_id, $num = 1, $spec = array(), $parent = 0)
{
$result = array();
/* 取得商品信息 */
$sql = "SELECT goods_number FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$goods_id}' AND is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
/* 如果商品有規格則取規格商品信息 配件除外 */
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
$prod = $GLOBALS['db']->getRow($sql);
if (is_spec($spec) && !empty($prod)) {
$product_info = get_products_info($goods_id, $spec);
}
if (empty($product_info)) {
$product_info = array('product_number' => '', 'product_id' => 0);
}
//商品庫存
$result['stock'] = $goods['goods_number'];
//商品存在規格 是貨品 檢查該貨品庫存
if (is_spec($spec) && !empty($prod)) {
if (!empty($spec)) {
/* 取規格的貨品庫存 */
$result['stock'] = $product_info['product_number'];
}
}
/* 如果該配件在添加為基本件的配件時,所設置的“配件價格”比原價低,即此配件在價格上提供了優惠, */
$sql = "SELECT parent_id, goods_price " . "FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE goods_id = '{$goods_id}'" . " AND parent_id = '{$parent}'" . " ORDER BY goods_price";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$result['fittings_price'] = $row['goods_price'];
}
/* 計算商品的促銷價格 */
$result['fittings_price'] = isset($result['fittings_price']) ? $result['fittings_price'] : get_final_price($goods_id, $num, true, $spec);
$result['spec_price'] = spec_price($spec);
//屬性價格
$result['goods_price'] = get_final_price($goods_id, $num, true, $spec);
return $result;
}
示例5: zy_addto_cart
//.........這裏部分代碼省略.........
$msg['status']=mb_convert_encoding($msg['status'],'utf-8','gbk');
jsonExit($msg);
//echo $_GET['jsoncallback']."(".$msg['status'].")";
//exit;
}else{
jsonExit($msg);
}
return false;
}
//商品存在規格 是貨品 檢查該貨品庫存
/* if (is_spec($spec) && !empty($prod))
{
if (!empty($spec))
{
// 取規格的貨品庫存
if ($num > $product_info['product_number'])
{
//$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $product_info['product_number']), ERR_OUT_OF_STOCK);
$msg['status'] = rpcLang("goods.php", "no_enough_spec_product");
if(EC_CHARSET == 'gbk'){
jsonExit($msg['status']);
print_r($_GET['jsoncallback'],"(".$msg.")");
}else{
jsonExit($msg);
}
return false;
}
}
} */
}
/* 計算商品的促銷價格 */
$spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, $num, true, $spec);
$goods['market_price'] += $spec_price;
$goods_attr = get_goods_attr_info($spec);
$goods_attr_id = join(',', $spec);
/* 初始化要插入購物車的基本件數據 */
$parent = array(
'user_id' => $_SESSION['user_id'],
'session_id' => SESS_ID,
'goods_id' => $goods_id,
'goods_sn' => addslashes($goods['goods_sn']),
// 'product_id' => $product_info['product_id'],
'goods_name' => addslashes($goods['goods_name']),
'market_price' => $goods['market_price'],
'goods_attr' => addslashes($goods_attr),
'goods_attr_id' => $goods_attr_id,
'is_real' => $goods['is_real'],
'extension_code'=> $goods['extension_code'],
'is_gift' => 0,
'is_shipping' => $goods['is_shipping'],
'rec_type' => CART_GENERAL_GOODS
);
/* 如果該配件在添加為基本件的配件時,所設置的“配件價格”比原價低,即此配件在價格上提供了優惠, */
/* 則按照該配件的優惠價格賣,但是每一個基本件隻能購買一個優惠價格的“該配件”,多買的“該配件”不享 */
/* 受此優惠 */
$basic_list = array();
$sql = "SELECT parent_id, goods_price " .
"FROM " . $GLOBALS['ecs']->table('group_goods') .
" WHERE goods_id = '$goods_id'" .
" AND goods_price < '$goods_price'" .
" AND parent_id = '$_parent_id'" .
示例6: addto_cart
/**
* 添加商品到購物車
*
* @access public
* @param integer $goods_id 商品編號
* @param integer $num 商品數量
* @param array $spec 規格
* @param integer $parent 基本件
* @return boolean
*/
function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0)
{
$GLOBALS['err']->clean();
/* 取得商品信息 */
$sql = "SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, " . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
if (empty($goods)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 如果是作為配件添加到購物車的,需要先檢查購物車裏麵是否已經有基本件 */
if ($parent > 0) {
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id='{$parent}' AND session_id='" . SESS_ID . "'";
if ($GLOBALS['db']->getOne($sql) == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['no_basic_goods'], ERR_NO_BASIC_GOODS);
return false;
}
/* 檢查該配件是否已經添加過了。 */
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id = '{$goods_id}' AND parent_id='{$parent}' AND session_id='" . SESS_ID . "'";
if ($GLOBALS['db']->getOne($sql) > 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['fitting_goods_exists'], ERR_NOT_EXISTS);
return false;
}
}
/* 是否正在銷售 */
if ($goods['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
/* 不是配件時檢查是否允許單獨銷售 */
if (empty($parent) && $goods['is_alone_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['cannt_alone_sale'], ERR_CANNT_ALONE_SALE);
return false;
}
/* 檢查庫存 */
if ($GLOBALS['_CFG']['use_storage'] == 1 && $num > $goods['goods_number']) {
$num = $goods['goods_number'];
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $num), ERR_OUT_OF_STOCK);
return false;
}
/* 計算商品的促銷價格 */
$spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, $num, true, $spec);
$goods['market_price'] += $spec_price;
$goods_attr = get_goods_attr_info($spec);
$goods_attr_id = join(',', $spec);
/* 初始化要插入購物車的基本件數據 */
$parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'extension_code' => $goods['extension_code'], 'is_gift' => 0, 'rec_type' => CART_GENERAL_GOODS);
/* 取得該商品的基本件和該商品作為其配件的價格(條件是價格低) */
$basic_list = array();
$sql = "SELECT parent_id, goods_price " . "FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE goods_id = '{$goods_id}'" . " AND goods_price < '{$goods_price}'" . " ORDER BY goods_price";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$basic_list[$row['parent_id']] = $row['goods_price'];
}
/* 取得購物車中該商品每個基本件的數量 */
$basic_count_list = array();
if ($basic_list) {
$sql = "SELECT goods_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND parent_id = 0" . " AND goods_id " . db_create_in(array_keys($basic_list)) . " GROUP BY goods_id";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$basic_count_list[$row['goods_id']] = $row['count'];
}
}
/* 取得購物車中該商品每個基本件已有該商品配件數量,計算出每個基本件還能有幾個該商品配件 */
if ($basic_count_list) {
$sql = "SELECT parent_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND goods_id = '{$goods_id}'" . " AND parent_id " . db_create_in(array_keys($basic_count_list)) . " GROUP BY parent_id";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$basic_count_list[$row['parent_id']] -= $row['count'];
}
}
/* 循環插入配件 */
foreach ($basic_list as $parent_id => $fitting_price) {
/* 如果已全部插入,退出 */
if ($num <= 0) {
break;
}
/* 如果該基本件不再購物車中,執行下一個 */
if (!isset($basic_count_list[$parent_id])) {
continue;
}
/* 如果該基本件的配件數量已滿,執行下一個基本件 */
if ($basic_count_list[$parent_id] <= 0) {
continue;
}
/* 作為該基本件的配件插入 */
$parent['goods_price'] = max($fitting_price, 0);
$parent['goods_number'] = min($num, $basic_count_list[$parent_id]);
$parent['parent_id'] = $parent_id;
//.........這裏部分代碼省略.........
示例7: addto_cart
/**
* 添加商品到購物車
*
* @access public
* @param integer $goods_id 商品編號
* @param integer $num 商品數量
* @param array $spec 規格
* @param integer $parent 基本件
* @return boolean
*/
function addto_cart($goods_id, $num = 1, $spec = array(), $is_integ = 0, $parent = 0)
{
$GLOBALS['err']->clean();
/* 取得商品信息 */
$sql = "SELECT goods_name, goods_sn, is_on_sale, cat_id, is_real, shop_price, integral " . " FROM " . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$goods_id}' and is_delete = 0 ";
$goods = $GLOBALS['db']->getRow($sql);
if (empty($goods)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 是否正在銷售 */
if ($goods['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
$goods_price = $goods['shop_price'];
$spec_price = spec_price($spec);
$goods_price += $spec_price;
$goods_attr = get_goods_attr_info($spec);
$goods_attr_id = get_goods_attr_id($spec[0]);
$name = $goods_attr_id == '194' || $goods_attr_id == '195' ? stripenglish($goods['goods_name']) . '(無糖)' : stripenglish($goods['goods_name']);
if (strpos($goods_attr, '0.68磅')) {
$res_attr = '0.68磅';
} elseif (strpos($goods_attr, '磅')) {
$res_attr = substr($goods_attr, strpos($goods_attr, '磅') - 3, 6);
} elseif (strpos($goods_attr, 'P')) {
$res_attr = substr($goods_attr, strpos($goods_attr, 'P') - 3, 4);
} else {
$res_attr = substr($goods_attr, 7, 6);
}
/* 初始化要插入購物車的基本件數據 */
$parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($name), 'goods_attr' => addslashes($res_attr), 'goods_attr_id' => $goods_attr_id, 'is_real' => $goods['is_real'], 'is_integral' => $is_integ);
/* 如果數量不為0,作為基本件插入 */
if ($num > 0) {
/* 檢查該商品是否已經存在在購物車中 */
$sql = "SELECT goods_number FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . "AND parent_id = 0 AND goods_attr = '" . $res_attr . "' " . "AND is_integral = '{$is_integ}' AND goods_attr_id = '{$goods_attr_id}'";
$row = $GLOBALS['db']->getRow($sql);
if ($row) {
$num += $row['goods_number'];
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '{$num}'" . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$goods_id}' " . "AND parent_id = 0 AND goods_attr = '" . $res_attr . "' " . "AND goods_attr_id = '{$goods_attr_id}'";
$GLOBALS['db']->query($sql);
} else {
$parent['goods_price'] = $is_integ == 1 && $goods['cat_id'] != 4 ? $goods['integral'] : max($goods_price, 0);
$parent['goods_attr_id'] = $parent['goods_price'] > 100 ? $parent['goods_attr_id'] : 0;
$parent['goods_number'] = $num;
$GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('cart'), $parent, 'INSERT');
}
}
/* 把贈品刪除 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0";
$GLOBALS['db']->query($sql);
return true;
}
示例8: addto_cart
/**
* 添加商品到購物車
*
* @access public
* @param integer $goods_id 商品編號
* @param integer $num 商品數量
* @param array $spec 規格值對應的id數組
* @param integer $parent 基本件
* @return boolean
*/
function addto_cart($goods_id, $num = 1, $spec = array(), $parent = 0)
{
$GLOBALS['err']->clean();
$_parent_id = $parent;
/* 取得商品信息 */
$sql = "SELECT g.goods_name, g.goods_sn, g.is_on_sale, g.is_real, " . "g.market_price, g.cost_price, g.shop_price AS org_price, g.promote_price, g.promote_start_date, " . "g.promote_end_date, g.goods_weight, g.integral, g.extension_code, " . "g.goods_number, g.is_alone_sale, g.is_shipping," . "IFNULL(mp.user_price, g.shop_price * '{$_SESSION['discount']}') AS shop_price " . " FROM " . $GLOBALS['ecs']->table('goods') . " AS g " . " LEFT JOIN " . $GLOBALS['ecs']->table('member_price') . " AS mp " . "ON mp.goods_id = g.goods_id AND mp.user_rank = '{$_SESSION['user_rank']}' " . " WHERE g.goods_id = '{$goods_id}'" . " AND g.is_delete = 0";
$goods = $GLOBALS['db']->getRow($sql);
if (empty($goods)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 如果是作為配件添加到購物車的,需要先檢查購物車裏麵是否已經有基本件 */
if ($parent > 0) {
$sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('cart') . " WHERE goods_id='{$parent}' AND session_id='" . SESS_ID . "' AND extension_code <> 'package_buy'";
if ($GLOBALS['db']->getOne($sql) == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['no_basic_goods'], ERR_NO_BASIC_GOODS);
return false;
}
}
/* 是否正在銷售 */
if ($goods['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
/* 不是配件時檢查是否允許單獨銷售 */
if (empty($parent) && $goods['is_alone_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['cannt_alone_sale'], ERR_CANNT_ALONE_SALE);
return false;
}
/* 如果商品有規格則取規格商品信息 配件除外 */
$sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
$prod = $GLOBALS['db']->getRow($sql);
if (is_spec($spec) && !empty($prod)) {
$product_info = get_products_info($goods_id, $spec);
}
if (empty($product_info)) {
$product_info = array('product_number' => '', 'product_id' => 0);
}
/* 檢查:庫存 */
if ($GLOBALS['_CFG']['use_storage'] == 1) {
//檢查:商品購買數量是否大於總庫存
if ($num > $goods['goods_number']) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $goods['goods_number']), ERR_OUT_OF_STOCK);
return false;
}
//商品存在規格 是貨品 檢查該貨品庫存
if (is_spec($spec) && !empty($prod)) {
if (!empty($spec)) {
/* 取規格的貨品庫存 */
if ($num > $product_info['product_number']) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $product_info['product_number']), ERR_OUT_OF_STOCK);
return false;
}
}
}
}
/* 計算商品的促銷價格 */
$spec_price = spec_price($spec);
$goods_price = get_final_price($goods_id, $num, true, $spec);
$goods['market_price'] += $spec_price;
$goods_attr = get_goods_attr_info($spec);
$goods_attr_id = join(',', $spec);
/* 初始化要插入購物車的基本件數據 */
$parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $goods_id, 'goods_sn' => addslashes($goods['goods_sn']), 'product_id' => $product_info['product_id'], 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $goods_attr_id, 'cost_price' => $goods['cost_price'], 'is_real' => $goods['is_real'], 'extension_code' => $goods['extension_code'], 'is_gift' => 0, 'is_shipping' => $goods['is_shipping'], 'add_time' => gmtime(), 'rec_type' => CART_GENERAL_GOODS);
//初始化為普通商品
$_SESSION['flow_type'] = CART_GENERAL_GOODS;
/* 如果該配件在添加為基本件的配件時,所設置的“配件價格”比原價低,即此配件在價格上提供了優惠, */
/* 則按照該配件的優惠價格賣,但是每一個基本件隻能購買一個優惠價格的“該配件”,多買的“該配件”不享 */
/* 受此優惠 */
$basic_list = array();
$sql = "SELECT parent_id, goods_price " . "FROM " . $GLOBALS['ecs']->table('group_goods') . " WHERE goods_id = '{$goods_id}'" . " AND goods_price < '{$goods_price}'" . " AND parent_id = '{$_parent_id}'" . " ORDER BY goods_price";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$basic_list[$row['parent_id']] = $row['goods_price'];
}
/* 取得購物車中該商品每個基本件的數量 */
$basic_count_list = array();
if ($basic_list) {
$sql = "SELECT goods_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND parent_id = 0" . " AND extension_code <> 'package_buy' " . " AND goods_id " . db_create_in(array_keys($basic_list)) . " GROUP BY goods_id";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
$basic_count_list[$row['goods_id']] = $row['count'];
}
}
/* 取得購物車中該商品每個基本件已有該商品配件數量,計算出每個基本件還能有幾個該商品配件 */
/* 一個基本件對應一個該商品配件 */
if ($basic_count_list) {
$sql = "SELECT parent_id, SUM(goods_number) AS count " . "FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "'" . " AND goods_id = '{$goods_id}'" . " AND extension_code <> 'package_buy' " . " AND parent_id " . db_create_in(array_keys($basic_count_list)) . " GROUP BY parent_id";
$res = $GLOBALS['db']->query($sql);
while ($row = $GLOBALS['db']->fetchRow($res)) {
//.........這裏部分代碼省略.........