Exemplo n.º 1
0
/**
 * 获取相关属性的库存
 * @param int $goodid 商品id
 * @param string(array) $attrids 商品属性id的数组或者逗号分开的字符串
 */
function get_product_attr_num($goodid, $attrids = 0)
{
    $ret = array();
    /* 判断商品是否参与预售活动,如果参与则获取商品的(预售库存-已售出的数量) */
    // if(!empty($_REQUEST['pre_sale_id']))
    // {
    // 	$pre_sale = pre_sale_info($_REQUEST['pre_sale_id'], $goods_num);
    // 	//如果预售为空或者预售库存小于等于0则认为不限购
    // 	if(!empty($pre_sale) && $pre_sale['restrict_amount'] > 0){
    // 		$product_num = $pre_sale['restrict_amount'] - $pre_sale['valid_goods'];
    // 		return $product_num;
    // 	}
    // }
    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);
    }
    $goods_attr_array = sort_goods_attr_id_array($attrids);
    if (isset($goods_attr_array['sort'])) {
        $goods_attr = implode('|', $goods_attr_array['sort']);
        $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 = '" . $goods_attr . "' LIMIT 0, 1";
        $row = $GLOBALS['db']->getRow($sql);
        return $row['product_number'];
    }
    //sort($attrids);
    //$attrids = implode('|',$attrids);
    //$attrids = array_unique($attrids);
    //$attrids = str_replace(',','|',$attrids);
    /*
    	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;
    */
}
Exemplo n.º 2
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;
    */
}