Exemplo n.º 1
0
/**
 * 合并订单
 * @param   string  $from_order_sn  从订单号
 * @param   string  $to_order_sn    主订单号
 * @return  成功返回true,失败返回错误信息
 */
function merge_order($from_order_sn, $to_order_sn)
{
    /* 订单号不能为空 */
    if (trim($from_order_sn) == '' || trim($to_order_sn) == '') {
        return $GLOBALS['_LANG']['order_sn_not_null'];
    }
    /* 订单号不能相同 */
    if ($from_order_sn == $to_order_sn) {
        return $GLOBALS['_LANG']['two_order_sn_same'];
    }
    /* 取得订单信息 */
    $from_order = order_info(0, $from_order_sn);
    $to_order = order_info(0, $to_order_sn);
    /* 检查订单是否存在 */
    if (!$from_order) {
        return sprintf($GLOBALS['_LANG']['order_not_exist'], $from_order_sn);
    } elseif (!$to_order) {
        return sprintf($GLOBALS['_LANG']['order_not_exist'], $to_order_sn);
    }
    /* 检查合并的订单是否为普通订单,非普通订单不允许合并 */
    if ($from_order['extension_code'] != '' || $to_order['extension_code'] != 0) {
        return $GLOBALS['_LANG']['merge_invalid_order'];
    }
    /* 检查订单状态是否是已确认或未确认、未付款、未发货 */
    if ($from_order['order_status'] != OS_UNCONFIRMED && $from_order['order_status'] != OS_CONFIRMED) {
        return sprintf($GLOBALS['_LANG']['os_not_unconfirmed_or_confirmed'], $from_order_sn);
    } elseif ($from_order['pay_status'] != PS_UNPAYED) {
        return sprintf($GLOBALS['_LANG']['ps_not_unpayed'], $from_order_sn);
    } elseif ($from_order['shipping_status'] != SS_UNSHIPPED) {
        return sprintf($GLOBALS['_LANG']['ss_not_unshipped'], $from_order_sn);
    }
    if ($to_order['order_status'] != OS_UNCONFIRMED && $to_order['order_status'] != OS_CONFIRMED) {
        return sprintf($GLOBALS['_LANG']['os_not_unconfirmed_or_confirmed'], $to_order_sn);
    } elseif ($to_order['pay_status'] != PS_UNPAYED) {
        return sprintf($GLOBALS['_LANG']['ps_not_unpayed'], $to_order_sn);
    } elseif ($to_order['shipping_status'] != SS_UNSHIPPED) {
        return sprintf($GLOBALS['_LANG']['ss_not_unshipped'], $to_order_sn);
    }
    /* 检查订单用户是否相同 */
    if ($from_order['user_id'] != $to_order['user_id']) {
        return $GLOBALS['_LANG']['order_user_not_same'];
    }
    /* 合并订单 */
    $order = $to_order;
    $order['order_id'] = '';
    $order['add_time'] = gmtime();
    // 合并商品总额
    $order['goods_amount'] += $from_order['goods_amount'];
    // 合并折扣
    $order['discount'] += $from_order['discount'];
    if ($order['shipping_id'] > 0) {
        // 重新计算配送费用
        $weight_price = order_weight_price($to_order['order_id']);
        $from_weight_price = order_weight_price($from_order['order_id']);
        $weight_price['weight'] += $from_weight_price['weight'];
        $weight_price['amount'] += $from_weight_price['amount'];
        $weight_price['number'] += $from_weight_price['number'];
        $region_id_list = array($order['country'], $order['province'], $order['city'], $order['district']);
        $shipping_area = shipping_area_info($order['shipping_id'], $region_id_list);
        $order['shipping_fee'] = shipping_fee($shipping_area['shipping_code'], unserialize($shipping_area['configure']), $weight_price['weight'], $weight_price['amount'], $weight_price['number']);
        // 如果保价了,重新计算保价费
        if ($order['insure_fee'] > 0) {
            $order['insure_fee'] = shipping_insure_fee($shipping_area['shipping_code'], $order['goods_amount'], $shipping_area['insure']);
        }
    }
    // 重新计算包装费、贺卡费
    if ($order['pack_id'] > 0) {
        $pack = pack_info($order['pack_id']);
        $order['pack_fee'] = $pack['free_money'] > $order['goods_amount'] ? $pack['pack_fee'] : 0;
    }
    if ($order['card_id'] > 0) {
        $card = card_info($order['card_id']);
        $order['card_fee'] = $card['free_money'] > $order['goods_amount'] ? $card['card_fee'] : 0;
    }
    // 红包不变,合并积分、余额、已付款金额
    $order['integral'] += $from_order['integral'];
    $order['integral_money'] = value_of_integral($order['integral']);
    $order['surplus'] += $from_order['surplus'];
    $order['money_paid'] += $from_order['money_paid'];
    // 计算应付款金额(不包括支付费用)
    $order['order_amount'] = $order['goods_amount'] - $order['discount'] + $order['shipping_fee'] + $order['insure_fee'] + $order['pack_fee'] + $order['card_fee'] - $order['bonus'] - $order['integral_money'] - $order['surplus'] - $order['money_paid'];
    // 重新计算支付费
    if ($order['pay_id'] > 0) {
        // 货到付款手续费
        $cod_fee = $shipping_area ? $shipping_area['pay_fee'] : 0;
        $order['pay_fee'] = pay_fee($order['pay_id'], $order['order_amount'], $cod_fee);
        // 应付款金额加上支付费
        $order['order_amount'] += $order['pay_fee'];
    }
    /* 插入订单表 */
    do {
        $order['order_sn'] = get_order_sn();
        if ($GLOBALS['db']->autoExecute($GLOBALS['ecs']->table('order_info'), addslashes_deep($order), 'INSERT')) {
            break;
        } else {
            if ($GLOBALS['db']->errno() != 1062) {
                die($GLOBALS['db']->errorMsg());
            }
        }
    } while (true);
    // 防止订单号重复
    /* 订单号 */
    $order_id = $GLOBALS['db']->insert_id();
    /* 更新订单商品 */
    $sql = 'UPDATE ' . $GLOBALS['ecs']->table('order_goods') . " SET order_id = '{$order_id}' " . "WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id']));
    $GLOBALS['db']->query($sql);
    include_once ROOT_PATH . 'includes/lib_clips.php';
    /* 插入支付日志 */
    insert_pay_log($order_id, $order['order_amount'], PAY_ORDER);
    /* 删除原订单 */
    $sql = 'DELETE FROM ' . $GLOBALS['ecs']->table('order_info') . " WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id']));
    $GLOBALS['db']->query($sql);
    /* 删除原订单支付日志 */
    $sql = 'DELETE FROM ' . $GLOBALS['ecs']->table('pay_log') . " WHERE order_id " . db_create_in(array($from_order['order_id'], $to_order['order_id']));
    $GLOBALS['db']->query($sql);
    /* 返还 from_order 的红包,因为只使用 to_order 的红包 */
    if ($from_order['bonus_id'] > 0) {
        unuse_bonus($from_order['bonus_id']);
    }
    /* 返回成功 */
    return true;
}
Exemplo n.º 2
0
             ecs_header("Location: order.php?act=info&order_id=" . $order_id . "\n");
         }
         exit;
     }
 } elseif ('shipping' == $step) {
     /* 如果不存在实体商品,退出 */
     if (!exist_real_goods($order_id)) {
         die('Hacking Attemp');
     }
     /* 取得订单信息 */
     $order_info = order_info($order_id);
     $region_id_list = array($order_info['country'], $order_info['province'], $order_info['city'], $order_info['district']);
     /* 保存订单 */
     $shipping_id = $_POST['shipping'];
     $shipping = shipping_area_info($shipping_id, $region_id_list);
     $weight_amount = order_weight_price($order_id);
     $shipping_fee = shipping_fee($shipping['shipping_code'], $shipping['configure'], $weight_amount['weight'], $weight_amount['amount'], $weight_amount['number']);
     $order = array('shipping_id' => $shipping_id, 'shipping_name' => addslashes($shipping['shipping_name']), 'shipping_fee' => $shipping_fee);
     if (isset($_POST['insure'])) {
         /* 计算保价费 */
         $order['insure_fee'] = shipping_insure_fee($shipping['shipping_code'], order_amount($order_id), $shipping['insure']);
     } else {
         $order['insure_fee'] = 0;
     }
     update_order($order_id, $order);
     update_order_amount($order_id);
     /* 更新 pay_log */
     update_pay_log($order_id);
     /* 清除首页缓存:发货单查询 */
     clear_cache_files('index.dwt');
     /* todo 记录日志 */
Exemplo n.º 3
0
                     /* 取得区域 */
                     $smarty->assign('district_list', get_regions(3, $order['city']));
                 }
             }
         }
     }
 } elseif ('shipping' == $step) {
     /* 如果不存在实体商品 */
     if (!exist_real_goods($order_id)) {
         die('Hacking Attemp');
     }
     /* 取得可用的配送方式列表 */
     $region_id_list = array($order['country'], $order['province'], $order['city'], $order['district']);
     $shipping_list = available_shipping_list($region_id_list);
     /* 取得配送费用 */
     $total = order_weight_price($order_id);
     foreach ($shipping_list as $key => $shipping) {
         $shipping_fee = shipping_fee($shipping['shipping_code'], unserialize($shipping['configure']), $total['weight'], $total['amount'], $total['number']);
         $shipping_list[$key]['shipping_fee'] = $shipping_fee;
         $shipping_list[$key]['format_shipping_fee'] = price_format($shipping_fee);
         $shipping_list[$key]['free_money'] = price_format($shipping['configure']['free_money']);
     }
     $smarty->assign('shipping_list', $shipping_list);
 } elseif ('payment' == $step) {
     /* 取得可用的支付方式列表 */
     if (exist_real_goods($order_id)) {
         /* 存在实体商品 */
         $region_id_list = array($order['country'], $order['province'], $order['city'], $order['district']);
         $shipping_area = shipping_area_info($order['shipping_id'], $region_id_list);
         $pay_fee = $shipping_area['support_cod'] == 1 ? $shipping_area['pay_fee'] : 0;
         $payment_list = available_payment_list($shipping_area['support_cod'], $pay_fee);
Exemplo n.º 4
0
     $order['money_refund'] = abs($order['order_amount']);
     $order['formated_money_refund'] = price_format(abs($order['order_amount']));
 }
 /* 其他处理 */
 $order['order_time'] = date($_CFG['time_format'], $order['add_time']);
 $order['pay_time'] = $order['pay_time'] > 0 ? date($_CFG['time_format'], $order['pay_time']) : $_LANG['ps'][PS_UNPAYED];
 $order['shipping_time'] = $order['shipping_time'] > 0 ? date($_CFG['time_format'], $order['shipping_time']) : $_LANG['ss'][SS_UNSHIPPED];
 $order['status'] = $_LANG['os'][$order['order_status']] . ',' . $_LANG['ps'][$order['pay_status']] . ',' . $_LANG['ss'][$order['shipping_status']];
 $order['invoice_no'] = $order['shipping_status'] == SS_UNSHIPPED || $order['shipping_status'] == SS_PREPARING ? $_LANG['ss'][SS_UNSHIPPED] : $order['invoice_no'];
 /* 取得订单的来源 */
 $order['referer'] = $_SESSION['admin_name'];
 /* 此订单的发货备注(此订单的最后一条操作记录) */
 $sql = "SELECT action_note FROM " . $ecs->table('order_action') . " WHERE order_id = '{$order['order_id']}' AND shipping_status = 1 ORDER BY log_time DESC";
 $order['invoice_note'] = $db->getOne($sql);
 /* 取得订单商品总重量 */
 $weight_price = order_weight_price($order['order_id']);
 $order['total_weight'] = $weight_price['formated_weight'];
 /* 取得顾客的旺旺号 */
 $sql = 'SELECT aliww FROM ' . $GLOBALS['ecs']->table('users') . " WHERE user_id={$order['user_id']}";
 $order['aliww'] = $GLOBALS['db']->getOne($sql);
 /* 参数赋值:订单 */
 $smarty->assign('order', $order);
 /* 取得用户信息 */
 if ($order['user_id'] > 0) {
     /* 用户等级 */
     if ($user['user_rank'] > 0) {
         $where = " WHERE rank_id = '{$user['user_rank']}' ";
     } else {
         $where = " WHERE min_points<=" . intval($user['rank_points']) . " ORDER BY min_points DESC ";
     }
     $sql = "SELECT rank_name FROM " . $ecs->table('user_rank') . $where;