엑셀 배송일괄처리 추가 중

This commit is contained in:
chicpro
2013-12-05 15:07:39 +09:00
parent 429a7b2407
commit 9247f50aa1
6 changed files with 436 additions and 124 deletions

View File

@ -0,0 +1,122 @@
<?php
if (!defined('_GNUBOARD_')) exit;
// 상품옵션별재고 또는 상품재고에 더하기
function add_io_stock($it_id, $ct_qty, $io_id="", $io_type=0)
{
global $g5;
if($io_id) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty + '{$ct_qty}'
where it_id = '{$it_id}'
and io_id = '{$io_id}'
and io_type = '{$io_type}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty + '{$ct_qty}'
where it_id = '{$it_id}' ";
}
return sql_query($sql);
}
// 상품옵션별재고 또는 상품재고에서 빼기
function subtract_io_stock($it_id, $ct_qty, $io_id="", $io_type=0)
{
global $g5;
if($io_id) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty - '{$ct_qty}'
where it_id = '{$it_id}'
and io_id = '{$io_id}'
and io_type = '{$io_type}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty - '{$ct_qty}'
where it_id = '{$it_id}' ";
}
return sql_query($sql);
}
// 주문과 장바구니의 상태를 변경한다.
function change_status($od_id, $current_status, $change_status)
{
global $g5;
$sql = " update {$g5['g5_shop_order_table']} set od_status = '{$change_status}' where od_id = '{$od_id}' and od_status = '{$current_status}' ";
sql_query($sql, true);
$sql = " update {$g5['g5_shop_cart_table']} set ct_status = '{$change_status}' where od_id = '{$od_id}' and ct_status = '{$current_status}' ";
sql_query($sql, true);
}
// 주문서에 입금시 update
function order_update_receipt($od_id)
{
global $g5;
$sql = " update {$g5['g5_shop_order_table']} set od_receipt_price = od_misu, od_misu = 0, od_receipt_time = '".G5_TIME_YMDHIS."' where od_id = '$od_id' and od_status = '입금' ";
return sql_query($sql);
}
// 주문서에 배송시 update
function order_update_delivery($od_id, $mb_id, $change_status, $delivery)
{
global $g5;
if($change_status != '배송')
return;
$sql = " update {$g5['g5_shop_order_table']} set od_delivery_company = '{$delivery['delivery_company']}', od_invoice = '{$delivery['invoice']}', od_invoice_time = '{$delivery['invoice_time']}' where od_id = '$od_id' and od_status = '준비' ";
sql_query($sql);
$sql = " select * from {$g5['g5_shop_cart_table']} where od_id = '$od_id' ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
// 재고를 사용하지 않았다면
$stock_use = $row['ct_stock_use'];
if(!$row['ct_stock_use'])
{
// 재고에서 뺀다.
subtract_io_stock($row['it_id'], $row['ct_qty'], $row['io_id'], $row['io_type']);
$stock_use = 1;
$sql = " update {$g5['g5_shop_cart_table']} set ct_stock_use = '$stock_use' where ct_id = '{$row['ct_id']}' ";
sql_query($sql);
}
}
}
// 처리내용 SMS
function conv_sms_contents($od_id, $contents)
{
global $g5, $config, $default;
$sms_contents = '';
if ($od_id && $config['cf_sms_use'] == 'icode')
{
$sql = " select od_id, od_name, od_invoice, od_receipt_price, od_delivery_company
from {$g5['g5_shop_order_table']} where od_id = '$od_id' ";
$od = sql_fetch($sql);
$sms_contents = $contents;
$sms_contents = preg_replace("/{이름}/", $od['od_name'], $sms_contents);
$sms_contents = preg_replace("/{입금액}/", number_format($od['od_receipt_price']), $sms_contents);
$sms_contents = preg_replace("/{택배회사}/", $od['od_delivery_company'], $sms_contents);
$sms_contents = preg_replace("/{운송장번호}/", $od['od_invoice'], $sms_contents);
$sms_contents = preg_replace("/{주문번호}/", $od['od_id'], $sms_contents);
$sms_contents = preg_replace("/{회사명}/", $default['de_admin_company_name'], $sms_contents);
}
return iconv("utf-8", "euc-kr", stripslashes($sms_contents));
}
?>

View File

@ -0,0 +1,55 @@
<?php
$sub_menu = '400400';
include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
$g5['title'] = '엑셀 배송일괄처리';
include_once(G5_PATH.'/head.sub.php');
?>
<div class="new_win">
<h1><?php echo $g5['title']; ?></h1>
<div class="local_desc01 local_desc">
<p>
엑셀파일을 이용하여 배송정보를 일괄등록할 수 있습니다.<br>
형식은 <strong>배송처리용 엑셀파일</strong>을 다운로드하여 배송 정보를 입력하시면 됩니다.<br>
수정 완료 후 엑셀파일을 업로드하시면 배송정보가 일괄등록됩니다.<br>
엑셀파일을 저장하실 때는 Excel 97 - 2003 통합문서 (*.xls) 로 저장하셔야 합니다.<br>
<strong>주문상태가 준비이고 미수금이 0인 주문에 한해 엑셀파일이 생성됩니다.</strong>
</p>
<p>
<a href="<?php echo G5_ADMIN_URL; ?>/shop_admin/orderdeliveryexcel.php">배송정보 일괄등록용 엑셀파일 다운로드</a>
</p>
</div>
<form name="forderdelivery" method="post" action="./orderdeliveryupdate.php" enctype="MULTIPART/FORM-DATA" autocomplete="off">
<div id="excelfile_upload">
<label for="excelfile">파일선택</label>
<input type="file" name="excelfile" id="excelfile">
</div>
<div>
<input type="checkbox" name="od_send_mail" value="1" id="od_send_mail" checked="checked">
<label for="od_send_mail">배송안내 메일</label>
<input type="checkbox" name="send_sms" value="1" id="od_send_sms" checked="checked">
<label for="od_send_sms">배송안내 SMS</label>
<input type="checkbox" name="send_escrow" value="1" id="od_send_escrow">
<label for="od_send_escrow">에스크로배송등록</label>
</div>
<div class="btn_confirm01 btn_confirm">
<input type="submit" value="배송정보 등록" class="btn_submit">
<button type="button" onclick="window.close();">닫기</button>
</div>
</form>
</div>
<?php
include_once(G5_PATH.'/tail.sub.php');
?>

View File

@ -0,0 +1,60 @@
<?php
$sub_menu = '400400';
include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
// 주문정보
$sql = " select *
from {$g5['g5_shop_order_table']}
where od_misu = '0'
and od_status = '준비'
order by od_id desc ";
$result = sql_query($sql);
if(!@mysql_num_rows($result))
alert_close('배송처리할 주문 내역이 없습니다.');
/*================================================================================
php_writeexcel http://www.bettina-attack.de/jonny/view.php/projects/php_writeexcel/
=================================================================================*/
include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_workbook.inc.php');
include_once(G5_LIB_PATH.'/Excel/php_writeexcel/class.writeexcel_worksheet.inc.php');
$fname = tempnam(G5_DATA_PATH, "tmp-deliverylist.xls");
$workbook = new writeexcel_workbook($fname);
$worksheet = $workbook->addworksheet();
// Put Excel data
$data = array('주문번호', '주문자명', '주문자전화1', '주문자전화2', '배송자명', '배송지전화1', '배송지전화2', '배송지주소', '배송회사', '운송장번호');
$data = array_map('iconv_euckr', $data);
$col = 0;
foreach($data as $cell) {
$worksheet->write(0, $col++, $cell);
}
for($i=1; $row=sql_fetch_array($result); $i++) {
$row = array_map('iconv_euckr', $row);
$worksheet->write($i, 0, ' '.$row['od_id']);
$worksheet->write($i, 1, $row['od_name']);
$worksheet->write($i, 2, $row['od_tel']);
$worksheet->write($i, 3, $row['od_hp']);
$worksheet->write($i, 4, $row['od_b_name']);
$worksheet->write($i, 5, $row['od_b_tel']);
$worksheet->write($i, 6, $row['od_b_hp']);
$worksheet->write($i, 7, $row['od_b_addr1'].' '.$row['od_b_addr2']);
$worksheet->write($i, 8, $row['od_delivery_company']);
$worksheet->write($i, 9, $row['od_invoice']);
}
$workbook->close();
header("Content-Type: application/x-msexcel; name=\"deliverylist-".date("ymd", time()).".xls\"");
header("Content-Disposition: inline; filename=\"deliverylist-".date("ymd", time()).".xls\"");
$fh=fopen($fname, "rb");
fpassthru($fh);
unlink($fname);
?>

View File

@ -0,0 +1,187 @@
<?php
$sub_menu = '400400';
include_once('./_common.php');
include_once('./admin.shop.lib.php');
include_once(G5_LIB_PATH.'/mailer.lib.php');
include_once(G5_LIB_PATH.'/icode.sms.lib.php');
auth_check($auth[$sub_menu], "w");
define("_ORDERMAIL_", true);
$sms_count = 0;
if($config['cf_sms_use'] == 'icode' && $_POST['send_sms'])
{
$SMS = new SMS;
$SMS->SMS_con($config['cf_icode_server_ip'], $config['cf_icode_id'], $config['cf_icode_pw'], $config['cf_icode_server_port']);
}
$escrow_count = 0;
if($_POST['send_escrow']) {
$escrow_tno = array();
$escrow_corp = array();
$escrow_numb = array();
$escrow_idx = 0;
}
if($_FILES['excelfile']['tmp_name']) {
$file = $_FILES['excelfile']['tmp_name'];
include_once(G5_LIB_PATH.'/Excel/reader.php');
$data = new Spreadsheet_Excel_Reader();
// Set output Encoding.
$data->setOutputEncoding('UTF-8');
/***
* if you want you can change 'iconv' to mb_convert_encoding:
* $data->setUTFEncoder('mb');
*
**/
/***
* By default rows & cols indeces start with 1
* For change initial index use:
* $data->setRowColOffset(0);
*
**/
/***
* Some function for formatting output.
* $data->setDefaultFormat('%.2f');
* setDefaultFormat - set format for columns with unknown formatting
*
* $data->setColumnFormat(4, '%.3f');
* setColumnFormat - set format for column (apply only to number fields)
*
**/
$data->read($file);
/*
$data->sheets[0]['numRows'] - count rows
$data->sheets[0]['numCols'] - count columns
$data->sheets[0]['cells'][$i][$j] - data from $i-row $j-column
$data->sheets[0]['cellsInfo'][$i][$j] - extended info about cell
$data->sheets[0]['cellsInfo'][$i][$j]['type'] = "date" | "number" | "unknown"
if 'type' == "unknown" - use 'raw' value, because cell contain value with format '0.00';
$data->sheets[0]['cellsInfo'][$i][$j]['raw'] = value if cell without format
$data->sheets[0]['cellsInfo'][$i][$j]['colspan']
$data->sheets[0]['cellsInfo'][$i][$j]['rowspan']
*/
error_reporting(E_ALL ^ E_NOTICE);
$fail_od_id = array();
$total_count = 0;
$fail_count = 0;
$succ_count = 0;
// $i 사용시 ordermail.inc.php의 $i 때문에 무한루프에 빠짐
for ($k = 2; $k <= $data->sheets[0]['numRows']; $k++) {
$total_count++;
$od_id = addslashes(trim($data->sheets[0]['cells'][$k][1]));
$od_delivery_company = addslashes($data->sheets[0]['cells'][$k][9]);
$od_invoice = addslashes($data->sheets[0]['cells'][$k][10]);
if(!$od_id || !$od_delivery_company || !$od_invoice) {
$fail_count++;
$fail_od_id[] = $od_id;
continue;
}
// 주문정보
$od = sql_fetch(" select * from {$g5['g5_shop_order_table']} where od_id = '$od_id' ");
if (!$od) {
$fail_od_id[] = $od_id;
continue;
}
$delivery['invoice'] = $od_invoice;
$delivery['invoice_time'] = G5_TIME_YMDHIS;
$delivery['delivery_company'] = $od_delivery_company;
// 주문정보 업데이트
order_update_delivery($od_id, $od['mb_id'], '배송', $delivery);
change_status($od_id, '준비', '배송');
// SMS
if($config['cf_sms_use'] == 'icode' && $_POST['send_sms'] && $default['de_sms_use5']) {
$sms_contents = conv_sms_contents($od_id, $default['de_sms_cont5']);
if($sms_contents) {
$receive_number = preg_replace("/[^0-9]/", "", $od['od_hp']); // 수신자번호
$send_number = preg_replace("/[^0-9]/", "", $default['de_admin_company_tel']); // 발신자번호
if($receive_number && $send_number) {
$SMS->Add($receive_number, $send_number, $config['cf_icode_id'], $sms_contents, "");
$sms_count++;
}
}
}
// 메일
if($config['cf_email_use'] && $_POST['od_send_mail'])
include './ordermail.inc.php';
// 에스크로 배송
if($_POST['send_escrow'] && $od['od_tno'] && $od['od_escrow']) {
$escrow_tno[$escrow_idx] = $od['od_tno'];
$escrow_numb[$escrow_idx] = $od_invoice;
$escrow_corp[$escrow_idx] = $od_delivery_company;
$escrow_idx++;
$escrow_count++;
}
}
}
// SMS
if($config['cf_sms_use'] == 'icode' && $_POST['send_sms'] && $sms_count)
{
$SMS->Send();
}
// 에스크로 배송
if($_POST['send_escrow'] && $escrow_count)
{
include_once('./orderescrow.inc.php');
}
$g5['title'] = '엑셀 배송일괄처리 결과';
include_once(G5_PATH.'/head.sub.php');
?>
<div class="new_win">
<h1><?php echo $g5['title']; ?></h1>
<p class="new_win_desc">배송일괄처리를 완료했습니다.</p>
<dl id="excelfile_result">
<dt>총배송건수</dt>
<dd><?php echo number_format($total_count); ?></dd>
<dt>완료건수</dt>
<dd><?php echo number_format($succ_count); ?></dd>
<dt>실패건수</dt>
<dd><?php echo number_format($fail_count); ?></dd>
<?php if($fail_count > 0) { ?>
<dt>실패주문코드</dt>
<dd><?php echo implode(', ', $fail_od_id); ?></dd>
<?php } ?>
</dl>
<div class="btn_win01 btn_win">
<button type="button" onclick="window.close();">창닫기</button>
</div>
</div>
<?php
include_once(G5_PATH.'/tail.sub.php');
?>

View File

@ -118,6 +118,8 @@ $listall = '<a href="'.$_SERVER['PHP_SELF'].'" class="ov_listall">전체목록</
<div class="local_ov01 local_ov">
<?php echo $listall; ?>
전체 주문내역 <?php echo $total_count; ?>건
<a href="./orderdelivery.php" id="order_delivery">엑셀배송처리</a>
</div>
<form name="frmorderlist" class="local_sch01 local_sch">
@ -495,6 +497,13 @@ $(function(){
$("body").on("click", function() {
$("#orderitemlist").remove();
});
// 엑셀배송처리창
$("#order_delivery").on("click", function() {
var opt = "width=600,height=450,left=10,top=10";
window.open(this.href, "win_excel", opt);
return false;
});
});
function set_date(today)

View File

@ -1,6 +1,7 @@
<?php
$sub_menu = '400400';
include_once('./_common.php');
include_once('./admin.shop.lib.php');
include_once(G5_LIB_PATH.'/mailer.lib.php');
include_once(G5_LIB_PATH.'/icode.sms.lib.php');
@ -23,126 +24,6 @@ if($_POST['send_escrow']) {
$escrow_idx = 0;
}
// 상품옵션별재고 또는 상품재고에 더하기
function add_io_stock($it_id, $ct_qty, $io_id="", $io_type=0)
{
global $g5;
if($io_id) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty + '{$ct_qty}'
where it_id = '{$it_id}'
and io_id = '{$io_id}'
and io_type = '{$io_type}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty + '{$ct_qty}'
where it_id = '{$it_id}' ";
}
return sql_query($sql);
}
// 상품옵션별재고 또는 상품재고에서 빼기
function subtract_io_stock($it_id, $ct_qty, $io_id="", $io_type=0)
{
global $g5;
if($io_id) {
$sql = " update {$g5['g5_shop_item_option_table']}
set io_stock_qty = io_stock_qty - '{$ct_qty}'
where it_id = '{$it_id}'
and io_id = '{$io_id}'
and io_type = '{$io_type}' ";
} else {
$sql = " update {$g5['g5_shop_item_table']}
set it_stock_qty = it_stock_qty - '{$ct_qty}'
where it_id = '{$it_id}' ";
}
return sql_query($sql);
}
// 주문과 장바구니의 상태를 변경한다.
function change_status($od_id, $current_status, $change_status)
{
global $g5;
$sql = " update {$g5['g5_shop_order_table']} set od_status = '{$change_status}' where od_id = '{$od_id}' and od_status = '{$current_status}' ";
sql_query($sql, true);
$sql = " update {$g5['g5_shop_cart_table']} set ct_status = '{$change_status}' where od_id = '{$od_id}' and ct_status = '{$current_status}' ";
sql_query($sql, true);
}
// 주문서에 입금시 update
function order_update_receipt($od_id)
{
global $g5;
$sql = " update {$g5['g5_shop_order_table']} set od_receipt_price = od_misu, od_misu = 0, od_receipt_time = '".G5_TIME_YMDHIS."' where od_id = '$od_id' and od_status = '입금' ";
return sql_query($sql);
}
// 주문서에 배송시 update
function order_update_delivery($od_id, $mb_id, $change_status, $delivery)
{
global $g5;
if($change_status != '배송')
return;
$sql = " update {$g5['g5_shop_order_table']} set od_delivery_company = '{$delivery['delivery_company']}', od_invoice = '{$delivery['invoice']}', od_invoice_time = '{$delivery['invoice_time']}' where od_id = '$od_id' and od_status = '준비' ";
sql_query($sql);
$sql = " select * from {$g5['g5_shop_cart_table']} where od_id = '$od_id' ";
$result = sql_query($sql);
for ($i=0; $row=sql_fetch_array($result); $i++)
{
// 재고를 사용하지 않았다면
$stock_use = $row['ct_stock_use'];
if(!$row['ct_stock_use'])
{
// 재고에서 뺀다.
subtract_io_stock($row['it_id'], $row['ct_qty'], $row['io_id'], $row['io_type']);
$stock_use = 1;
$sql = " update {$g5['g5_shop_cart_table']} set ct_stock_use = '$stock_use' where ct_id = '{$row['ct_id']}' ";
sql_query($sql);
}
}
}
// 처리내용 SMS
function conv_sms_contents($od_id, $contents)
{
global $g5, $config, $default;
$sms_contents = '';
if ($od_id && $config['cf_sms_use'] == 'icode')
{
$sql = " select od_id, od_name, od_invoice, od_receipt_price, od_delivery_company
from {$g5['g5_shop_order_table']} where od_id = '$od_id' ";
$od = sql_fetch($sql);
$sms_contents = $contents;
$sms_contents = preg_replace("/{이름}/", $od['od_name'], $sms_contents);
$sms_contents = preg_replace("/{입금액}/", number_format($od['od_receipt_price']), $sms_contents);
$sms_contents = preg_replace("/{택배회사}/", $od['od_delivery_company'], $sms_contents);
$sms_contents = preg_replace("/{운송장번호}/", $od['od_invoice'], $sms_contents);
$sms_contents = preg_replace("/{주문번호}/", $od['od_id'], $sms_contents);
$sms_contents = preg_replace("/{회사명}/", $default['de_admin_company_name'], $sms_contents);
}
return iconv("utf-8", "euc-kr", stripslashes($sms_contents));
}
for ($i=0; $i<count($_POST['chk']); $i++)
{
// 실제 번호를 넘김
@ -225,11 +106,9 @@ for ($i=0; $i<count($_POST['chk']); $i++)
// 에스크로 배송
if($_POST['send_escrow'] && $od['od_tno'] && $od['od_escrow']) {
$od = sql_fetch(" select * from {$g5['g5_shop_order_table']} where od_id = '$od_id' ");
$escrow_tno[$escrow_idx] = $od['od_tno'];
$escrow_numb[$escrow_idx] = $od['od_invoice'];
$escrow_corp[$escrow_idx] = $od['od_delivery_company'];
$escrow_numb[$escrow_idx] = $invoice;
$escrow_corp[$escrow_idx] = $delivery_company;
$escrow_idx++;
$escrow_count++;
}