当前位置: 首页>>代码示例>>PHP>>正文


PHP get_goods_attr_info函数代码示例

本文整理汇总了PHP中get_goods_attr_info函数的典型用法代码示例。如果您正苦于以下问题:PHP get_goods_attr_info函数的具体用法?PHP get_goods_attr_info怎么用?PHP get_goods_attr_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_goods_attr_info函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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);
    /* 初始化要插入购物车的基本件数据 */
//.........这里部分代码省略.........
开发者ID:dlpc,项目名称:ecshop,代码行数:101,代码来源:lib_order.php

示例2: action_add_huan_goods

function action_add_huan_goods()
{
    $user = $GLOBALS['user'];
    $_CFG = $GLOBALS['_CFG'];
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    $user_id = $_SESSION['user_id'];
    include_once 'includes/cls_json.php';
    include_once 'includes/lib_order.php';
    $json = new JSON();
    $result = array('error' => 0, 'content' => '');
    $_POST['goods'] = strip_tags(urldecode($_POST['goods']));
    $_POST['goods'] = json_str_iconv($_POST['goods']);
    $goods = $json->decode($_POST['goods']);
    $spec = $goods->spec;
    $goods_id = $goods->goods_id;
    $goods_name = $db->getOne("select goods_name from " . $ecs->table('goods') . " where goods_id='{$goods_id}' ");
    /* 如果商品有规格则取规格商品信息 配件除外 */
    $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);
    }
    $goods_attr = get_goods_attr_info($spec);
    $result['error'] = 1;
    $result['goods_name'] = $goods_name . "  ";
    $result['product_id'] = $product_info['product_id'];
    $result['product_id'] = $result['product_id'] == 'null' ? '0' : intval($result['product_id']);
    $result['content'] = addslashes($goods_attr);
    die($json->encode($result));
}
开发者ID:seanguo166,项目名称:yinoos,代码行数:33,代码来源:user.php

示例3: update_cart

/**
 * 更新购物车中的商品
 */
function update_cart()
{
    global $ecs, $db;
    //删除已下架商品
    $sql = "DELETE c FROM " . $ecs->table('cart', 'c') . " WHERE " . get_cart_cond('c.') . " AND NOT EXISTS (SELECT 1 FROM " . $ecs->table('goods', 'g') . " WHERE g.goods_id = c.goods_id AND g.is_on_sale = 1 AND g.is_delete = 0) " . " AND c.extension_code <> 'flash_sale' AND c.rec_type = " . CART_GENERAL_GOODS;
    $db->query($sql);
    //删除已过期限时抢购
    $now = time();
    $sql = "DELETE c FROM " . $ecs->table('cart', 'c') . " WHERE " . get_cart_cond('c.') . " AND NOT EXISTS (SELECT 1 FROM " . $ecs->table('flash_sale', 'f') . " WHERE f.id = c.extension_id AND f.is_on_sale = 1 AND f.start_time <= {$now} AND f.end_time > {$now}) " . " AND c.extension_code = 'flash_sale' AND c.rec_type = " . CART_GENERAL_GOODS;
    $db->query($sql);
    //限时抢购商品限购数量检查
    check_cartgoods_number(true);
    //更新产品价格、规格等
    $sql = "SELECT c.rec_id, c.goods_id, c.goods_number, c.goods_attr_id, g.goods_name, g.market_price, g.shop_price, g.amount_desc, g.free_more FROM " . $ecs->table('cart', 'c') . ',' . $ecs->table('goods', 'g') . " WHERE c.goods_id = g.goods_id AND c.extension_code <> 'flash_sale' AND " . get_cart_cond('c.');
    $query = $db->query($sql);
    while ($rs = $db->fetch_array($query)) {
        $spec = explode(',', $rs['goods_attr_id']);
        $goods_attr = get_goods_attr_info($spec);
        if (empty($goods_attr)) {
            $goods_attr = $rs['amount_desc'];
        } else {
            $goods_attr = $rs['amount_desc'] . "\n" . $goods_attr;
        }
        $cart = array('goods_name' => $rs['goods_name'], 'market_price' => $rs['market_price'], 'goods_price' => get_final_price($rs['goods_id'], $rs['goods_number'], true, $spec), 'goods_attr' => $goods_attr, 'free_more' => $rs['free_more']);
        $db->autoExecute($ecs->table('cart'), $cart, 'UPDATE', 'rec_id=' . $rs['rec_id']);
    }
}
开发者ID:GYWang1983,项目名称:fruit,代码行数:30,代码来源:lib_order.php

示例4: zy_addto_cart


//.........这里部分代码省略.........
            	//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'" .
            " ORDER BY goods_price";
    $res = $GLOBALS['db']->query($sql);
    while ($row = $GLOBALS['db']->fetchRow($res))
开发者ID:noikiy,项目名称:mdwp,代码行数:67,代码来源:flow.model.php

示例5: 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;
//.........这里部分代码省略.........
开发者ID:BGCX261,项目名称:zishashop-svn-to-git,代码行数:101,代码来源:lib_order.php

示例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(), $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;
}
开发者ID:songtaiwu,项目名称:m-cmsold,代码行数:63,代码来源:lib_order.php

示例7: 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)) {
//.........这里部分代码省略.........
开发者ID:seanguo166,项目名称:yinoos,代码行数:101,代码来源:lib_order.php


注:本文中的get_goods_attr_info函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。