• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

PHP get_products_info函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了get_products_info函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: is_stock

function is_stock($goods_id, $num, $spec = array())
{
    $sql = 'SELECT goods_number,is_alone_sale,is_on_sale FROM ' . $GLOBALS['ecs']->table('goods') . " WHERE goods_id = '{$goods_id}'";
    $goods = $GLOBALS['db']->getRow($sql);
    if (empty($goods)) {
        return 3;
    }
    if ($goods['is_on_sale'] == 0) {
        return 4;
    }
    if ($goods['is_alone_sale'] == 0) {
        return 2;
        // 不是配件时检查是否允许单独销售
    }
    if ($GLOBALS['_CFG']['use_storage'] == 1) {
        $sql = 'SELECT * FROM ' . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
        $prod = $GLOBALS['db']->getRow($sql);
    } else {
        return true;
    }
    if (is_spec($spec) && !empty($prod)) {
        $product_info = get_products_info($goods_id, $spec);
    }
    //检查:商品购买数量是否大于总库存
    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;
            }
        }
    }
    return true;
}
开发者ID:netroby,项目名称:ecshop,代码行数:40,代码来源:flow.php


示例4: explode

 }
 $goods_number = $_POST['add_number'];
 $attr_list = $goods_attr;
 $goods_attr = explode(',', $goods_attr);
 $k = array_search(0, $goods_attr);
 unset($goods_attr[$k]);
 $sql = "SELECT attr_value " . 'FROM ' . $GLOBALS['ecs']->table('goods_attr') . "WHERE goods_attr_id in({$attr_list})";
 $res = $db->query($sql);
 while ($row = $db->fetchRow($res)) {
     $attr_value[] = $row['attr_value'];
 }
 $attr_value = implode(",", $attr_value);
 $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
 $prod = $GLOBALS['db']->getRow($sql);
 if (is_spec($goods_attr) && !empty($prod)) {
     $product_info = get_products_info($_REQUEST['goodslist'], $goods_attr);
 }
 //商品存在规格 是货品 检查该货品库存
 if (is_spec($goods_attr) && !empty($prod)) {
     if (!empty($goods_attr)) {
         /* 取规格的货品库存 */
         if ($goods_number > $product_info['product_number']) {
             $url = "order.php?act=" . $step_act . "&order_id=" . $order_id . "&step=goods";
             echo '<a href="' . $url . '">' . $_LANG['goods_num_err'] . '</a>';
             exit;
             return false;
         }
     }
 }
 if (is_spec($goods_attr) && !empty($prod)) {
     /* 插入订单商品 */
开发者ID:norain2050,项目名称:benhu,代码行数:31,代码来源:order.php


示例5: foreach

    /* 查询:取得规格 */
    $specs = '';
    foreach ($_POST as $key => $value)
    {
        if (strpos($key, 'spec_') !== false)
        {
            $specs .= ',' . intval($value);
        }
    }
    $specs = trim($specs, ',');

    /* 查询:如果商品有规格则取规格商品信息 配件除外 */
    if ($specs)
    {
        $_specs = explode(',', $specs);
        $product_info = get_products_info($goods['goods_id'], $_specs);
    }

    empty($product_info) ? $product_info = array('product_number' => 0, 'product_id' => 0) : '';

    /* 查询:判断指定规格的货品数量是否足够 */
    if ($specs && $number > $product_info['product_number'])
    {
        show_message($_LANG['gb_error_goods_lacking'], '', '', 'error');
    }

    /* 查询:查询规格名称和值,不考虑价格 */
    $attr_list = array();
    $sql = "SELECT a.attr_name, g.attr_value " .
            "FROM " . $ecs->table('goods_attr') . " AS g, " .
                $ecs->table('attribute') . " AS a " .
开发者ID:blowfishJ,项目名称:galaxyCode,代码行数:31,代码来源:group_buy.php


示例6: show_message

 // 用户的积分总数
 if ($goods['exchange_integral'] > $user_points) {
     show_message($_LANG['eg_error_integral'], array($_LANG['back_up_page']), array($back_act), 'error');
 }
 /* 查询:取得规格 */
 $specs = '';
 foreach ($_POST as $key => $value) {
     if (strpos($key, 'spec_') !== false) {
         $specs .= ',' . intval($value);
     }
 }
 $specs = trim($specs, ',');
 /* 查询:如果商品有规格则取规格商品信息 配件除外 */
 if (!empty($specs)) {
     $_specs = explode(',', $specs);
     $product_info = get_products_info($goods_id, $_specs);
 }
 if (empty($product_info)) {
     $product_info = array('product_number' => '', 'product_id' => 0);
 }
 //查询:商品存在规格 是货品 检查该货品库存
 if (!empty($specs) && $product_info['product_number'] == 0 && $_CFG['use_storage'] == 1) {
     show_message($_LANG['eg_error_number'], array($_LANG['back_up_page']), array($back_act), 'error');
 }
 /* 查询:查询规格名称和值,不考虑价格 */
 $attr_list = array();
 $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs);
 $res = $db->query($sql);
 while ($row = $db->fetchRow($res)) {
     $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value'];
 }
开发者ID:nirvana-info,项目名称:old_bak,代码行数:31,代码来源:exchange.php


示例7: array

    $gallery_content = array();
    foreach ($gallery_list_www_ecshop68_com as $gkey => $gval) {
        $smarty->assign('picture', $gval);
        $content = $smarty->fetch('/library/goods_gallery.lib');
        $gallery_content[] = $content;
    }
    make_json_result($gallery_content);
    exit;
}
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'get_products_info') {
    include 'includes/cls_json.php';
    $json = new JSON();
    // $res = array('err_msg' => '', 'result' => '', 'qty' => 1);
    $spce_id = $_GET['id'];
    $goods_id = $_GET['goods_id'];
    $row = get_products_info($goods_id, explode(",", $spce_id));
    //$res = array('err_msg'=>$goods_id,'id'=>$spce_id);
    die($json->encode($row));
}
/* 代码增加_end By  www.ecshop68.com */
/*------------------------------------------------------ */
//-- 改变属性、数量时重新计算商品价格
/*------------------------------------------------------ */
if (!empty($_REQUEST['act']) && $_REQUEST['act'] == 'price') {
    include 'includes/cls_json.php';
    $json = new JSON();
    $res = array('err_msg' => '', 'result' => '', 'qty' => 1);
    //$attr_id    = isset($_REQUEST['attr']) ? explode(',', $_REQUEST['attr']) : array();
    $attr_id = isset($_REQUEST['attr']) ? $_REQUEST['attr'] : array();
    $number = isset($_REQUEST['number']) ? intval($_REQUEST['number']) : 1;
    //$number		= 1;
开发者ID:firsteam,项目名称:falcons,代码行数:31,代码来源:goods.php


示例8: 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;
}
开发者ID:dlpc,项目名称:ecshop,代码行数:41,代码来源:lib_order_2014-12-29.php


示例9: get_final_price

 } else {
     if ($number == 0) {
         $res['qty'] = $number = 1;
     } else {
         $res['qty'] = $number;
     }
     $shop_price = get_final_price($goods_id, $number, true, $attr_id);
     $res['result'] = price_format($shop_price * $number);
 }
 //ecshop商品详情页动态库存调用
 $goods_tinfo = get_goods_info($goods_id);
 $goods_sn = $goods_tinfo['goods_sn'];
 $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' LIMIT 0, 1";
 $prod = $GLOBALS['db']->getRow($sql);
 if (is_spec($attr_id) && !empty($prod)) {
     $product_info = get_products_info($goods_id, $attr_id);
 }
 if ($product_info['product_number']) {
     $res['stock'] = $product_info['product_number'];
     //商品库存
 } else {
     $res['stock'] = $goods_tinfo['goods_number'];
     //商品库存
 }
 if ($product_info['product_sn']) {
     $res['goods_sn'] = $product_info['product_sn'];
 } else {
     $res['goods_sn'] = $goods_tinfo['goods_sn'];
 }
 if ($product_info['product_weight']) {
     $res['goods_pweight'] = $product_info['product_weight'] . ' 千克(kg)';
开发者ID:norain2050,项目名称:benhu,代码行数:31,代码来源:goods.php


示例10: action_buy

function action_buy()
{
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    /* 查询:判断是否登录 */
    if ($_SESSION['user_id'] <= 0) {
        show_message($_LANG['ps_error_login'], '', '', 'error');
    }
    /* 查询:取得参数:预售活动id */
    $pre_sale_id = isset($_POST['pre_sale_id']) ? intval($_POST['pre_sale_id']) : 0;
    if ($pre_sale_id <= 0) {
        ecs_header("Location: pre_sale.php\n");
        exit;
    }
    /* 查询:取得数量 */
    $number = isset($_POST['number']) ? intval($_POST['number']) : 1;
    $number = $number < 1 ? 1 : $number;
    /* 查询:取得预售活动信息 */
    $pre_sale = pre_sale_info($pre_sale_id, $number);
    if (empty($pre_sale)) {
        ecs_header("Location: pre_sale.php\n");
        exit;
    }
    /* 查询:检查预售活动是否是进行中 */
    if ($pre_sale['status'] != PSS_UNDER_WAY) {
        show_message($_LANG['ps_error_status'], '', '', 'error');
    }
    /* 查询:取得预售商品信息 */
    $goods = goods_info($pre_sale['goods_id']);
    if (empty($goods)) {
        ecs_header("Location: pre_sale.php\n");
        exit;
    }
    /* 查询:判断数量是否足够 */
    if ($pre_sale['restrict_amount'] > 0 && $number > $pre_sale['restrict_amount'] - $pre_sale['valid_goods'] || $number > $goods['goods_number']) {
        show_message($_LANG['ps_error_goods_lacking'], '', '', 'error');
    }
    /* 查询:取得规格 */
    $specs = '';
    foreach ($_POST as $key => $value) {
        if (strpos($key, 'spec_') !== false) {
            $specs .= ',' . intval($value);
        }
    }
    $specs = trim($specs, ',');
    /* 查询:如果商品有规格则取规格商品信息 配件除外 */
    if ($specs) {
        $_specs = explode(',', $specs);
        $product_info = get_products_info($goods['goods_id'], $_specs);
    }
    empty($product_info) ? $product_info = array('product_number' => 0, 'product_id' => 0) : '';
    /* 查询:判断指定规格的货品数量是否足够 */
    if ($specs && $number > $product_info['product_number'] && false) {
        show_message($_LANG['ps_error_goods_lacking'], '', '', 'error');
    }
    /* 查询:查询规格名称和值,不考虑价格 */
    $attr_list = array();
    $sql = "SELECT a.attr_name, g.attr_value " . "FROM " . $ecs->table('goods_attr') . " AS g, " . $ecs->table('attribute') . " AS a " . "WHERE g.attr_id = a.attr_id " . "AND g.goods_attr_id " . db_create_in($specs);
    $res = $db->query($sql);
    while ($row = $db->fetchRow($res)) {
        $attr_list[] = $row['attr_name'] . ': ' . $row['attr_value'];
    }
    $goods_attr = join(chr(13) . chr(10), $attr_list);
    /* 更新:清空购物车中所有预售商品 */
    include_once ROOT_PATH . 'includes/lib_order.php';
    clear_cart(CART_pre_sale_GOODS);
    /* 更新:加入购物车 */
    $goods_price = $pre_sale['deposit'] > 0 ? $pre_sale['deposit'] : $pre_sale['cur_price'];
    $cart = array('user_id' => $_SESSION['user_id'], 'session_id' => SESS_ID, 'goods_id' => $pre_sale['goods_id'], 'product_id' => $product_info['product_id'], 'goods_sn' => addslashes($goods['goods_sn']), 'goods_name' => addslashes($goods['goods_name']), 'market_price' => $goods['market_price'], 'goods_price' => $goods_price, 'goods_number' => $number, 'goods_attr' => addslashes($goods_attr), 'goods_attr_id' => $specs, 'is_real' => $goods['is_real'], 'extension_code' => addslashes($goods['extension_code']), 'parent_id' => 0, 'rec_type' => CART_PRE_SALE_GOODS, 'is_gift' => 0);
    $db->autoExecute($ecs->table('cart'), $cart, 'INSERT');
    $_SESSION['sel_cartgoods'] = $db->insert_id();
    $_SESSION['pre_sale_cart'] = $cart;
    /* 更新:记录购物流程类型:预售 */
    $_SESSION['flow_type'] = CART_PRE_SALE_GOODS;
    $_SESSION['extension_code'] = PRE_SALE_CODE;
    $_SESSION['extension_id'] = $pre_sale_id;
    /* 进入收货人页面 */
    ecs_header("Location: ./flow.php?step=checkout\n");
    exit;
}
开发者ID:seanguo166,项目名称:yinoos,代码行数:81,代码来源:pre_sale.php


示例11: 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_products_info函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP get_profile函数代码示例发布时间:2022-05-15
下一篇:
PHP get_products函数代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap