ecshop后台订单列表显示IP和地理位置

效果如下:

QQ图片20140105091643

思路:利用ecshop的ecs_geoip($ip)获取IP对应的地理位置函数,在数据库order_info表中增加一个字段ip_address存放用户提交订单时提交的ip地址,后台订单管理php文件中增加查询条件获取ip和地理位置,后台订单模板文件order_list.htm中增加和显示ip地理位置。

开发前,请先阅读《ecshop更新IP库操作》,按照该文章的步骤做好准备工作,升级ecshop自带的陈旧的IP库。

1,在数据库order_info表中增加一个字段ip_address存放用户提交订单时提交的ip地址

ALTER TABLE `ecs_order_info` ADD `ip_address` VARCHAR( 15 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL DEFAULT '';

2,前台 flow.php,添加获取IP并插入数据库

$order = array(
	'ip_address'      => real_ip(),//插入用户的IP地址	
	'shipping_id'     => intval($_POST['shipping']),
	'pay_id'          => intval($_POST['payment']),
	'pack_id'         => isset($_POST['pack']) ? intval($_POST['pack']) : 0,
	'card_id'         => isset($_POST['card']) ? intval($_POST['card']) : 0,
	'card_message'    => trim($_POST['card_message']),
	'surplus'         => isset($_POST['surplus']) ? floatval($_POST['surplus']) : 0.00,
	'integral'        => isset($_POST['integral']) ? intval($_POST['integral']) : 0,
	'bonus_id'        => isset($_POST['bonus']) ? intval($_POST['bonus']) : 0,
	'need_inv'        => empty($_POST['need_inv']) ? 0 : 1,
	'inv_type'        => $_POST['inv_type'],
	'inv_payee'       => trim($_POST['inv_payee']),
	'inv_content'     => $_POST['inv_content'],
	'postscript'      => trim($_POST['postscript']),
	'how_oos'         => isset($_LANG['oos'][$_POST['how_oos']]) ? addslashes($_LANG['oos'][$_POST['how_oos']]) : '',
	'need_insure'     => isset($_POST['need_insure']) ? intval($_POST['need_insure']) : 0,
	'user_id'         => $_SESSION['user_id'],
	'add_time'        => gmtime(),
	'order_status'    => OS_UNCONFIRMED,
	'shipping_status' => SS_UNSHIPPED,
	'pay_status'      => PS_UNPAYED,
	'agency_id'       => get_agency_by_regions(array($consignee['country'], $consignee['province'], $consignee['city'], $consignee['district']))
	);

3,admin/order.php,添加查询IP

/* 查询 */
$sql = "SELECT o.order_id, o.order_sn, o.add_time, o.order_status, o.shipping_status, o.order_amount, o.money_paid, o.ip_address," .
/* 格式话数据 */
foreach ($row AS $key => $value)
{
	$row[$key]['formated_order_amount'] = price_format($value['order_amount']);
	$row[$key]['formated_money_paid'] = price_format($value['money_paid']);
	$row[$key]['formated_total_fee'] = price_format($value['total_fee']);
	$row[$key]['short_order_time'] = local_date('m-d H:i', $value['add_time']);
	
	$ip_area = ecs_geoip($row[$key]['ip_address']); //获取IP对应的地理位置
	empty($row[$key]['ip_address']) ? '' : $row[$key]['ip_address'] .= ' [ ' . $ip_area . ' ]';
	
	if ($value['order_status'] == OS_INVALID || $value['order_status'] == OS_CANCELED)
	{
		/* 如果该订单为无效或取消则显示删除链接 */
		$row[$key]['can_remove'] = 1;
	}
	else
	{
		$row[$key]['can_remove'] = 0;
	}
}

4,admin/templates/order_list.htm,添加显示IP

<th><a href="javascript:listTable.sort('add_time', 'DESC'); ">{$lang.order_time}</a>{$sort_order_time}</th>
<th><a href="javascript:listTable.sort('consignee', 'DESC'); ">{$lang.consignee}</a>{$sort_consignee}</th>

<th><a href="javascript:listTable.sort('ip_address', 'DESC'); ">{$lang.ip_address}</a>{$sort_ip_address}</th><!--IP地址标题-->

<th><a href="javascript:listTable.sort('total_fee', 'DESC'); ">{$lang.total_fee}</a>{$sort_total_fee}</th>
<th><a href="javascript:listTable.sort('order_amount', 'DESC'); ">{$lang.order_amount}</a>{$sort_order_amount}</th>
    <td align="left" valign="top"><a href="mailto:{$order.email}"> {$order.consignee|escape}</a>{if $order.tel} [TEL: {$order.tel|escape}]{/if} <br />{$order.address|escape}</td>
	
	<td align="left" valign="top" nowrap="nowrap">{$order.ip_address}</td><!--用户IP和位置--> 
	 
    <td align="right" valign="top" nowrap="nowrap">{$order.formated_total_fee}</td>
    <td align="right" valign="top" nowrap="nowrap">{$order.formated_order_amount}</td>

5,admin/languages/zh_cn/order.php,添加语言项

$_LANG['ip_address'] = 'IP地址';

End!

阅读剩余
THE END