ECSHOP增加城市分站功能
  • 分类:经验分享
  • 发表:2016-04-13
  • 围观(3,842)
  • 评论(0)

适合所有ECSHOP内核的系统,比如小 京东,大商创,等等

1、打开include/lib_common.php,在尾部添加函数

/**
 * 显示当前城市
 *
 * @return  array
 */
function s_city()
{
	$s_city_id = $_SESSION['s_city_id'];
	$s_city_name = $_SESSION['s_city_name'];
	if (empty($s_city_id) && empty($s_city_name))
	{
		$s_city_ip = real_ip();
		$url = 'http://ip.taobao.com/service/getIpInfo.php?ip=' . $s_city_ip;
    	$json = file_get_contents($url);
    	$arr = json_decode($json, true);
		if ($arr['data']['country_id']=="-1" || $arr['data']['city']=="")
		{
			$s_city_name = "LAN";	
		}
		else
		{
			$s_city_name = $arr['data']['city'];
			$s_city_name = str_replace("区","",str_replace("市","",$s_city_name));
			$sql = "SELECT region_id FROM " .$GLOBALS['ecs']->table('region'). " WHERE region_name Like '$s_city_name%'";
			$s_city_id = $GLOBALS['db']->getOne($sql);		
			$_SESSION['s_city_id'] = $s_city_id;
			$_SESSION['s_city_name'] = $s_city_name;
		}		
	}//echo $s_city_ip;
	return $s_city_name;
}

2、打开themes/[模板目录]/library/page_head.lbi,在合适位置添加:

<div class="city">
<span>{$s_city}</span><em><a href="/s_area.php">选择其它城市</a></em>
</div>

上面的样式南非要自己设,,不多说,,

并在themes/[模板目录]下新建一个模板文件s_area.dwt,模板的核心代码是:

<!-- {foreach from=$aera_list item=aera} -->
<dl class="aera_s">
<dt><a href="#top" class="fh">返回</a><a href="/s_area.php?city_id={$aera.region_id}">{$aera.region_name}</a></dt>
<dd>
<!-- {foreach from=$aera.city item=aeras} -->
<a href="/s_area.php?city_id={$aeras.region_id}">{$aeras.region_name}</a>
<!-- {/foreach} -->
<div class="clear"></div>
</dd>
<div class="clear"></div>
</dl>
<!-- {/foreach} -->

其它的,如模板头,模板尾什么的,根据自身需要修改。

3、在根目录下新建s_area.php文件,核心代码是:

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
header('Content-type: text/html; charset=' . EC_CHARSET);

$s_city_id = $_REQUEST['city_id'];

if (empty($s_city_id))
{
	if ((DEBUG_MODE & 2) != 2)
	{
		$smarty->caching = true;
	}
	
	if (!$smarty->is_cached($templates, $cache_id))
	{
		/* 模板赋值 */
		assign_template();
		$position = assign_ur_here();
		$smarty->assign('page_title',       $position['title']);       // 页面标题
		$smarty->assign('show_marketprice', $_CFG['show_marketprice']);
		$smarty->assign('sort_goods_arr',   $sort_goods_arr);          // 商品列表
		$smarty->assign('categories_pro',  get_categories_tree_pro()); // 分类树加强版/* 周改
		$smarty->assign('s_city',      s_city()); // 城市选择
		$smarty->assign('aera_list',       s_get_regions());
	}
	$smarty->display("s_area.dwt", $cache_id);
}
else
{
	$s_city_id = mysql_like_quote($s_city_id);
	$sql = "SELECT region_name FROM " .$GLOBALS['ecs']->table('region'). " WHERE region_id=$s_city_id";
	$s_city_name = $GLOBALS['db']->getOne($sql);
	if(empty($s_city_name))	{
		Header("Location: /s_area.php");
	}
	$_SESSION['s_city_id'] = $s_city_id;
	$_SESSION['s_city_name'] = $s_city_name;
	clear_all_files($ext = '');
	Header("Location: /index.php");
}


function s_get_regions($parent)
{
	$aera_list=get_regions(1,1);
	foreach ($aera_list AS $k => $v)
	{
		$aera_list[$k]['city'] = get_regions(2,$v['region_id']);
	}
	return $aera_list;
}

 

这个放在s_area.php页面的下面

上面只是主要代码,应该放哪,怎么放,还要根据实际需要!

上面只是主要代码,应该放哪,怎么放,还要根据实际需要!

上面只是主要代码,应该放哪,怎么放,还要根据实际需要!

 

示范样式:

.city{float:left; padding:35px 15px 0px 15px; width:75px; margin:0px 10px 0px 10px;}
.city span{ font-size:18px; display:block; border-bottom:1px solid #DDD; padding-bottom:8px; margin-bottom:5px; text-align:center;}
.city em{ display:block; text-align:center; color:#999;}
dl.aera_s{ display:block; clear:both; margin-bottom:15px; border:1px solid #DDD;}
dl.aera_s dt { height:30px; padding-left:10px; font-size:14px; font-weight:bold; background:url(../images/title_back.jpg); line-height:30px;}
dl.aera_s dt a.fh{ font-size:12px; color:#999; font-weight:normal; float:right; margin-right:15px;}
dl.aera_s dd { padding:0px 10px; min-height:30px;}
dl.aera_s dd a{ float:left; margin-right:15px; line-height:30px; color:#333;}
dl.aera_s a:hover{ color:#CF010E;}

注意,这个功能只是实现自动识别浏览者所在地区,并且提供地区选择。并不能实现真实的商品、广告按地区划分,,适合一部分客户需求

这个思路同样也用到微信端,,看怎么用了。。

Top