ecshop我的订单里查询指定时间段订单,在前台用户中心
一、修改前台静态页面
…/themes/default/user_transaction.dwt 第178行左右,我的订单部分开始更改,增加如下
<!–#订单列表界面 start–>
<!– {if $action eq ‘order_list’} –>
<script type=”text/javascript” src=”js/calendar.php?lang={$cfg_lang}”></script>
<link href=”js/calendar/calendar.css” rel=”stylesheet” type=”text/css” />
<h5><span>{$lang.label_order}</span></h5>
<script type=”text/javascript”>
{foreach from=$lang.profile_js item=item key=key}
var {$key} = “{$item}”;
{/foreach}
</script>
<div>
<form action=”user.php” method=”post” name=”checkDate”>
<input type=”hidden” name=”act” value=”order_list” />
{$lang.start_date}
<input name=”start_date” id=”start_date” value=”{$start_date}” style=”width:80px;” />
{$lang.end_date}
<input name=”end_date” id=”end_date” value=”{$end_date}” style=”width:80px;” />
<input type=”submit” name=”submit” value=”{$lang.access_query}” />
</form>
</div>
二、配置语言文件
languages\zh_cn\user.php,增加
$_LANG['start_date'] = ‘开始日期’;
$_LANG['end_date'] = ‘结束日期’;
$_LANG['access_query'] = ‘查询’;
$_LANG['profile_js']['start_time_check'] = ‘请您输入起始时间’;
三、修改提示语言,当没有输入起始时间的时候需要提示
ecshop\js\user.js,增加
//搜索订单时间提示
function checkstartDate()
{
var start = document.getElementByIdx_x(“start_date”).value;
var end = document.getElementByIdx_x(“end_date”).value;
if ( ! start)
{
alert(start_time_check);
return false;
}
return true;
}
三、修改执行文件
ecshop\user.php,大约786行
elseif ($action == ‘order_list’)
{
$start_time = strtotime($_POST['start_date']) ? strtotime($_POST['start_date']) : $_GET['start_date'];
$end_time = strtotime($_POST['end_date']) ? strtotime($_POST['end_date']) : $_GET['end_date'];
include_once(ROOT_PATH . ‘includes/lib_transaction.php’);
$page = isset($_REQUEST['page']) ? intval($_REQUEST['page']) : 1;
if($start_time && $end_time){
$where = ” AND add_time BETWEEN ‘”.$start_time.”‘ AND ‘”.$end_time.”‘”;
$page_ary = array(‘act’ => $action, ‘start_date’ =>$start_time, ‘end_date’ => $end_time);
}elseif($start_time){
$end_time = time();
$where = ” AND add_time BETWEEN ‘”.$start_time.”‘ AND ‘”.$end_time.”‘”;
$page_ary = array(‘act’ => $action, ‘start_date’ =>$start_time);
}else{
$where = ” “;
$page_ary = array(‘act’ => $action);
}
$record_count = $db->getOne(“SELECT COUNT(*) FROM ” .$ecs->table(‘order_info’). ” WHERE user_id = ‘$user_id’”.$where);
$pager = get_pager(‘user.php’, $page_ary, $record_count, $page);
$orders = get_user_orders($user_id, $pager['size'], $pager['start'], $start_time, $end_time);
$merge = get_user_merge($user_id);
if($start_time || $end_time){
if(!$end_time){
$end_time = time();
}
$smarty->assign(‘start_date’, date(‘Y-m-d’,$start_time));
$smarty->assign(‘end_date’, date(‘Y-m-d’,$end_time));
}
$smarty->assign(‘merge’, $merge);
$smarty->assign(‘pager’, $pager);
$smarty->assign(‘orders’, $orders);
$smarty->display(‘user_transaction.dwt’);
}
第三步,修改get_user_orders(),ecshop\includes\lib_transaction.php
function get_user_orders($user_id, $num = 10, $start = 0, $start_time, $end_time)
{
$arr = array();
if($start_time && $end_time){
$where = ” AND add_time BETWEEN ‘”.$start_time.”‘ AND ‘”.$end_time.”‘”;
}elseif($start_time){
$end_date = time();
$where = ” AND add_time BETWEEN ‘”.$start_time.”‘ AND ‘”.$end_date.”‘”;
}else{
$where = ” “;
}
$sql = “SELECT order_id, order_sn, order_status, shipping_status, pay_status, add_time, ” .
“(goods_amount + shipping_fee + insure_fee + pay_fee + pack_fee + card_fee + tax – discount) AS total_fee “.
” FROM ” .$GLOBALS['ecs']->table(‘order_info’) .
” WHERE user_id = ‘$user_id’”.$where.” ORDER BY add_time DESC”;
$res = $GLOBALS['db']->SelectLimit($sql, $num, $start);
好了