<?php
/**
* ECSHOP 订单管理
* ============================================================================
* 版权所有 2005-2010 上海商派网络科技有限公司,并保留所有权利。
* 网站地址: http://www.ecshop.com;
* ----------------------------------------------------------------------------
* 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
* 使用;不允许对程序代码以任何形式任何目的的再发布。
* ============================================================================
* $Author: sxc_shop $
* $Id: order.php 17151 2010-05-05 08:58:23Z sxc_shop $
*/
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
require_once(ROOT_PATH . 'includes/lib_order.php');
require_once(ROOT_PATH . 'includes/lib_group.php');
/*------------------------------------------------------ */
//-- 订单查询
/*------------------------------------------------------ */
if ($_REQUEST['act'] == 'order_query')
{
/* 检查权限 */
admin_priv('order_view');
/* 载入配送方式 */
$smarty->assign('shipping_list', shipping_list());
/* 载入支付方式 */
$smarty->assign('pay_list', payment_list());
/* 载入国家 */
$smarty->assign('country_list', get_regions());
/* 载入订单状态、付款状态、发货状态 */
$smarty->assign('os_list', get_status_list('order'));
$smarty->assign('ps_list', get_status_list('payment'));
$smarty->assign('ss_list', get_status_list('shipping'));
/* 模板赋值 */
$smarty->assign('ur_here', $_LANG['03_order_query']);
$smarty->assign('action_link', array('href' => 'order.php?act=list', 'text' => $_LANG['02_order_list']));
/* 显示模板 */
assign_query_info();
$smarty->display('order_query.htm');
}
/*------------------------------------------------------ */
//-- 订单列表
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'list')
{
/* 检查权限 */
admin_priv('order_view');
/* 模板赋值 */
$smarty->assign('ur_here', $_LANG['02_order_list']);
$smarty->assign('action_link', array('href' => 'order.php?act=order_query', 'text' => $_LANG['03_order_query']));
$smarty->assign('status_list', $_LANG['cs']); // 订单状态
$smarty->assign('os_unconfirmed', OS_UNCONFIRMED);
$smarty->assign('cs_await_pay', CS_AWAIT_PAY);
$smarty->assign('cs_await_ship', CS_AWAIT_SHIP);
$smarty->assign('full_page', 1);
$order_list = order_list();
$smarty->assign('todaynum', get_today_ordernum());
$smarty->assign('order_list', $order_list['orders']);
$smarty->assign('filter', $order_list['filter']);
$smarty->assign('record_count', $order_list['record_count']);
$smarty->assign('page_count', $order_list['page_count']);
$smarty->assign('sort_order_time', '<img src="images/sort_desc.gif">');
/* 显示模板 */
assign_query_info();
$smarty->display('order_list.htm');
}
/*------------------------------------------------------ */
//-- 排序、分页、查询
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'query')
{
/* 检查权限 */
admin_priv('order_view');
$order_list = order_list();
$smarty->assign('order_list', $order_list['orders']);
$smarty->assign('filter', $order_list['filter']);
$smarty->assign('record_count', $order_list['record_count']);
$smarty->assign('page_count', $order_list['page_count']);
$sort_flag = sort_flag($order_list['filter']);
$smarty->assign($sort_flag['tag'], $sort_flag['img']);
make_json_result($smarty->fetch('order_list.htm'), '', array('filter' => $order_list['filter'], 'page_count' => $order_list['page_count']));
}
/*------------------------------------------------------ */
//-- 订单详情页面
/*------------------------------------------------------ */
elseif ($_REQUEST['act'] == 'info')
{
/* 根据订单id或订单号查询订单信息 */
if (isset($_REQUEST['order_id']))
{
$order_id = intval($_REQUEST['order_id']);
$order = order_info($order_id);
}
elseif (isset($_REQUEST['order_sn']))
{
$order_sn = trim($_REQUEST['order_sn']);
$order = order_info(0, $order_sn);
}
else
{
/* 如果参数不存在,退出 */
die('invalid parameter');
}
/* 如果订单不存在,退出 */
if (empty($order))
{
die('order does not exist');
}
/* 根据订单是否完成检查权限 */
if (order_finished($order))
{
admin_priv('order_view_finished');
}
else
{
admin_priv('order_view');
}
/* 如果管理员属于某个办事处,检查该订单是否也属于这个办事处 */
$sql = "SELECT agency_id FROM " . $ecs->table('admin_user') . " WHERE user_id = '$_SESSION[admin_id]'";
$agency_id = $db->getOne($sql);
if ($agency_id > 0)
{
if ($order['agency_id'] != $agency_id)
{
sys_msg($_LANG['priv_error']);
}
}
/* 取得上一个、下一个订单号 */
if (!empty($_COOKIE['ECSCP']['lastfilter']))
{
$filter = unserialize(urldecode($_COOKIE['ECSCP']['lastfilter']));
if (!empty($filter['composite_status']))
{
$where = '';
//综合状态
switch($filter['composite_status'])
{
case CS_AWAIT_PAY :
$where .= order_query_sql('await_pay');
break;
case CS_AWAIT_SHIP :
$where .= order_query_sql('await_ship');
break;
case CS_FINISHED :
$where .= order_query_sql('finished');
break;
default:
if ($filter['composite_status'] != -1)
{
$where .= " AND o.order_status = '$filter[composite_status]' ";
}
}
}
}
$sql = "SELECT MAX(order_id) FROM " . $ecs->table('order_info') . " as o WHERE order_id < '$order[order_id]'";
if ($agency_id > 0)
{
$sql .= " AND agency_id = '$agency_id'";
}
if (!empty($where))
{
$sql .= $where;
}
$smarty->assign('prev_id', $db->getOne($sql));
$sql = "SELECT MIN(order_id) FROM " . $ecs->table('order_info') . " as o WHERE order_id > '$order[order_id]'";
if ($agency_id > 0)
{
$sql .= " AND agency_id = '$agency_id'";
}
if (!empty($where))
{
$sql .= $where;
}
$smarty->assign('next_id', $db->getOne($sql));
/* 取得用户名 */
if ($order['user_id'] > 0)
{
$user = user_info($order['user_id']);
if (!empty($user))
{
$order['user_name'] = $user['user_name'];
}
}
/* 取得所有办事处 */
$sql = "SELECT agency_id, agency_name FROM " . $ecs->table('agency');
$smarty->assign('agency_list', $db->getAll($sql));
/* 取得区域名 */
$sql = "SELECT concat(IFNULL(c.region_name, ''), ' ', IFNULL(p.region_name, ''), " .
"' ', IFNULL(t.region_name, ''), ' ', IFNULL(d.region_name, '')) AS region " .
"FROM " . $ecs->table('order_info') . " AS o " .
"LEFT JOIN " . $ecs->table('region') . " AS c ON o.country = c.region_id " .
"LEFT JOIN " . $ecs->table('region') . " AS p ON o.province = p.region_id " .
"LEFT JOIN " . $ecs->table('region') . " AS t ON o.city = t.region_id " .
"LEFT JOIN " . $ecs->table('region') . " AS d ON o.district = d.region_id " .
"WHERE o.order_id = '$order[order_id]'";
$order['region'] = $db->getOne($sql);
/* 格式化金额 */
if ($order['order_amount'] < 0)
{
$order['money_refund'] = abs($order['order_amount']);
$order['formated_money_refund'] = price_format(abs($order['order_amount']));
}
/*