示例#1
0
function address_to_store()
{
    $_COOKIE['region_3'] = 0;
    //把第三级设置成空
    $_COOKIE['region_4'] = 0;
    //把第四级设置成空
    $address = cookie_to_str();
    //组织地址
    $stockArray = get_address_by_store($address);
    //查询地址对应哪些仓库
    $goodsIds = get_index_goods($stockArray);
    //获取仓库下的所有商品id
    return $goodsIds;
}
示例#2
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);
    $attrValue = trim($attrValue);
    $attrValue = str_replace(',', '|', $attrValue);
    if (!empty($attrValue)) {
        $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;
}
示例#3
0
/**
 * 获取店铺店铺街中的店铺
 */
function get_all_supplier($address)
{
    global $tpl;
    $is_search = 0;
    //是否是搜索过来的
    $filter['id'] = empty($_REQUEST['id']) ? 0 : intval($_REQUEST['id']);
    $filter['keywords'] = isset($_REQUEST['keywords']) ? trim(addslashes(htmlspecialchars($_REQUEST['keywords']))) : '';
    $filter['sort_by'] = empty($_REQUEST['sort_by']) ? 'sort_order' : trim($_REQUEST['sort_by']);
    $filter['sort_order'] = empty($_REQUEST['sort_order']) ? 'ASC' : trim($_REQUEST['sort_order']);
    /* 分页大小 */
    $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']);
    if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) {
        $filter['page_size'] = intval($_REQUEST['page_size']);
    } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) {
        $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']);
    } else {
        $filter['page_size'] = 13;
    }
    $filter['start'] = ($filter['page'] - 1) * $filter['page_size'];
    $where = " where status=1 and is_show=1 ";
    $store_ids = get_address_by_store($address);
    $store_ids = array_unique($store_ids);
    if (count($store_ids) > 0) {
        $supplierid = $GLOBALS['db']->getColCached('select st.supplier_id from ' . $GLOBALS['ecs']->table('store_main') . ' as sm left join ' . $GLOBALS['ecs']->table('store_type') . ' as st on sm.supplier_id = st.type  where sm.store_id in (' . implode(',', $store_ids) . ')');
        $supplierid = array_filter(array_unique($supplierid));
        if (count($supplierid) > 0) {
            $where .= ' and supplier_id in (' . implode(',', $supplierid) . ') ';
        } else {
            return array();
        }
    }
    if ($filter['id']) {
        $where .= ' and supplier_type=' . $filter['id'];
    }
    if ($filter['keywords'] && $filter['keywords'] != '请输入关键词') {
        $is_search = 1;
        $tpl = 'search_store.dwt';
        $GLOBALS['smarty']->assign('search_keywords', stripslashes(htmlspecialchars_decode($_REQUEST['keywords'])));
        $where .= " and supplier_id in(SELECT DISTINCT supplier_id\n\t\t\t\tFROM " . $GLOBALS['ecs']->table('supplier_shop_config') . " AS ssc\n\t\t\t\tWHERE (\n\t\t\t\tcode = 'shop_name'\n\t\t\t\tAND value LIKE '%" . $filter['keywords'] . "%'\n\t\t\t\t)\n\t\t\t\tOR (\n\t\t\t\tcode = 'shop_keywords'\n\t\t\t\tAND value LIKE '%" . $filter['keywords'] . "%'\n\t\t\t\t))";
    }
    $GLOBALS['smarty']->assign('issearch', $is_search);
    /* 记录总数 */
    $sql = "SELECT COUNT(*) FROM " . $GLOBALS['ecs']->table('supplier_street') . " {$where}";
    $filter['record_count'] = $GLOBALS['db']->getOne($sql);
    $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1;
    $sql = "SELECT * " . " FROM " . $GLOBALS['ecs']->table('supplier_street') . " {$where}" . " ORDER BY {$filter['sort_by']} {$filter['sort_order']} " . " LIMIT " . $filter['start'] . ",{$filter['page_size']}";
    $arr = $GLOBALS['db']->getAll($sql);
    foreach ($arr as $key => $val) {
        $shopinfo = $GLOBALS['db']->getAll("select code,value from " . $GLOBALS['ecs']->table('supplier_shop_config') . " where supplier_id=" . $val['supplier_id'] . " and code in('shop_closed','shop_name','shop_keywords')");
        foreach ($shopinfo as $k => $v) {
            if ($is_search) {
                $v['value'] = str_replace($filter['keywords'], "<font color=red>" . $filter['keywords'] . "</font>", $v['value']);
            }
            $arr[$key][$v['code']] = $v['value'];
        }
    }
    return array('shops' => $arr, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
}
示例#4
0
/**
 * 获取商品对应城市下是否有库存
 * @param int $goodId  商品id
 * @param string $attrValue 商品属性组合串
 * @param book  $isapp
 * @return int $stock 商品库存值
 */
function is_have_stock($goodId, $attrValue = '', $isapp = false)
{
    global $db, $ecs;
    $where = " sgs.goods_id=" . intval($goodId);
    //$attrValue = trim($attrValue);
    //$attrValue = str_replace(',','|',$attrValue);
    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;
    $info = array();
    $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,sm.store_name 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) {
                    if ($isapp) {
                        return array('attr_num' => $row['store_number'], 'c_name' => $row['store_name']);
                    } else {
                        return $row['store_number'];
                    }
                }
                $stock = $stock > $row['store_number'] ? $stock : $row['store_number'];
                if ($isapp) {
                    $info = array('attr_num' => $stock, 'c_name' => $row['store_name']);
                }
            }
        }
    }
    return $isapp ? $info : $stock;
}
示例#5
0
function get_address_by_store($address)
{
    global $db, $ecs;
    while (count($address) > 1) {
        $where = '';
        foreach ($address as $k => $v) {
            $where .= " and " . $k . "=" . $v;
        }
        $sql = "select store_id from " . $ecs->table('store_shipping_region') . " where 1" . $where;
        $result = $db->getColCached($sql);
        if (count($result) > 0) {
            return array_unique($result);
        } else {
            get_address_by_store(array_pop($address));
        }
    }
    return false;
}