Example #1
0
function get_sale_performance($start_time, $end_time)
{
    $result = get_admin_sql();
    $admin_id_str = $result['admin_id_str'];
    $sale_performance = $result['admin_id_arr'];
    $where = " WHERE order_status IN(1,5) AND shipping_status<>3 AND admin_id IN({$admin_id_str}) AND add_time>={$start_time} AND add_time<={$end_time}";
    $sql_select = 'SELECT admin_id,SUM(final_amount) as final_amount,COUNT(*) order_num FROM ' . $GLOBALS['ecs']->table('order_info') . $where . ' GROUP BY admin_id ';
    $order_list = $GLOBALS['db']->getAll($sql_select);
    if ($order_list != null) {
        foreach ($sale_performance as &$sale) {
            foreach ($order_list as $key => $order) {
                if ($sale['user_id'] == $order['admin_id']) {
                    $sale['final_amount'] = $order['final_amount'];
                    $sale['order_num'] = $order['order_num'];
                    if ($order['order_num']) {
                        $sale['average_amount'] = sprintf('%0.2f', $order['final_amount'] / $order['order_num']);
                    }
                    unset($order[$key]);
                }
            }
        }
    }
    foreach ($sale_performance as &$val) {
        $val['final_amount'] = empty($val['final_amount']) ? '0.00' : $val['final_amount'];
        $val['order_num'] = empty($val['order_num']) ? '0' : $val['order_num'];
        $val['average_amount'] = empty($val['average_amount']) ? '0.00' : $val['average_amount'];
    }
    //print_r($sale_performance);exit;
    $sale_amount = array();
    if ($sort_by == '' || $sort_by_final_amount) {
        foreach ($sale_performance as $key => &$val) {
            $sale_amount[$key] = $val['final_amount'];
        }
        if ($sale_amount) {
            array_multisort($sale_amount, SORT_DESC, $sale_performance);
        }
    }
    return $sale_performance;
}
Example #2
0
function get_sale_performance($start_time, $end_time)
{
    $result = get_admin_sql();
    $admin_id_str = $result['admin_id_str'];
    $sale_performance = $result['admin_id_arr'];
    $where = " WHERE order_status IN(1,5) AND shipping_status<>3 AND admin_id IN({$admin_id_str}) AND add_time>={$start_time} AND add_time<={$end_time}";
    $sql_select = 'SELECT admin_id,SUM(final_amount) as final_amount,COUNT(*) order_num FROM ' . $GLOBALS['ecs']->table('order_info') . $where . ' GROUP BY admin_id ';
    $order_list = $GLOBALS['db']->getAll($sql_select);
    if ($order_list != null) {
        foreach ($sale_performance as &$sale) {
            foreach ($order_list as $key => $order) {
                if ($sale['user_id'] == $order['admin_id']) {
                    $sale['final_amount'] = $order['final_amount'];
                    $sale['order_num'] = $order['order_num'];
                    unset($order[$key]);
                }
            }
        }
    }
    foreach ($sale_performance as &$val) {
        $val['final_amount'] = empty($val['final_amount']) ? '0.00' : $val['final_amount'];
        $val['order_num'] = empty($val['order_num']) ? '0' : $val['order_num'];
    }
    return $sale_performance;
}