本文整理汇总了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);
}