테스트 사이트 - 개발 중인 베타 버전입니다

주문내역출력 CSV 에서 같은 주문은 한줄로 처리하기 3

· 11년 전 · 86
2014-03-05 오전 10-50-52.jpg
 
 
상품명을 여러줄로 출력해 주는 코드입니다.
adm/shop_admin/orderprintresult.php 를 아래의 코드로 대체하세요.
 
 
<?
$sub_menu = "500120";
include_once("./_common.php");
auth_check($auth[$sub_menu], "r");
function conv_telno($t)
{
    // 숫자만 있고 0으로 시작하는 전화번호
    if (!preg_match("/[^0-9]/", $t) && preg_match("/^0/", $t))  {
        if (preg_match("/^01/", $t)) {
            $t = preg_replace("/([0-9]{3})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
        } else if (preg_match("/^02/", $t)) {
            $t = preg_replace("/([0-9]{2})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
        } else {
            $t = preg_replace("/([0-9]{3})(.*)([0-9]{4})/", "\\1-\\2-\\3", $t);
        }
    }
    return $t;
}
// 1.04.01
// MS엑셀 CSV 데이터로 다운로드 받음
if ($csv)
{
    $fr_date = date_conv($fr_date);
    $to_date = date_conv($to_date);

    $sql = " SELECT distinct a.on_uid, od_id, od_b_zip1, od_b_zip2, od_b_addr1, od_b_addr2, od_b_name, od_b_tel, od_b_hp
              FROM $g4[yc4_order_table] a, $g4[yc4_cart_table] b
              WHERE a.on_uid = b.on_uid ";
    if ($case == 1)
        $sql .= " and a.od_time between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
    else
        $sql .= " and a.od_id between '$fr_od_id' and '$to_od_id' ";
    if ($ct_status)
        $sql .= " and b.ct_status = '$ct_status' ";
    $sql .="  order by a.od_time asc ";
    $result = sql_query($sql);
    $cnt = @mysql_num_rows($result);
    if (!$cnt)
        alert("출력할 내역이 없습니다.");
    //header('Content-Type: text/x-csv');
    header('Content-Type: doesn/matter');
    header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
    header('Content-Disposition: attachment; filename="' . date("ymd", time()) . '.csv"');
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    header('Pragma: public');
    echo "우편번호,주소,이름,전화1,전화2,상품명,수량,비고\n";
    for ($i=0; $row=mysql_fetch_array($result); $i++)
    {
        /*
        $sql2 = " select count(*) as cnt, sum(ct_qty) as sum_qty from $g4[yc4_cart_table] where on_uid = '$row[on_uid]' ";
        $row2 = sql_fetch($sql2);
        $sql3 = " select it_name from $g4[yc4_cart_table] a, $g4[yc4_item_table] b where a.it_id = b.it_id and a.on_uid = '$row[on_uid]' order by a.ct_id ";
        $row3 = sql_fetch($sql3);
        $it_name = $row3[it_name];
        if ($row2[cnt] > 1)
            $it_name .= " 외 ".($row2[cnt]-1)."건 ";
        */
        $aname = array();
        $sql2 = " select b.it_name,
                         b.it_opt1_subject,
                         b.it_opt2_subject,
                         b.it_opt3_subject,
                         b.it_opt4_subject,
                         b.it_opt5_subject,
                         b.it_opt6_subject,
                         a.it_opt1,
                         a.it_opt2,
                         a.it_opt3,
                         a.it_opt4,
                         a.it_opt5,
                         a.it_opt6
                    from $g4[yc4_cart_table] a, $g4[yc4_item_table] b where a.it_id = b.it_id and a.on_uid = '$row[on_uid]' order by a.ct_id ";
        $result2 = sql_query($sql2);
        for ($j=0; $row2=sql_fetch_array($result2); $j++) {
            $opt = "";
            for ($k=1; $k<=6; $k++) {
                if ($row2["it_opt{$k}"]) {
                    $opt .= ",".$row2["it_opt{$k}_subject"]." = ".$row2["it_opt{$k}"];
                }
            }
            $aname[] = $row2[it_name].$opt;
        }
        $it_name = implode("\n", $aname);
        echo '"' . $row[od_b_zip1] . '-' . $row[od_b_zip2] . '"' . ',';
        echo '"' . $row[od_b_addr1] . ' ' . $row[od_b_addr2] . '"' . ',';
        echo '"' . $row[od_b_name] . '"' . ',';
        //echo '"' . multibyte_digit((string)$row[od_b_tel]) . '"' . ',';
        //echo '"' . multibyte_digit((string)$row[od_b_hp]) . '"' . ',';
        echo '"' . conv_telno($row[od_b_tel]) . '"' . ',';
        echo '"' . conv_telno($row[od_b_hp]) . '"' . ',';
        echo '"' . $it_name . '"' . ',';
        echo '"' . $row2[sum_qty] . '"' . ',';
        echo '"' . '주문번호(' . $row[od_id] . ')' . '"';
        echo "\n";
    }
    if ($i == 0)
        echo "자료가 없습니다.\n";
    exit;
}
function get_order($on_uid)
{
global $g4;
$sql = " select * from $g4[yc4_order_table] where on_uid = '$on_uid' ";
    return sql_fetch($sql);
}
$g4[title] = "주문내역";
include_once("$g4[path]/head.sub.php");
if ($case == 1)
{
    $fr_date = date_conv($fr_date);
    $to_date = date_conv($to_date);
    $sql = " SELECT DISTINCT on_uid FROM $g4[yc4_order_table] a, $g4[yc4_cart_table] b
              where on_uid = b.on_uid
                and od_time between '$fr_date 00:00:00' and '$to_date 23:59:59' ";
}
else
{
    $sql = " SELECT DISTINCT on_uid FROM $g4[yc4_order_table] a, $g4[yc4_cart_table] b
              where on_uid = b.on_uid
                and od_id between '$fr_od_id' and '$to_od_id' ";
}
if ($ct_status)
    $sql .= " and b.ct_status = '$ct_status' ";
$sql .= " order by od_id ";
$result = sql_query($sql);
if (mysql_num_rows($result) == 0)
{
    echo "<script>alert('출력할 내역이 없습니다.'); window.close();</script>";
    exit;
}
?>
<html>
<head>
<meta http-equiv="Content-type" content="text/html; charset=euc-kr">
<title>주문내역</title>
<style>
    body, table, tr, td, p { font-size:9pt; }
</style>
</head>
<body bgcolor=ffffff leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<?
if ($case == 1)
    echo "<p><b>[ $fr_date - $to_date $ct_status 내역 ]</b>";
else
    echo "<p><b>[ $fr_od_id - $to_od_id $ct_status 내역 ]</b>";
?>
<table width=650 cellpadding=2 cellspacing=0 border=0 bordercolordark="white" bordercolorlight="gray">
<tr><td colspan=5><hr></td></tr>
<tr>
    <td rowspan=2 width=70 valign=top align=center>주문번호</td>
    <td width=60>보낸분</td>
    <td>주소</td>
    <td width=100>전화번호</td>
    <td width=100>핸드폰</td>
</tr>
<tr>
    <td>받는분</td>
    <td>주소</td>
    <td>전화번호</td>
    <td>핸드폰</td>
</tr>
<tr><td colspan=5><hr></td></tr>
<?
$mod = 10;
$tot_total_amount = 0;
for ($i=0; $row=sql_fetch_array($result); $i++)
{
    $sql1 = " select * from $g4[yc4_order_table] where on_uid = '$row[on_uid]' ";
    $row1 = sql_fetch($sql1);
    // 1.03.02
    $row1[od_addr] = "(".$row1[od_zip1]."-".$row1[od_zip2].") ".$row1[od_addr1]." ".$row1[od_addr2];
    $row1[od_b_addr] = "(".$row1[od_b_zip1]."-".$row1[od_b_zip2].") ".$row1[od_b_addr1]." ".$row1[od_b_addr2];
    $row1[od_addr] = ($row1[od_addr]) ? $row1[od_addr] : "&nbsp;";
    $row1[od_tel] = ($row1[od_tel]) ? $row1[od_tel] : "&nbsp;";
    $row1[od_hp]  = ($row1[od_hp]) ? $row1[od_hp] : "&nbsp;";
    $row1[od_b_tel] = ($row1[od_b_tel]) ? $row1[od_b_tel] : "&nbsp;";
    $row1[od_b_hp]  = ($row1[od_b_hp]) ? $row1[od_b_hp] : "&nbsp;";
    if ($row1[od_name] == $row1[od_b_name]) $row1[od_b_name] = '"';
    if ($row1[od_addr] == $row1[od_b_addr]) $row1[od_b_addr] = '"';
    if ($row1[od_tel] == $row1[od_b_tel]) $row1[od_b_tel] = '"';
    if ($row1[od_hp] == $row1[od_b_hp] && $row1[od_hp] != "&nbsp;") $row1[od_b_hp] = '"';
    $od_memo = ($row1[od_memo]) ? stripslashes($row1[od_memo]) : "";
    echo "
        <tr>
            <td rowspan=3 align=center valign=top>$row1[od_id]</td>
            <td>$row1[od_name]</td>
            <td>$row1[od_addr]</td>
            <td>$row1[od_tel]</td>
            <td>$row1[od_hp]</td>
        </tr>
        <tr>
            <td>$row1[od_b_name]</td>
            <td>$row1[od_b_addr]</td>
            <td>$row1[od_b_tel]</td>
            <td>$row1[od_b_hp]</td>
        </tr>
        <tr>   
            <td colspan=4>
                <table width=100% cellpadding=2 cellspacing=0 border=1 bordercolordark='white' bordercolorlight='gray'>
    ";
    $sql2 = " select    *,                               
                        b.it_opt1_subject,
                        b.it_opt2_subject,
                        b.it_opt3_subject,
                        b.it_opt4_subject,
                        b.it_opt5_subject,
                        b.it_opt6_subject,
                        b.it_name
                from $g4[yc4_cart_table] a, $g4[yc4_item_table] b
              where it_id = b.it_id
                and on_uid = '$row[on_uid]' ";
    if ($ct_status)
        $sql2 .= " and ct_status = '$ct_status' ";
    $sql2 .= "  order by ct_id ";
    $res2 = sql_query($sql2);
    $cnt = $sub_tot_qty = $sub_tot_amount = 0;
    while ($row2 = sql_fetch_array($res2))
    {
        $row2_tot_amount = $row2[ct_amount] * $row2[ct_qty];
        $sub_tot_qty    += $row2[ct_qty];
        $sub_tot_amount += $row2_tot_amount;
        $it_name = stripslashes($row2[it_name]);
        $it_name = "$it_name ($row2[it_id])<br><font color=#555555>";
        $str_split = "";
        for ($k=1; $k<=6; $k++)
        {
            if ($row2["it_opt{$k}"] == "") continue;
            $it_name .= $str_split;
            $it_opt_subject = $row2["it_opt{$k}_subject"];
            $opt = explode( ";", trim($row2["it_opt{$k}"]) );
            $it_name .= "&nbsp;&nbsp; $it_opt_subject = $opt[0]";
            if ($opt[1] != 0)
            {
                $it_name .= " (";
                if (ereg("[+]", $opt[1]) == true)
                    $it_name .= "+";
                // 금액을 전화문의 표시로
                $it_name .= display_amount($opt[1]) . ")";
            }
            $str_split = "<br>";
        }
        $it_name .= "</font>";
        $fontqty1 = $fontqty2 = "";
        if ($row2[ct_qty] >= 2)
        {
            $fontqty1 = "<font color=crimson><b>";
            $fontqty2 = "</b></font>";
        }
        echo "
            <tr>
                <td>$it_name</td>
                <td width=80 align=right>".number_format($row2[ct_amount])."&nbsp;</td>
                <td width=50 align=center>$fontqty1".number_format($row2[ct_qty])."$fontqty2</td>
                <td width=80 align=right>".number_format($row2_tot_amount)."&nbsp;</td>
            </tr>
        ";
        $cnt++;
    }
    if ($cnt >= 2)
    {
        echo "
        <tr>
            <td colspan=2 align=right><b>합 계</b> &nbsp;</td>
            <td align=center>".number_format($sub_tot_qty)."</td>
            <td align=right>".number_format($sub_tot_amount)."&nbsp;</td>
        </tr>";
    }
    $tot_tot_qty    += $sub_tot_qty;
    $tot_tot_amount += $sub_tot_amount;
    if ($od_memo) $od_memo = "<font color=crimson>비고 : $od_memo</font>";
    echo "
            </table>
            $od_memo
        </td>
    </tr>
    <tr><td colspan=5><hr></td></tr>";
}
?>
<tr>
    <td></td>
    <td colspan=4>
        <table width=100% cellpadding=2 cellspacing=0 border=1 bordercolordark='white' bordercolorlight='gray'>
        <tr>
        <?
        echo "
            <td colspan=2 align=right><b>전 체 합 계</b> &nbsp;</td>
            <td align=center width=50>".number_format($tot_tot_qty)."</td>
            <td align=right width=80>".number_format($tot_tot_amount)."&nbsp;</td>
        ";
        ?>
        </tr>
        </table>
    </td>
</tr>
</table>
<br><끝>
</body>
</html>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
1790
1788
1786
1782
1780
1778
1767
1762
1754
1748
1739
1736
1735
1731
1717
1712
1704
1700
1696
1682