1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
|
<?php $sub_menu = '270100'; include_once('./_common.php');
auth_check($auth[$sub_menu], "w");
$ct_chk_count = count($_POST['ct_chk']); if(!$ct_chk_count) alert('처리할 자료를 하나 이상 선택해 주십시오.');
$status_normal = array('주문','입금','준비','배송','완료'); $status_cancel = array('취소','반품','품절');
if (in_array($_POST['ct_status'], $status_normal) || in_array($_POST['ct_status'], $status_cancel)) { ; // 통과 } else { alert('변경할 상태가 올바르지 않습니다.'); }
$mod_history = ''; $cnt = count($_POST['ct_id']); $arr_it_id = array();
for ($i=0; $i<$cnt; $i++) { $k = $_POST['ct_chk'][$i]; $ct_id = $_POST['ct_id'][$k];
if(!$ct_id) continue;
$sql = " select * from {$g5['g5_shop_cart_table']} where od_id = '$od_id' and ct_id = '$ct_id' "; $ct = sql_fetch($sql); if(!$ct['ct_id']) continue;
// 수량이 변경됐다면 $ct_qty = $_POST['ct_qty'][$k]; if($ct['ct_qty'] != $ct_qty) { $diff_qty = $ct['ct_qty'] - $ct_qty;
// 재고에 차이 반영. if($ct['ct_stock_use']) { /*if($ct['io_id']) { $sql = " update {$g5['g5_shop_item_option_table']} set io_stock_qty = io_stock_qty + '$diff_qty' where it_id = '{$ct['it_id']}' and io_id = '{$ct['io_id']}' and io_type = '{$ct['io_type']}' "; } else { $sql = " update {$g5['g5_shop_item_table']} set it_stock_qty = it_stock_qty + '$diff_qty' where it_id = '{$ct['it_id']}' "; }
sql_query($sql);*/ // 재고 반영은 일괄 함수 처리로 변경함 }
// 수량변경 $sql = " update {$g5['g5_shop_cart_table']} set ct_qty = '$ct_qty' where ct_id = '$ct_id' and od_id = '$od_id' "; sql_query($sql); $mod_history .= G5_TIME_YMDHIS.' '.$ct['ct_option'].' 수량변경 '.$ct['ct_qty'].' -> '.$ct_qty."\n"; }
// 재고를 이미 사용했다면 (재고에서 이미 뺐다면) $stock_use = $ct['ct_stock_use']; if ($ct['ct_stock_use']) { if ($ct_status == '주문' || $ct_status == '취소' || $ct_status == '반품' || $ct_status == '품절') { //$stock_use = 0; // 재고에 다시 더한다. /*if($ct['io_id']) { $sql = " update {$g5['g5_shop_item_option_table']} set io_stock_qty = io_stock_qty + '{$ct['ct_qty']}' where it_id = '{$ct['it_id']}' and io_id = '{$ct['io_id']}' and io_type = '{$ct['io_type']}' "; } else { $sql = " update {$g5['g5_shop_item_table']} set it_stock_qty = it_stock_qty + '{$ct['ct_qty']}' where it_id = '{$ct['it_id']}' "; }
sql_query($sql);*/ // 재고 반영은 일괄 함수 처리로 변경함 } } else { // 재고 오류로 인한 수정 if ($ct_status == '배송' || $ct_status == '완료') { //$stock_use = 1; // 재고에서 뺀다. /*if($ct['io_id']) { $sql = " update {$g5['g5_shop_item_option_table']} set io_stock_qty = io_stock_qty - '{$ct['ct_qty']}' where it_id = '{$ct['it_id']}' and io_id = '{$ct['io_id']}' and io_type = '{$ct['io_type']}' "; } else { $sql = " update {$g5['g5_shop_item_table']} set it_stock_qty = it_stock_qty - '{$ct['ct_qty']}' where it_id = '{$ct['it_id']}' "; }
sql_query($sql);*/ // 재고 반영은 일괄 함수 처리로 변경함 } /* 주문 수정에서 "품절" 선택시 해당 상품 자동 품절 처리하기 else if ($ct_status == '품절') { $stock_use = 1; // 재고에서 뺀다. $sql =" update {$g5['g5_shop_item_table']} set it_stock_qty = 0 where it_id = '{$ct['it_id']}' "; sql_query($sql); } */ }
$point_use = $ct['ct_point_use']; // 회원이면서 포인트가 0보다 크면 // 이미 포인트를 부여했다면 뺀다. if ($mb_id && $ct['ct_point'] && $ct['ct_point_use']) { $point_use = 0; //insert_point($mb_id, (-1) * ($ct[ct_point] * $ct[ct_qty]), "주문번호 $od_id ($ct_id) 취소"); delete_point($mb_id, "@delivery", $mb_id, "$od_id,$ct_id"); }
// 히스토리에 남김 // 히스토리에 남길때는 작업|아이디|시간|IP|그리고 나머지 자료 $now = G5_TIME_YMDHIS; $ct_history="\n$ct_status|{$member['mb_id']}|$now|$REMOTE_ADDR";
if($ct_status=='배송'){ $sql_common = ", ct_delivery_company = '{$_POST['ct_delivery_company'][$k]}', ct_invoice = '{$_POST['ct_invoice'][$k]}', ct_invoice_time = '{$_POST['ct_invoice_time'][$k]}' "; } else { $sql_common = ""; }
$sql = " update {$g5['g5_shop_cart_table']} set ct_point_use = '$point_use', ct_stock_use = '$stock_use', ct_status = '$ct_status', ct_history = CONCAT(ct_history,'$ct_history') $sql_common where od_id = '$od_id' and ct_id = '$ct_id' ";
//_pr($sql); sql_query($sql);
// it_id를 배열에 저장 if($ct_status == '주문' || $ct_status == '취소' || $ct_status == '반품' || $ct_status == '품절' || $ct_status == '완료') $arr_it_id[] = $ct['it_id']; }
// 상품 판매수량 반영 if(is_array($arr_it_id) && !empty($arr_it_id)) { $unq_it_id = array_unique($arr_it_id);
foreach($unq_it_id as $it_id) { $sql2 = " select sum(ct_qty) as sum_qty from {$g5['g5_shop_cart_table']} where it_id = '$it_id' and ct_status = '완료' "; $row2 = sql_fetch($sql2);
$sql3 = " update {$g5['g5_shop_item_table']} set it_sum_qty = '{$row2['sum_qty']}' where it_id = '$it_id' "; sql_query($sql3); } }
// 장바구니 상품 모두 취소일 경우 주문상태 변경 $cancel_change = false; if (in_array($_POST['ct_status'], $status_cancel)) { $sql = " select count(*) as od_count1, SUM(IF(ct_status = '취소' OR ct_status = '반품' OR ct_status = '품절', 1, 0)) as od_count2 from {$g5['g5_shop_cart_table']} where od_id = '$od_id' "; $row = sql_fetch($sql);
if($row['od_count1'] == $row['od_count2']) { $cancel_change = true;
$pg_res_cd = ''; $pg_res_msg = ''; $pg_cancel_log = '';
// PG 신용카드 결제 취소일 때 if($pg_cancel == 1) { $sql = " select * from {$g5['g5_shop_order_table']} where od_id = '$od_id' "; $od = sql_fetch($sql);
if($od['od_tno'] && $od['od_settle_case'] == '신용카드') { switch($od['od_pg']) { case 'lg': include_once(G5_SHOP_PATH.'/settle_lg.inc.php');
$LGD_TID = $od['od_tno'];
$xpay = new XPay($configPath, $CST_PLATFORM);
// Mert Key 설정 $xpay->set_config_value('t'.$LGD_MID, $config['cf_lg_mert_key']); $xpay->set_config_value($LGD_MID, $config['cf_lg_mert_key']);
$xpay->Init_TX($LGD_MID);
$xpay->Set('LGD_TXNAME', 'Cancel'); $xpay->Set('LGD_TID', $LGD_TID);
if ($xpay->TX()) { $res_cd = $xpay->Response_Code(); if($res_cd != '0000' && $res_cd != 'AV11') { $pg_res_cd = $res_cd; $pg_res_msg = $xpay->Response_Msg(); } } else { $pg_res_cd = $xpay->Response_Code(); $pg_res_msg = $xpay->Response_Msg(); } break; case 'inicis': include_once(G5_SHOP_PATH.'/settle_inicis.inc.php'); $cancel_msg = iconv_euckr('쇼핑몰 운영자 승인 취소');
/********************* * 3. 취소 정보 설정 * *********************/ $inipay->SetField("type", "cancel"); // 고정 (절대 수정 불가) $inipay->SetField("mid", $default['de_inicis_mid']); // 상점아이디 /************************************************************************************************** * admin 은 키패스워드 변수명입니다. 수정하시면 안됩니다. 1111의 부분만 수정해서 사용하시기 바랍니다. * 키패스워드는 상점관리자 페이지(https://iniweb.inicis.com)의 비밀번호가 아닙니다. 주의해 주시기 바랍니다. * 키패스워드는 숫자 4자리로만 구성됩니다. 이 값은 키파일 발급시 결정됩니다. * 키패스워드 값을 확인하시려면 상점측에 발급된 키파일 안의 readme.txt 파일을 참조해 주십시오. **************************************************************************************************/ $inipay->SetField("admin", $default['de_inicis_admin_key']); //비대칭 사용키 키패스워드 $inipay->SetField("tid", $od['od_tno']); // 취소할 거래의 거래아이디 $inipay->SetField("cancelmsg", $cancel_msg); // 취소사유
/**************** * 4. 취소 요청 * ****************/ $inipay->startAction();
/**************************************************************** * 5. 취소 결과 * * * * 결과코드 : $inipay->getResult('ResultCode') ("00"이면 취소 성공) * * 결과내용 : $inipay->getResult('ResultMsg') (취소결과에 대한 설명) * * 취소날짜 : $inipay->getResult('CancelDate') (YYYYMMDD) * * 취소시각 : $inipay->getResult('CancelTime') (HHMMSS) * * 현금영수증 취소 승인번호 : $inipay->getResult('CSHR_CancelNum') * * (현금영수증 발급 취소시에만 리턴됨) * ****************************************************************/
$res_cd = $inipay->getResult('ResultCode'); $res_msg = $inipay->getResult('ResultMsg');
if($res_cd != '00') { $pg_res_cd = $res_cd; $pg_res_msg = iconv_utf8($res_msg); } break; case 'nicepay': $cancel_msg = "관리자 주문 취소"; if($default['de_card_test']=='1'){ // 테스트 결제 $mid = "nictest00m"; } else { $mid = $default['de_nicepay_mid']; } $_REQUEST['MID'] = $mid; $_REQUEST['TID'] = $od['od_tno']; $_REQUEST['CancelAmt'] = $od['od_receipt_price']; $_REQUEST['CancelMsg'] = $cancel_msg; $_REQUEST['CancelPwd'] = "123456"; $_REQUEST['Moid'] = $od['od_id']; $_REQUEST['PartialCancelCode'] = 0;
require_once(G5_SHOP_PATH.'/settle_nicepay.inc.php');
/** 2-4. 서비스모드 설정(결제 서비스 : PY0 , 취소 서비스 : CL0) */ $nicepayWEB->setParam("SERVICE_MODE", "CL0");
/** 3. 결제취소 요청 */ $responseDTO = $nicepayWEB->doService($_REQUEST);
$resultCode = $responseDTO->getParameter("ResultCode"); // 결과코드 (정상 :2001(취소성공), 2211(환불성공), 그 외 에러) $resultMsg = $responseDTO->getParameter("ResultMsg"); // 결과메시지 $cancelAmt = $responseDTO->getParameter("CancelAmt"); // 취소금액 $cancelDate = $responseDTO->getParameter("CancelDate"); // 취소일 $cancelTime = $responseDTO->getParameter("CancelTime"); // 취소시간 $cancelNum = $responseDTO->getParameter("CancelNum"); // 취소번호 $payMethod = $responseDTO->getParameter("PayMethod"); // 취소 결제수단 $mid = $responseDTO->getParameter("MID"); // 상점 ID $tid = $responseDTO->getParameter("TID"); // TID break; default: include_once(G5_SHOP_PATH.'/settle_kcp.inc.php'); require_once(G5_SHOP_PATH.'/kcp/pp_ax_hub_lib.php');
// locale ko_KR.euc-kr 로 설정 setlocale(LC_CTYPE, 'ko_KR.euc-kr');
$c_PayPlus = new C_PP_CLI;
$c_PayPlus->mf_clear();
$tno = $od['od_tno']; $tran_cd = '00200000'; $g_conf_home_dir = G5_SHOP_PATH.'/kcp'; $g_conf_key_dir = ''; if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { $g_conf_log_dir = G5_SHOP_PATH.'/kcp/log'; $g_conf_key_dir = G5_SHOP_PATH.'/kcp/bin/pub.key'; } $g_conf_site_cd = $default['de_kcp_mid'];
if (preg_match("/^T000/", $g_conf_site_cd) || $default['de_card_test']) { $g_conf_gw_url = "testpaygw.kcp.co.kr"; } else { $g_conf_gw_url = "paygw.kcp.co.kr"; } $cancel_msg = iconv_euckr('쇼핑몰 운영자 승인 취소'); $cust_ip = $_SERVER['REMOTE_ADDR']; $bSucc_mod_type = "STSC";
$c_PayPlus->mf_set_modx_data( "tno", $tno ); // KCP 원거래 거래번호 $c_PayPlus->mf_set_modx_data( "mod_type", $bSucc_mod_type ); // 원거래 변경 요청 종류 $c_PayPlus->mf_set_modx_data( "mod_ip", $cust_ip ); // 변경 요청자 IP $c_PayPlus->mf_set_modx_data( "mod_desc", $cancel_msg ); // 변경 사유
$c_PayPlus->mf_do_tx( $tno, $g_conf_home_dir, $g_conf_site_cd, $g_conf_site_key, $tran_cd, "", $g_conf_gw_url, $g_conf_gw_port, "payplus_cli_slib", $ordr_idxx, $cust_ip, "3" , 0, 0, $g_conf_key_dir, $g_conf_log_dir);
$res_cd = $c_PayPlus->m_res_cd; $res_msg = $c_PayPlus->m_res_msg;
if($res_cd != '0000') { $pg_res_cd = $res_cd; $pg_res_msg = iconv_utf8($res_msg); }
// locale 설정 초기화 setlocale(LC_CTYPE, ''); break; }
// PG 취소요청 성공했으면 if($pg_res_cd == '') { $pg_cancel_log = ' PG 신용카드 승인취소 처리'; $sql = " update {$g5['g5_shop_order_table']} set od_refund_price = '{$od['od_receipt_price']}' where od_id = '$od_id' "; sql_query($sql); } } }
// 관리자 주문취소 로그 $mod_history .= G5_TIME_YMDHIS.' '.$member['mb_id'].' 주문'.$_POST['ct_status'].' 처리'.$pg_cancel_log."\n"; } }
// 미수금 등의 정보 $info = get_order_info($od_id);
//_pr($info); exit;
if(!$info) alert('주문자료가 존재하지 않습니다.');
if($ct_status=='배송'){ $sql_common = ", od_delivery_company = '{$_POST['ct_delivery_company'][0]}', od_invoice = '{$_POST['ct_invoice'][0]}', od_invoice_time = '{$_POST['ct_invoice_time'][0]}' "; } else { $sql_common = ""; }
$sql = " update {$g5['g5_shop_order_table']} set od_cart_price = '{$info['od_cart_price']}', od_cart_coupon = '{$info['od_cart_coupon']}', od_coupon = '{$info['od_coupon']}', od_cancel_price = '{$info['od_cancel_price']}', od_send_coupon = '{$info['od_send_coupon']}', od_misu = '{$info['od_misu']}', od_tax_mny = '{$info['od_tax_mny']}', od_vat_mny = '{$info['od_vat_mny']}', od_free_mny = '{$info['od_free_mny']}' $sql_common "; if($default['de_vender_use']=='1'){ $sql = $sql .", od_send_cost = '{$info['od_send_cost']}' "; } if ($mod_history) { // 주문변경 히스토리 기록 $sql .= " , od_mod_history = CONCAT(od_mod_history,'$mod_history') "; }
if($cancel_change) { if($ct_status=='반품'){ $sql .= " , od_status = '반품' "; // 주문상품 모두 반품이면 주문 반품 } else { $sql .= " , od_status = '취소' "; // 주문상품 모두 취소, 품절이면 주문 취소 } } else { if (in_array($_POST['ct_status'], $status_normal)) { // 정상인 주문상태만 기록 $sql .= " , od_status = '{$_POST['ct_status']}' "; } }
$sql .= " where od_id = '$od_id' "; sql_query($sql);
// 상품재고부분을 처리한다. set_item_stock_cal("",$od_id); //장바구니 상태에 맞춰서 재고 차감 -> 현재 정책은 입금일때 재고차감 취소될때 재고 복원
// 오픈마켓 주문 정보 수정 if($otms_appy=='1'){ otms_order_status_ch($od_id); }
$qstr = "sort1=$sort1&sort2=$sort2&sel_field=$sel_field&search=$search&page=$page&od_status=$od_status";
$url = "./orderform.php?od_id=$od_id&$qstr";
// 신용카드 취소 때 오류가 있으면 알림 if($pg_cancel == 1 && $pg_res_cd && $pg_res_msg) { alert('오류코드 : '.$pg_res_cd.' 오류내용 : '.$pg_res_msg, $url); } else { // 1.06.06 $od = sql_fetch(" select od_receipt_point from {$g5['g5_shop_order_table']} where od_id = '$od_id' "); if ($od['od_receipt_point']) alert("포인트로 결제한 주문은,\\n\\n주문상태 변경으로 인해 포인트의 가감이 발생하는 경우\\n\\n회원관리 > 포인트관리에서 수작업으로 포인트를 맞추어 주셔야 합니다.", $url); else goto_url($url); } ?>
|