Ejemplo n.º 1
0
/**
 * 取指定规格的货品信息
 *
 * @access      public
 * @param       string      $goods_id
 * @param       array       $spec_goods_attr_id
 * @return      array
 */
function get_products_info($goods_id, $spec_goods_attr_id)
{
    $return_array = array();
    if (empty($spec_goods_attr_id) || !is_array($spec_goods_attr_id) || empty($goods_id)) {
        return $return_array;
    }
    $goods_attr_array = sort_goods_attr_id_array($spec_goods_attr_id);
    if (isset($goods_attr_array['sort'])) {
        $goods_attr = implode('|', $goods_attr_array['sort']);
        $sql = "SELECT * FROM " . $GLOBALS['ecs']->table('products') . " WHERE goods_id = '{$goods_id}' AND goods_attr = '{$goods_attr}' LIMIT 0, 1";
        $return_array = $GLOBALS['db']->getRow($sql);
    }
    return $return_array;
}
Ejemplo n.º 2
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;
    */
}
Ejemplo n.º 3
0
 $product['product_number'][$key] = empty($product['product_number'][$key]) ? empty($_CFG['use_storage']) ? 0 : $_CFG['default_storage'] : trim($product['product_number'][$key]);
 //库存
 //获取规格在商品属性表中的id
 foreach ($product['attr'] as $attr_key => $attr_value) {
     /* 检测:如果当前所添加的货品规格存在空值或0 */
     if (empty($attr_value[$key])) {
         continue 2;
     }
     $is_spec_list[$attr_key] = 'true';
     $value_price_list[$attr_key] = $attr_value[$key] . chr(9) . '';
     //$key,当前
     $id_list[$attr_key] = $attr_key;
 }
 $goods_attr_id = handle_goods_attr($product['goods_id'], $id_list, $is_spec_list, $value_price_list);
 /* 是否为重复规格的货品 */
 $goods_attr = sort_goods_attr_id_array($goods_attr_id);
 $goods_attr = implode('|', $goods_attr['sort']);
 if (check_goods_attr_exist($goods_attr, $product['goods_id'])) {
     continue;
     //sys_msg($_LANG['sys']['wrong'] . $_LANG['exist_same_goods_attr'], 1, array(), false);
 }
 //货品号不为空
 if (!empty($value)) {
     /* 检测:货品货号是否在商品表和货品表中重复 */
     if (check_goods_sn_exist($value)) {
         continue;
         //sys_msg($_LANG['sys']['wrong'] . $_LANG['exist_same_goods_sn'], 1, array(), false);
     }
     if (check_product_sn_exist($value)) {
         continue;
         //sys_msg($_LANG['sys']['wrong'] . $_LANG['exist_same_product_sn'], 1, array(), false);
Ejemplo n.º 4
0
/**
* 根据条形码获取对应商品信息
* @param array $info  条形码数组信息
*/
function get_goods_by_txm($info)
{
    global $db, $ecs;
    $sql = "select bc.*,g.* from " . $ecs->table('bar_code') . " as bc left join " . $ecs->table('goods') . " as g on bc.goods_id=g.goods_id where bc.bar_code in(" . implode(',', $info) . ")";
    $ret = $db->query($sql);
    $goodsinfo = array();
    while ($row = $db->fetchRow($ret)) {
        $attr_info = get_goods_attr_txm($row['goods_id'], $row['taypes']);
        //获取商品属性信息
        if (empty($attr_info['info'])) {
            $goods_number = $row['goods_number'];
            $attr_ids = '';
            $row['goods_attr'] = $row['goods_attr_id'] = $row['goods_attr_price'] = '';
        } else {
            $attr_ids = array_keys($attr_info['info']);
            $attr_ids = sort_goods_attr_id_array($attr_ids);
            //商品属性id排序
            $row['goods_attr_id'] = implode(',', $attr_ids['sort']);
            $row['goods_attr'] = $attr_info['info'];
            $row['goods_attr_price'] = is_array($attr_info['price']) ? array_sum($attr_info['price']) : 0;
            $goods_number = get_goods_nums_txm($row['goods_id'], $attr_ids['sort']);
            //货品总数量
        }
        $goodsinfo[$row['bar_code']]['goods_id'] = $row['goods_id'];
        $goodsinfo[$row['bar_code']]['goods_name'] = $row['goods_name'];
        $goodsinfo[$row['bar_code']]['goods_sn'] = $row['goods_sn'];
        $goodsinfo[$row['bar_code']]['product_id'] = '';
        $goodsinfo[$row['bar_code']]['goods_name'] = $row['goods_name'];
        $goodsinfo[$row['bar_code']]['market_price'] = $row['market_price'] + $row['goods_attr_price'];
        $goodsinfo[$row['bar_code']]['goods_price'] = get_final_price($row['goods_id'], 1, true, $attr_ids['sort']);
        //最终结算价格
        $goodsinfo[$row['bar_code']]['goods_number'] = intval($goods_number);
        $goodsinfo[$row['bar_code']]['goods_attr'] = $row['goods_attr'];
        $goodsinfo[$row['bar_code']]['goods_attr_id'] = $row['goods_attr_id'];
        $goodsinfo[$row['bar_code']]['goods_attr_price'] = $row['goods_attr_price'];
        $goodsinfo[$row['bar_code']]['goods_thumb'] = $row['goods_thumb'];
        $goodsinfo[$row['bar_code']]['goods_img'] = $row['goods_img'];
    }
    return $goodsinfo;
}
Ejemplo n.º 5
0
function get_goods_attr_id($goods_id, $attr_str)
{
    if (empty($attr_str)) {
        return '';
    } else {
        $attr_str = str_replace("\r", "", $attr_str);
        $attr_array = explode("\n", $attr_str);
        if (!is_array($attr_array)) {
            return '';
        }
        $attr_array = array_filter($attr_array);
        $return = "";
        foreach ($attr_array as $attr_temp) {
            $attr_temp = preg_replace("/\\[.+\\]/", "", $attr_temp);
            if ($attr_temp) {
                $attr_arr = explode(":", $attr_temp);
                $sql = "SELECT  a.attr_id  FROM " . $GLOBALS['ecs']->table('goods') . " AS g left join " . $GLOBALS['ecs']->table('attribute') . "  AS a on g.goods_type=a.cat_id WHERE g.goods_id='{$goods_id}' and a.attr_name='{$attr_arr['0']}' ";
                $attr_id = $GLOBALS['db']->getOne($sql);
                $sql = "SELECT goods_attr_id  FROM " . $GLOBALS['ecs']->table('goods_attr') . " WHERE goods_id='{$goods_id}' and attr_id='{$attr_id}' and attr_value='{$attr_arr['1']}' ";
                $goods_attr_id = $GLOBALS['db']->getOne($sql);
                $return .= $return ? "|" : "";
                $return .= $goods_attr_id;
            }
        }
        if ($return) {
            $goods_attr = explode("|", $return);
            $goods_attr = sort_goods_attr_id_array($goods_attr);
            $goods_attr = implode('|', $goods_attr['sort']);
            $return = $goods_attr;
        }
        return $return;
    }
}
Ejemplo n.º 6
0
 $error = array();
 $sql = "select bc.*,g.* from " . $ecs->table('bar_code') . " as bc left join " . $ecs->table('goods') . " as g on bc.goods_id=g.goods_id where bc.bar_code in(" . implode(',', $bar_info) . ")";
 $ret = $db->query($sql);
 while ($row = $db->fetchRow($ret)) {
     $attr_info = get_goods_attr_txm($row['goods_id'], $row['taypes']);
     //获取商品属性信息
     if (empty($attr_info['info'])) {
         //没有属性直接增加库存
         if ($row['goods_number'] < $_POST['number'][$row['bar_code']]) {
             $error[$row['bar_code']] = $_POST['number'][$row['bar_code']];
         } else {
             update_goods_store_num($row['goods_id'], 0 - $_POST['number'][$row['bar_code']]);
         }
     } else {
         $attr_ids = array_keys($attr_info['info']);
         $attr_ids = sort_goods_attr_id_array($attr_ids);
         //商品属性id排序
         $product_info = get_product_info_by_goods($row['goods_id'], $attr_ids['sort']);
         if ($product_info) {
             if ($product_info['product_number'] < $_POST['number'][$row['bar_code']]) {
                 $error[$row['bar_code']] = $_POST['number'][$row['bar_code']];
             } else {
                 $product_id = $product_info['product_id'];
                 $num = 0 - $_POST['number'][$row['bar_code']];
                 $sql = "UPDATE " . $ecs->table('products') . " SET product_number = product_number+" . $num . " WHERE product_id = " . $product_id;
                 $db->query($sql);
                 update_goods_store_num($row['goods_id'], $num);
             }
         } else {
             $error[$row['bar_code']] = $_POST['number'][$row['bar_code']];
         }
Ejemplo n.º 7
0
/**
* 获取当前商品对应的仓库信息
*/
function get_goods_send_stock($goods_id, $attr = '')
{
    $attr = trim($attr);
    if (!empty($attr)) {
        $attr = str_replace('|', ',', $attr);
        $attrids = explode(',', $attr);
        $goods_attr_array = sort_goods_attr_id_array($attrids);
        $attr = implode("|", $goods_attr_array['sort']);
        $tj = "and sgs.goods_attr='" . $attr . "'";
    } else {
        $tj = "";
    }
    $sql = "select sm.* from " . $GLOBALS['ecs']->table('store_goods_stock') . " as sgs , " . $GLOBALS['ecs']->table('store_shipping_region') . " as ssr, \n\t\t\t" . $GLOBALS['ecs']->table('store_main') . " as sm\n\t\t\twhere sgs.goods_id=" . $goods_id . " " . $tj . " and sm.store_id = sgs.store_id \n\t\t\tand ssr.province=" . $_COOKIE["region_1"] . " and ssr.city=" . $_COOKIE["region_2"] . " and ssr.district=" . $_COOKIE["region_3"] . " and ssr.xiangcun=" . $_COOKIE["region_4"] . " and ssr.store_id=sm.parent_id";
    $row = $GLOBALS['db']->getRow($sql);
    return $row;
}
Ejemplo n.º 8
0
/**
 * 获取商品对应城市下是否有库存
 * @param int $goodId  商品id
 * @param string $attrValue 商品属性组合串
 * @return int $stock 商品库存值
 */
function is_have_stock($goodId, $attrValue = '')
{
    global $db, $ecs;
    $where = " sgs.goods_id=" . intval($goodId);
    if (!empty($attrValue)) {
        if (!is_array($attrValue)) {
            $attrValue = str_replace('|', ',', $attrValue);
            $attrids = explode(',', $attrValue);
        } else {
            $attrids = $attrValue;
        }
        $goods_attr_array = sort_goods_attr_id_array($attrids);
        $attrValue = implode("|", $goods_attr_array['sort']);
        $where .= " AND sgs.goods_attr='" . $attrValue . "'";
    }
    $stock = 0;
    $address = cookie_to_str();
    $stockArray = get_address_by_store($address);
    if (is_array($stockArray)) {
        $sql = "SELECT sgs.store_number,sgs.store_id,sgs.goods_attr FROM " . $ecs->table('store_goods_stock') . " as sgs," . $ecs->table('store_main') . " as sm WHERE " . $where . "  and sm.parent_id in (" . implode(',', $stockArray) . ") and sgs.store_id = sm.store_id";
        $ret = $db->query($sql);
        if ($ret) {
            while ($row = $db->fetchRow($ret)) {
                if (!empty($attrValue) && $row['goods_attr'] == $attrValue && $row['store_number'] > 0) {
                    return $row['store_number'];
                }
                $stock = $stock > $row['store_number'] ? $stock : $row['store_number'];
            }
        }
    }
    return $stock;
}