修正Ecshop后台订单统计数据不准确

2016-09-07 22:02 来源:www.chinab4c.com 作者:ecshop专家

Ecshop本身源码写得就有问题。打开order_status.php文件,翻到最下方,看function get_orderinfo($start_date, $end_date)的定义,其中所有的sql都用了下面的代码:
 
 function get_orderinfo($start_date, $end_date)
 {
    $order_info = array();
 
    /* 未确认订单数 */
    $sql = 'SELECT COUNT(*) AS unconfirmed_num FROM ' .$GLOBALS['ecs']->table('order_info').
           " WHERE order_status = '" .OS_UNCONFIRMED. "' AND add_time >= '$start_date'".
           " AND add_time < '" . ($end_date + 86400) . "'"; 
很显然,这里有个很明显的逻辑错误,即$end_date+86400,除非这里用户选择的开始时间和结束时间是同一天,否则没有必要加上86400(86400秒等于1天),这个错误结果会导致最后的订单统计数量已经不是在指定时间段内的数据,而是指定的时间后再加上一天。
 
 
将无用的已确认订单统计代码改成已支付的统计代码:
 
/* 已确认订单数 */
    $sql = 'SELECT COUNT(*) AS confirmed_num FROM ' .$GLOBALS['ecs']->table('order_info').
           " WHERE order_status = '" .OS_CONFIRMED. "' AND shipping_status NOT ". db_create_in(array(SS_SHIPPED, SS_RECEIVED)) . " AND pay_status NOT" . db_create_in(array(PS_PAYED, PS_PAYING)) ." AND add_time >= '$start_date'".
           " AND add_time < '" . ($end_date + 86400) . "'";
    $order_info['confirmed_num'] = $GLOBALS['db']->getOne($sql);
改成:
 
/* by zuimoban.com 已支付订单数 */
    $sql = 'SELECT COUNT(*) AS confirmed_num FROM ' .$GLOBALS['ecs']->table('order_info').
           " WHERE pay_status =" . PS_PAYED ." AND shipping_status NOT" . db_create_in(array(SS_SHIPPED, SS_RECEIVED)) ." AND add_time >= '$start_date'".
           " AND add_time < $end_date";
    $order_info['confirmed_num'] = $GLOBALS['db']->getOne($sql);
 
(责任编辑:chinab4c)