Example #1
0
function getRebateOrderMoney($rid)
{
    global $ecs, $db;
    $back_and = '';
    if (($back_order_id = getBackOrderByRebate($rid)) != false) {
        //获取退货订单中相关订单
        $back_and = "and order_id not in(" . implode(',', $back_order_id) . ")";
    }
    $pay_id = getPayHoudaofukuan();
    //获取货到付款的id
    //获取全部订单金额
    $sql = "select (" . order_amount_field() . ") AS total_fee,pay_id,order_id from " . $ecs->table('order_info') . " where rebate_id=" . $rid . " {$back_and} and rebate_ispay=2";
    $query = $db->query($sql);
    $online = $onout = 0;
    $online_ids = $onout_ids = array();
    while ($row = $db->fetchRow($query)) {
        if ($row['pay_id'] == $pay_id) {
            //货到付款
            $onout += $row['total_fee'];
            $onout_ids[] = $row['order_id'];
        } else {
            //在线支付
            $online += $row['total_fee'];
            $online_ids[] = $row['order_id'];
        }
    }
    if (count($onout_ids) > 0) {
        //货到付款订单当中有商品发生的退货
        $sql = "select (goods_price * is_back) as price_out from " . $ecs->table('order_goods') . " where order_id in(" . implode(',', $onout_ids) . ")";
        $out_price = $db->getOne($sql);
        $onout = $onout - $out_price;
    }
    if (count($online_ids) > 0) {
        //在线支付订单当中有商品发生退货
        $sql = "select (goods_price * is_back) as price_out from " . $ecs->table('order_goods') . " where order_id in(" . implode(',', $online_ids) . ")";
        $line_price = $db->getOne($sql);
        $online = $online - $line_price;
    }
    return array('online' => $online, 'onout' => $onout);
}
Example #2
0
function getRebateOrderMoney($rid)
{
    global $ecs, $db;
    $back_and = '';
    if (($back_order_id = getBackOrderByRebate($rid)) != false) {
        //获取退货订单中相关订单
        $back_and = "and order_id not in(" . implode(',', $back_order_id) . ")";
    }
    $pay_id = getPayHoudaofukuan();
    //获取货到付款的id
    $sql = "select (" . order_amount_field() . ") AS total_fee,pay_id from " . $ecs->table('order_info') . " where rebate_id=" . $rid . " {$back_and} and rebate_ispay=2";
    $query = $db->query($sql);
    $online = $onout = 0;
    while ($row = $db->fetchRow($query)) {
        if ($row['pay_id'] == $pay_id) {
            //货到付款
            $onout += $row['total_fee'];
        } else {
            //在线支付
            $online += $row['total_fee'];
        }
    }
    return array('online' => $online, 'onout' => $onout);
}
function getOkOrder()
{
    global $ecs, $db, $rebate;
    $result = get_filter();
    if ($result === false) {
        $filter['rid'] = $rid = isset($_REQUEST['rid']) && intval($_REQUEST['rid']) > 0 ? intval($_REQUEST['rid']) : 0;
        $filter['add_time_start'] = !empty($_REQUEST['add_time_start']) ? local_strtotime($_REQUEST['add_time_start']) : 0;
        $filter['add_time_end'] = !empty($_REQUEST['add_time_end']) ? local_strtotime($_REQUEST['add_time_end'] . " 23:59:59") : 0;
        $filter['order_sn'] = isset($_REQUEST['order_sn']) ? trim($_REQUEST['order_sn']) : '';
        //$and = ' rebate_id='.$rid.' and shipping_status in ('.SS_SHIPPED.','.SS_RECEIVED.')';
        $and = ' store_rebate_id=' . $rid;
        //$hpay_id = getPayHoudaofukuan();
        //if($hpay_id){
        //$and .= ' and pay_id !='.$hpay_id.' ';
        //}
        $back_order_id = getBackOrderByRebate($rid);
        if (!empty($back_order_id)) {
            $notin = " and order_id not in(" . implode(',', $back_order_id) . ")";
        } else {
            $notin = '';
        }
        $and .= $notin;
        $and .= $filter['add_time_start'] ? " AND add_time >= '" . $filter['add_time_start'] . "' " : " ";
        $and .= $filter['add_time_end'] ? " AND add_time <= '" . $filter['add_time_end'] . "' " : " ";
        $and .= $filter['order_sn'] ? " AND order_sn = '" . $filter['order_sn'] . "' " : " ";
        /* 分页大小 */
        $filter['page'] = empty($_REQUEST['page']) || intval($_REQUEST['page']) <= 0 ? 1 : intval($_REQUEST['page']);
        if (isset($_REQUEST['page_size']) && intval($_REQUEST['page_size']) > 0) {
            $filter['page_size'] = intval($_REQUEST['page_size']);
        } elseif (isset($_COOKIE['ECSCP']['page_size']) && intval($_COOKIE['ECSCP']['page_size']) > 0) {
            $filter['page_size'] = intval($_COOKIE['ECSCP']['page_size']);
        } else {
            $filter['page_size'] = 15;
        }
        //总数
        $sql = "select count(order_id) from " . $ecs->table('order_info') . " where " . $and;
        $filter['record_count'] = $GLOBALS['db']->getOne($sql);
        $filter['page_count'] = $filter['record_count'] > 0 ? ceil($filter['record_count'] / $filter['page_size']) : 1;
        //记录
        $sql = "select order_id, order_sn, add_time, order_status, shipping_status, order_amount, money_paid," . "pay_status, consignee, address, email, tel, extension_code, extension_id, shipping_time, store_rebate_ispay, " . "(" . order_amount_field() . ") AS total_fee " . "from " . $ecs->table('order_info') . " where " . $and . " LIMIT " . ($filter['page'] - 1) * $filter['page_size'] . ",{$filter['page_size']}";
        //echo $sql;
        set_filter($filter, $sql);
    } else {
        $sql = $result['sql'];
        $filter = $result['filter'];
    }
    $query = $db->query($sql);
    $ret = array();
    while ($row = $db->fetchRow($query)) {
        $is_order = $is_shipping = $is_pay = 0;
        $row['formated_order_amount'] = price_format($row['order_amount']);
        $row['formated_money_paid'] = price_format($row['money_paid']);
        $row['formated_rebate_fee'] = getGoodsOrderRebatePrice($row['order_id']);
        $row['formated_rebate_fee'] = 0 - price_format($row['formated_rebate_fee'] * $rebate['rebate'] / 100);
        $row['formated_total_fee'] = price_format($row['total_fee']);
        $row['short_order_time'] = local_date('Y-m-d H:i', $row['add_time']);
        $row['is_rebeat'] = $row['datas'] = 0;
        //订单状态
        if ($row['order_status'] == OS_CONFIRMED || $row['order_status'] == OS_SPLITED) {
            $is_order = 1;
        }
        //配送状态
        if ($row['shipping_status'] == SS_SHIPPED) {
            $is_shipping = 1;
        }
        if ($row['shipping_status'] == SS_RECEIVED) {
            $row['is_rebeat'] = 1;
        }
        //支付状态
        if ($row['pay_status'] == PS_PAYED) {
            $is_pay = 1;
        }
        if ($is_order && $is_shipping && $is_pay) {
            $cha = datecha($row['shipping_time']);
            $row['datas'] = $GLOBALS['_CFG']['okgoods_time'] - $cha;
            if ($row['datas'] <= 0) {
                $row['is_rebeat'] = 1;
            }
        }
        if ($row['store_rebate_ispay'] == 2) {
            $row['is_rebeat'] = 0;
        }
        $ret[$row['order_id']] = $row;
    }
    //echo "<pre>";
    //print_r($ret);
    $arr = array('orders' => $ret, 'filter' => $filter, 'page_count' => $filter['page_count'], 'record_count' => $filter['record_count']);
    return $arr;
}