Beispiel #1
0
if ($_REQUEST['step'] == 'update_group_cart') {
    include_once 'includes/cls_json.php';
    $result = array('error' => 0, 'message' => '', 'content' => '', 'goods_id' => '');
    $json = new JSON();
    $rec_id = intval($_GET['rec_id']);
    $number = intval($_GET['number']);
    $goods_id = intval($_GET['goods_id']);
    $result['suppid'] = intval($_GET['suppid']);
    $result['rec_id'] = $rec_id;
    $result['number'] = $number;
    if ($GLOBALS['_CFG']['use_storage'] == 1) {
        //morestock_morecity _start
        //获取当前购物车中商品的属性值
        $goodsRow = $GLOBALS['db']->getRow("select goods_number,goods_id,goods_attr_id from " . $GLOBALS['ecs']->table('cart') . " where rec_id=" . $rec_id);
        //$goods_number = $GLOBALS['db']->getOne("select goods_number from ".$GLOBALS['ecs']->table('goods')." where goods_id='$goods_id'");
        $goods_number = is_have_stock($goodsRow['goods_id'], trim($goodsRow['goods_attr_id']));
        if ($number > $goods_number) {
            $result['error'] = '1';
            $result['content'] = '对不起,您选择的数量超出库存您最多可购买' . $goods_number . "件";
            $result['number'] = $goodsRow['goods_number'] > $goods_number ? $goods_number : ($number > $goodsRow['goods_number'] ? $goodsRow['goods_number'] : $number);
            die($json->encode($result));
        }
        //morestock_morecity _end
    }
    $sql = "UPDATE " . $GLOBALS['ecs']->table('cart') . " SET goods_number = '{$number}' WHERE rec_id = {$rec_id}";
    $GLOBALS['db']->query($sql);
    /* 取得商品列表,计算合计 */
    $cart_goods = get_cart_goods();
    //折扣活动
    $result['your_discount'] = '';
    $discount = compute_discount($result['suppid']);
Beispiel #2
0
     $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);
 $_COOKIE['region_1'] = $old_order['province'] > 0 ? $old_order['province'] : 0;
 $_COOKIE['region_2'] = $old_order['city'] > 0 ? $old_order['city'] : 0;
 $_COOKIE['region_3'] = $old_order['district'] > 0 ? $old_order['district'] : 0;
 $_COOKIE['region_4'] = $old_order['xiangcun'] > 0 ? $old_order['xiangcun'] : 0;
 require_once ROOT_PATH . 'includes/lib_setarea.php';
 require_once ROOT_PATH . 'includes/lib_stock.php';
 if (is_spec($goods_attr) && !empty($prod)) {
     $product_info = get_products_info($_REQUEST['goodslist'], $goods_attr);
 } else {
     $product_info = $prod;
     $product_info['product_number'] = is_have_stock($_REQUEST['goodslist']);
 }
 //商品存在规格 是货品 检查该货品库存
 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;
         }
     }
 }
 //查找商品对应仓库的仓库id
 if (empty($product_info['goods_attr'])) {
Beispiel #3
0
/**
 * 获得购物车中的商品
 *
 * @access  public
 * @return  array
 */
function get_cart_goods($other = '')
{
    /* 初始化 */
    $goods_list = array();
    $total = array('goods_price' => 0, 'market_price' => 0, 'saving' => 0, 'save_rate' => 0, 'goods_amount' => 0);
    /* 循环、统计 */
    /* 代码增加_start    By   www.68ecshop.com */
    $sql_where = $_SESSION['user_id'] > 0 ? "c.user_id='" . $_SESSION['user_id'] . "' " : "c.session_id = '" . SESS_ID . "' AND c.user_id=0 ";
    $sql = "SELECT c.*, g.supplier_id, IF(c.parent_id, c.parent_id, c.goods_id) AS pid  " . " FROM " . $GLOBALS['ecs']->table('cart') . " AS c left join " . $GLOBALS['ecs']->table('goods') . " AS g " . " on c.goods_id=g.goods_id " . " WHERE {$sql_where} AND c.rec_type = '" . CART_GENERAL_GOODS . "' {$other} " . " ORDER BY pid, c.parent_id";
    /* 代码增加_end    By   www.68ecshop.com */
    $res = $GLOBALS['db']->query($sql);
    /* 用于统计购物车中实体商品和虚拟商品的个数 */
    $virtual_goods_count = 0;
    $real_goods_count = 0;
    while ($row = $GLOBALS['db']->fetchRow($res)) {
        $total['goods_price'] += $row['goods_price'] * $row['goods_number'];
        $total['market_price'] += $row['market_price'] * $row['goods_number'];
        $row['subtotal'] = price_format($row['goods_price'] * $row['goods_number'], false);
        $row['goods_price'] = price_format($row['goods_price'], false);
        $row['market_price'] = price_format($row['market_price'], false);
        /* 统计实体商品和虚拟商品的个数 */
        if ($row['is_real']) {
            $real_goods_count++;
        } else {
            $virtual_goods_count++;
        }
        /* 查询规格 */
        if (trim($row['goods_attr']) != '') {
            $row['goods_attr'] = addslashes($row['goods_attr']);
            $sql = "SELECT attr_value FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_attr_id " . db_create_in($row['goods_attr']);
            $attr_list = $GLOBALS['db']->getCol($sql);
            foreach ($attr_list as $attr) {
                $row['goods_name'] .= ' [' . $attr . '] ';
            }
        }
        /* 增加是否在购物车里显示商品图 */
        if (($GLOBALS['_CFG']['show_goods_in_cart'] == "2" || $GLOBALS['_CFG']['show_goods_in_cart'] == "3") && $row['extension_code'] != 'package_buy') {
            $goods_thumb = $GLOBALS['db']->getOne("SELECT `goods_thumb` FROM " . $GLOBALS['ecs']->table('goods') . " WHERE `goods_id`='{$row['goods_id']}'");
            $row['goods_thumb'] = '../' . get_image_path($row['goods_id'], $goods_thumb, true);
        }
        if ($row['extension_code'] == 'package_buy') {
            $row['package_goods_list'] = get_package_goods($row['goods_id'], $row['package_attr_id']);
            //修改 by www.ecshop68.com 增加一个变量
        }
        /* 代码增加_start  By  www.68ecshop.com */
        $row['is_cansel'] = is_cansel($row['goods_id'], $row['product_id'], $row['package_buy']);
        if ($row['supplier_id']) {
            $supplier_name = $GLOBALS['db']->getOne("select supplier_name from " . $GLOBALS['ecs']->table('supplier') . " where supplier_id='" . $row['supplier_id'] . "' ");
            $supplier_name = '商家:' . $supplier_name;
        } else {
            $supplier_name = '网站自营';
        }
        $row['stock_num'] = is_have_stock($row['goods_id'], $row['goods_attr_id']);
        //morestock_morecity
        $row['stock_dec'] = $row['stock_num'] > 0 ? '有货' : '无货';
        //morestock_morecity
        $keyname = $row['supplier_id'] ? $row['supplier_id'] : '0';
        $goods_list[$keyname]['goods_list'][] = $row;
        $goods_list[$keyname]['supplier_name'] = $supplier_name;
        ksort($goods_list);
        //$goods_list[] = $row;
        /* 代码修改_end  By  www.68ecshop.com */
    }
    $total['goods_amount'] = $total['goods_price'];
    $total['saving'] = price_format($total['market_price'] - $total['goods_price'], false);
    if ($total['market_price'] > 0) {
        $total['save_rate'] = $total['market_price'] ? round(($total['market_price'] - $total['goods_price']) * 100 / $total['market_price']) . '%' : 0;
    }
    $total['goods_price'] = price_format($total['goods_price'], false);
    $total['market_price'] = price_format($total['market_price'], false);
    $total['real_goods_count'] = $real_goods_count;
    $total['virtual_goods_count'] = $virtual_goods_count;
    return array('goods_list' => $goods_list, 'total' => $total);
}
Beispiel #4
0
function insert_is_youhuo($arr)
{
    $stock_num = is_have_stock($arr['goodid'], $arr['attr']);
    if ($stock_num > 0) {
        return '有货';
    } else {
        return '无货';
    }
}
Beispiel #5
0
function get_goods_nums_txm($goods_id, $attr_id)
{
    $goods_attr = implode(',', $attr_id);
    return is_have_stock($goods_id, $goods_attr);
    /*
    $sql = "SELECT product_id, goods_id, goods_attr, product_sn, product_number
    		FROM " . $GLOBALS['ecs']->table('products') . " 
    		WHERE goods_id = $goods_id AND goods_attr = '".$goods_attr."' LIMIT 0, 1";
    $row = $GLOBALS['db']->getRow($sql);
    
    return $row['product_number'];
    */
}
Beispiel #6
0
/**
 * 获取相关属性的库存
 * @param int $goodid 商品id
 * @param string(array) $attrids 商品属性id的数组或者逗号分开的字符串
 */
function get_product_attr_num($goodid, $attrids = 0)
{
    //if(!empty($attrids)){
    //$attrids = str_replace(',','|',$attrids);
    //}
    return is_have_stock($goodid, $attrids);
    //morestock_morecity
}
Beispiel #7
0
function is_cansel($goods_id, $product_id, $package_buy)
{
    if ($package_buy == 'package_buy') {
        return '1';
    }
    $sql = "select is_on_sale, goods_number from " . $GLOBALS['ecs']->table('goods') . " where goods_id='{$goods_id}' ";
    $row = $GLOBALS['db']->getRow($sql);
    if (!$row['is_on_sale']) {
        return '0';
    }
    if ($product_id > 0) {
        $sql2 = "select goods_attr from " . $GLOBALS['ecs']->table('products') . " where product_id='{$product_id}' ";
        $attr_str = $GLOBALS['db']->getOne($sql);
    } else {
        $attr_str = "";
    }
    $goods_number = is_have_stock($goods_id, $attr_str);
    if ($goods_number <= 0) {
        return '0';
    }
    return '1';
    /*
    	else
    	{
    		if ($product_id>0)
    		{
    			$sql2 = "select product_number from ". $GLOBALS['ecs']->table('products') ." where product_id='$product_id' ";
    			$row2 = $GLOBALS['db']->getRow($sql2);
    			if (!$row2['product_number'])
    			{
    				return '0';
    			}
    		}
    		else
    		{
    			if (!$row['goods_number'])
    			{
    				return '0';
    			}
    		}
    	}
    	return '1';*/
}
Beispiel #8
0
/**
 * 获取相关属性的库存
 * @param int $goodid 商品id
 * @param string(array) $attrids 商品属性id的数组或者逗号分开的字符串
 */
function get_product_attr_num($goodid, $attrids = 0)
{
    //if(!empty($attrids)){
    //	$attrids = str_replace(',','|',$attrids);
    //}
    return is_have_stock($goodid, $attrids);
    //morestock_morecity
    $ret = array();
    if (empty($attrids)) {
        $ginfo = get_goods_attr_value($goodid, 'goods_number');
        return $ginfo['goods_number'];
        //$ret[$attrids] = $ginfo['goods_number'];
        //return $ret;
    }
    //if(!is_array($attrids)){
    //	$attrids = explode(',',$attrids);
    //}
    //$attrids = array_unique($attrids);
    $attrids = str_replace(',', '|', $attrids);
    $sql = "SELECT product_id, goods_id, goods_attr, product_sn, product_number\n                FROM " . $GLOBALS['ecs']->table('products') . " \n                WHERE goods_id = {$goodid} AND goods_attr = '" . $attrids . "'";
    $row = $GLOBALS['db']->getRow($sql);
    return $row['product_number'];
    /*
    	echo "<pre>";
    	print_r($row);
    
    	foreach ($row as $key => $value)
    {
        if(in_array($value['goods_attr'],$attrids)){
        	$ret[$value['goods_attr']] = $value['product_number'];
        }
    }
    return $ret;
    */
}