本文整理匯總了PHP中judge_package_stock函數的典型用法代碼示例。如果您正苦於以下問題:PHP judge_package_stock函數的具體用法?PHP judge_package_stock怎麽用?PHP judge_package_stock使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了judge_package_stock函數的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: add_package_to_cart
/**
* 添加禮包到購物車
*
* @access public
* @param integer $package_id 禮包編號
* @param integer $num 禮包數量
* @return boolean
*/
function add_package_to_cart($package_id, $num = 1)
{
$GLOBALS['err']->clean();
/* 取得禮包信息 */
$package = get_package_info($package_id);
if (empty($package)) {
$GLOBALS['err']->add($GLOBALS['_LANG']['goods_not_exists'], ERR_NOT_EXISTS);
return false;
}
/* 是否正在銷售 */
if ($package['is_on_sale'] == 0) {
$GLOBALS['err']->add($GLOBALS['_LANG']['not_on_sale'], ERR_NOT_ON_SALE);
return false;
}
/* 現有庫存是否還能湊齊一個禮包 */
if ($GLOBALS['_CFG']['use_storage'] == '1' && judge_package_stock($package_id)) {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], 1), ERR_OUT_OF_STOCK);
return false;
}
/* 檢查庫存 */
// if ($GLOBALS['_CFG']['use_storage'] == 1 && $num > $package['goods_number'])
// {
// $num = $goods['goods_number'];
// $GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $num), ERR_OUT_OF_STOCK);
//
// return false;
// }
/* 初始化要插入購物車的基本件數據 */
$parent = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $package_id, 'goods_sn' => '', 'goods_name' => addslashes($package['package_name']), 'market_price' => $package['market_package'], 'goods_price' => $package['package_price'], 'goods_number' => $num, 'goods_attr' => '', 'goods_attr_id' => '', 'is_real' => $package['is_real'], 'extension_code' => 'package_buy', 'is_gift' => 0, 'rec_type' => CART_GENERAL_GOODS);
/* 如果數量不為0,作為基本件插入 */
if ($num > 0) {
/* 檢查該商品是否已經存在在購物車中 */
$sql = "SELECT goods_number FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '" . $package_id . "' " . " AND parent_id = 0 AND extension_code = 'package_buy' " . " AND rec_type = '" . CART_GENERAL_GOODS . "'";
$row = $GLOBALS['db']->getRow($sql);
if ($row) {
$num += $row['goods_number'];
if ($GLOBALS['_CFG']['use_storage'] == 0 || $num > 0) {
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '" . $num . "'" . " WHERE session_id = '" . SESS_ID . "' AND goods_id = '{$package_id}' " . " AND parent_id = 0 AND extension_code = 'package_buy' " . " AND rec_type = '" . CART_GENERAL_GOODS . "'";
$GLOBALS['db']->query($sql);
} else {
$GLOBALS['err']->add(sprintf($GLOBALS['_LANG']['shortage'], $num), ERR_OUT_OF_STOCK);
return false;
}
} else {
$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;
}
示例2: check_goods_store
function check_goods_store($rec_id, $num)
{
$return = array('mes' => '', 'number' => 1);
$num = intval(make_semiangle($num));
$rec_id = intval($rec_id);
if ($num <= 0 && !is_numeric($num)) {
$return['mes'] = '所填數字必須是正整數!';
return $return;
}
if ($rec_id <= 0) {
$return['mes'] = '參數錯誤!';
return $return;
}
//查詢:
$sql = "SELECT `goods_id`, `goods_attr_id`, `product_id`, `extension_code` FROM" . $GLOBALS['ecs']->table('cart') . " WHERE rec_id='{$rec_id}' AND session_id='" . SESS_ID . "'";
$goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name, g.goods_number " . "FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('cart') . " AS c " . "WHERE g.goods_id = c.goods_id AND c.rec_id = '{$rec_id}'";
$row = $GLOBALS['db']->getRow($sql);
//查詢:係統啟用了庫存,檢查輸入的商品數量是否有效
if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy') {
if ($row['goods_number'] < $num) {
$return['mes'] = "非常抱歉,您選擇的商品" . $row['goods_name'] . " 的庫存數量不足 , 您最多隻能購買 " . $row['goods_number'] . " 件。";
$return['number'] = $row['goods_number'];
return $return;
}
/* 是貨品 */
$goods['product_id'] = trim($goods['product_id']);
if (!empty($goods['product_id'])) {
$sql = "SELECT product_number FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $goods['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $num) {
$return['mes'] = "非常抱歉,您選擇的商品" . $row['goods_name'] . " 的庫存數量隻有 " . $row['product_number'] . ",您最多隻能購買 " . $row['product_number'] . " 件。";
$return['number'] = $row['product_number'];
return $return;
}
}
} elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy') {
if (judge_package_stock($goods['goods_id'], $num)) {
$return['mes'] = "非常抱歉,庫存數量不足,請減少購買數購買。";
return $return;
}
}
return $return;
}
示例3: flow_cart_stock
/**
* 檢查訂單中商品庫存
*
* @access public
* @param array $arr
*
* @return void
*/
function flow_cart_stock($arr)
{
foreach ($arr as $key => $val) {
$val = intval(make_semiangle($val));
if ($val <= 0) {
continue;
}
$sql = "SELECT `goods_id`, `goods_attr_id`, `extension_code` FROM" . $GLOBALS['ecs']->table('cart') . " WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
$goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name, g.goods_number, c.product_id " . "FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('cart') . " AS c " . "WHERE g.goods_id = c.goods_id AND c.rec_id = '{$key}'";
$row = $GLOBALS['db']->getRow($sql);
//係統啟用了庫存,檢查輸入的商品數量是否有效
if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy') {
if ($row['goods_number'] < $val) {
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'], $row['goods_number'], $row['goods_number']));
exit;
}
/* 是貨品 */
$row['product_id'] = trim($row['product_id']);
if (!empty($row['product_id'])) {
$sql = "SELECT product_number FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $row['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $val) {
show_message(sprintf($GLOBALS['_LANG']['stock_insufficiency'], $row['goods_name'], $row['goods_number'], $row['goods_number']));
exit;
}
}
} elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy') {
if (judge_package_stock($goods['goods_id'], $val)) {
show_message($GLOBALS['_LANG']['package_stock_insufficiency']);
exit;
}
}
}
}
示例4: flow_update_cart
/**
* 更新購物車中的商品數量
*
* @access public
* @param array $arr
* @return void
*/
function flow_update_cart($arr)
{
/* 處理 */
foreach ($arr as $key => $val) {
$val = intval(make_semiangle($val));
if ($val <= 0 || !is_numeric($key)) {
continue;
}
//查詢:
$sql = "SELECT `goods_id`, `goods_attr_id`, `product_id`, `extension_code` FROM" . $GLOBALS['ecs']->table('cart') . " WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
$goods = $GLOBALS['db']->getRow($sql);
$sql = "SELECT g.goods_name, g.goods_number " . "FROM " . $GLOBALS['ecs']->table('goods') . " AS g, " . $GLOBALS['ecs']->table('cart') . " AS c " . "WHERE g.goods_id = c.goods_id AND c.rec_id = '{$key}'";
$row = $GLOBALS['db']->getRow($sql);
//查詢:係統啟用了庫存,檢查輸入的商品數量是否有效
if (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] != 'package_buy') {
if ($row['goods_number'] < $val) {
GZ_Api::outPut(10008);
exit;
}
/* 是貨品 */
$goods['product_id'] = trim($goods['product_id']);
if (!empty($goods['product_id'])) {
$sql = "SELECT product_number FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '" . $goods['goods_id'] . "' AND product_id = '" . $goods['product_id'] . "'";
$product_number = $GLOBALS['db']->getOne($sql);
if ($product_number < $val) {
GZ_Api::outPut(10008);
exit;
}
}
} elseif (intval($GLOBALS['_CFG']['use_storage']) > 0 && $goods['extension_code'] == 'package_buy') {
if (judge_package_stock($goods['goods_id'], $val)) {
GZ_Api::outPut(10008);
exit;
}
}
/* 查詢:檢查該項是否為基本件 以及是否存在配件 */
/* 此處配件是指添加商品時附加的並且是設置了優惠價格的配件 此類配件都有parent_id goods_number為1 */
$sql = "SELECT b.goods_number, b.rec_id\n FROM " . $GLOBALS['ecs']->table('cart') . " a, " . $GLOBALS['ecs']->table('cart') . " b\n WHERE a.rec_id = '{$key}'\n AND a.session_id = '" . SESS_ID . "'\n AND a.extension_code <> 'package_buy'\n AND b.parent_id = a.goods_id\n AND b.session_id = '" . SESS_ID . "'";
$offers_accessories_res = $GLOBALS['db']->query($sql);
//訂貨數量大於0
if ($val > 0) {
/* 判斷是否為超出數量的優惠價格的配件 刪除*/
$row_num = 1;
while ($offers_accessories_row = $GLOBALS['db']->fetchRow($offers_accessories_res)) {
if ($row_num > $val) {
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' " . "AND rec_id = '" . $offers_accessories_row['rec_id'] . "' LIMIT 1";
$GLOBALS['db']->query($sql);
}
$row_num++;
}
/* 處理超值禮包 */
if ($goods['extension_code'] == 'package_buy') {
//更新購物車中的商品數量
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '{$val}' WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
} else {
$attr_id = empty($goods['goods_attr_id']) ? array() : explode(',', $goods['goods_attr_id']);
$goods_price = get_final_price($goods['goods_id'], $val, true, $attr_id);
//更新購物車中的商品數量
$sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '{$val}', goods_price = '{$goods_price}' WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
}
} else {
/* 如果是基本件並且有優惠價格的配件則刪除優惠價格的配件 */
while ($offers_accessories_row = $GLOBALS['db']->fetchRow($offers_accessories_res)) {
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' " . "AND rec_id = '" . $offers_accessories_row['rec_id'] . "' LIMIT 1";
$GLOBALS['db']->query($sql);
}
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE rec_id='{$key}' AND session_id='" . SESS_ID . "'";
}
$GLOBALS['db']->query($sql);
}
/* 刪除所有贈品 */
$sql = "DELETE FROM " . $GLOBALS['ecs']->table('cart') . " WHERE session_id = '" . SESS_ID . "' AND is_gift <> 0";
$GLOBALS['db']->query($sql);
}