/home/mjc1/public_html/j3demo/shop/ajax.order_process.php


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
<?php
$dir 
".";
include_once(
$dir."/_common.php");

$custinfo $cinfo;
$vattype $custinfo['vattype']; // 고객의 부가세 부분

//_pr($_POST); exit;

$ss_od_id get_od_id(); //세션에 저장된 주문번호 가져오고 기존 장바구니가 있으면 주문번호 변경한다.

$mode_ok "Y";

if(
$ss_od_id==$od_id){ // 세션의 주문정보와 주문서 작성의 주문번호를 비교함

    
if($order_mode=='orderform2'){ // 화환 주문시
        
$tmp_ccode $id_ccode;
        
$pinfo product_info_get($p_code2);
        
$id_ccode $tmp_ccode// 함수안에서 비회원 ccode 초기화되는 문제로 임시저장후 원복

        
$loginUrl $j3_shopp_url."/ajax.prod_cart_process.php";
        
$login_data "code={$pinfo['code']}&ct_name={$pinfo['name']}&ct_price={$pinfo['saleprice']}&dmode=&opt_code%5B%5D={$pinfo['code']}&opt_mode%5B%5D=&opt_price%5B%5D={$pinfo['saleprice']}&p_min_buy%5B%5D=0&p_max_buy%5B%5D=0&p_pack_buy%5B%5D=0&qty_default%5B%5D=0&jego%5B%5D={$pinfo['j3go']}&p_ev_code%5B%5D=&qty%5B%5D=1&od_od_id={$od_id}";
        
$res curl_call($loginUrl,$login_data);

        
$s_hpno $s_hpno1."-".$s_hpno2;
        
$consignee_telno $consignee_telno1."-".$consignee_telno2;
        
$s_telno $visit_take_day1." ".$visit_take_day2."시".$visit_take_day3."분";

        
$xml simplexml_load_string($res"SimpleXMLElement"LIBXML_NOCDATA);
        if(
$xml->mode_ok=='Y'){
            
$sql "update shop_cart set ct_state = '1' where od_id='{$od_id}'";
            
mysql_query($sql,$connect_j3);

            
$all_price 0;
            
$sql "select * from shop_cart where od_id='{$od_id}' ";
            
$res mysql_query($sql,$connect_j3);
            
$idx_list "";
            while(
$info mysql_fetch_array($res)){
                
$all_price += $info['ct_tot_amt'];
                
$idx_list .= "'{$info['idx']}',";
            }
            
$idx_list substr($idx_list,0,strlen($idx_list)-1);
        } else {
            
$mode_ok "N";
        }
    }

    
$sql "select od_id, pcode from shop_cart where idx in ({$idx_list});"
    
$res mysql_query($sql,$connect_j3);
    
$where "";
    while(
$info=mysql_fetch_array($res)){
        
$where .= " (a.od_id = '{$info['od_id']}' and a.pcode = '{$info['pcode']}') or "// 옵션 상품이 있으므로 장바구니 idx값으로 od_id, pcode를 받아와서 옵션상품도 체크할수 있도록 가져온다
    
}
    
$where "and (".substr($where,0,strlen($where)-3).")";
    
$sql "select a.*, b.norm, b.tax_yn, c.p_soldout, c.p_use, c.p_price_tel, c.p_sell_tel from shop_cart a 
                    inner join product_m b on if(a.opt_mode='',a.pcode,a.opt_pcode) = b.code
                    inner join product_s c on if(a.opt_mode='',a.pcode,a.opt_pcode) = c.pcode
            where 1=1 
$where order by od_id desc, ev_code, pcode, if(a.opt_mode='','1',if(a.opt_mode='opt','2','3')) asc";
    
//_pr($sql);
    
$res mysql_query($sql,$connect_j3);
    
$ct_idx_list "";
    while(
$info=mysql_fetch_array($res)){
        
$ct_idx_list .= $info['idx'].",";
        if(
$info['ct_state']!='1'){ $mode_ok "N"$msg "주문정보가 변경되었습니다. 다시 주문하시기 바랍니다.1"; break; }
        if(
$info['opt_mode']==''){ // 본상품과 옵션구분해서 키 매출가를 지정한다.
            
$info['jego'] = product_jego_get($info['pcode']);
            
//$info['key_price'] = $info['ct_price']*$info['ct_qty'];
            
$info['key_price'] = $info['ct_tot_amt'];
            
$info['key_code'] = $info['pcode'];
            
$info['prod_title'] = $info['ct_name'];
            
$info['opt_price'] = $info['ct_price'];
        } else {
            
$info['jego'] = product_jego_get($info['opt_pcode']);
            
//$info['key_price'] = $info['opt_price']*$info['ct_qty'];
            
$info['key_price'] = $info['ct_tot_amt'];
            
$info['key_code'] = $info['opt_pcode'];
            if(
$info['opt_mode']=='opt'){ $info['prod_title'] = "(옵션){$info['opt_name']}"; } else { $info['prod_title'] = "(추가){$info['opt_name']}"; }
        }
        
$jego_ck_code[$info['key_code']] += $info['ct_qty']; // 옵션상품과 본상품등으로 혼재된 상품재고를 한개로 묶는 작업
        
$ct_array[] = $info;
    }
    
$ct_idx_list substr($ct_idx_list,0,strlen($ct_idx_list)-1);
    if(
$mode_ok=="Y"){
        for(
$i=0;$i<count($ct_array);$i++){ // 재고 체크
            
$ct $ct_array[$i];
            
//_pr($ct['jego']."^".$jego_ck_code[$ct['kcode']]);
            
if($ct['p_use']!='1'){
                
$mode_ok "N"$msg "{$ct['prod_title']} 상품은 판매하지 않는 상품입니다."; break;
            }        
            if(
$ct['p_soldout']=='1'){
                
$mode_ok "N"$msg "{$ct['prod_title']} 상품은 품절 상품입니다."; break;
            }        
            if(
$ct['p_price_tel']=='1'){
                
$mode_ok "N"$msg "{$ct['prod_title']} 상품은 전화문의 상품이라서 주문하실수 없습니다.";
            }
            if(
$ct['p_sell_tel']=='1'){
                
$mode_ok "N"$msg "{$ct['prod_title']} {$configshop['sell_tel_text']}";
            }
            if(
$ct['jego']<$jego_ck_code[$ct['key_code']]){
                
$mode_ok "N"$msg "{$ct['prod_title']} 상품의 재고가 부족합니다. 재고:{$ct['jego']}"; break;
            }        
            if(
$_SERVER['REMOTE_ADDR']=='58.151.27.172'){
                
//$mode_ok = "N";
            
}
        }
    }

    if(
$visit_take=='1'){ // 방문수령시 체크 패스~

    
} else {
        
$consignee_zipcode preg_replace("/[^0-9]/"""$consignee_zipcode);
        if(
strlen($consignee_zipcode)!='5'){
            
$mode_ok "N"$msg "잘못된 우편번호가 입력되었습니다.";
        }
    }

    
//_pr($ct_array); $mode_ok = "N";
    
if($mode_ok=="Y"){
        
$sum_ct_price 0;
        
$sum_ct_point 0;
        
$sale_ord_d_sql "";
        
$cnt 1;
        
$prod_title "";
        foreach(
$ct_array as $key=>$info){
            
$vats vat_price_get($vattype$info['tax_yn'], $info['key_price']); // 부가세 받아옴
            
$ct_amt $vats['ct_amt']; $ct_vat $vats['ct_vat']; $ct_tot_amt $vats['ct_tot_amt']; // 부가세 정보 분할

            
if($key==0){ $prod_title "{$info['prod_title']} ({$info['key_price']}원)"; }

            
$sale_ord_d[] = "insert into sale_ord_d set
                                    midx = '[midx]', seq = '
{$cnt}', pcode = '{$info['key_code']}', pname = '{$info['prod_title']}', pnorm = '{$info['norm']}',
                                    qty = '
{$info['ct_qty']}', price = '{$info['opt_price']}', sup_amt = '{$ct_amt}', vat = '{$ct_vat}',
                                    tot_amt = '
{$info['key_price']}', tax_type = '{$info['tax_yn']}', input_type = '98', remarks = '{$info['idx']}', data_created = '".date("Y-m-d H:i:s",time())."';
            "
;
            
/* old 버젼 방식 : 상단방식은 VAR 재계산해서 처리함
                $sale_ord_d[] = "insert into sale_ord_d set
                                    midx = '[midx]', seq = '{$cnt}', pcode = '{$info['key_code']}', pname = '{$info['prod_title']}', pnorm = '{$info['norm']}',
                                    qty = '{$info['ct_qty']}', price = '{$info['opt_price']}', sup_amt = '{$info['ct_amt']}', vat = '{$info['ct_vat']}',
                                    tot_amt = '{$info['key_price']}', tax_type = '{$info['tax_yn']}', input_type = '98', remarks = '{$info['idx']}', data_created = '".date("Y-m-d H:i:s",time())."';
            ";*/

            
$sum_ct_price += $info['key_price'];
            
$sum_ct_point += $info['ct_point']*$info['ct_qty'];
            
$cnt++;

            if(
$info['key_price']==$ct_vat && $info['key_price']>0){
                
$mode_ok "N"$msg "{$info['prod_title']} 상품의 장바구니 부가세가 정상적이 않습니다..{$info['key_price']} / {$ct_vat}";
            }
        }

        
//_pr($sale_ord_d);        exit;
        
if($sum_ct_price!=$all_price && $configshop['prod_danga_view']!='1'){ // 상품 부가세 제외 표시에서는 금액이 틀릴수 있으므로 해당부분 체크하지 않음
            
$mode_ok "N"$msg "주문시 금액과 장바구니 금액이 동일하지 않습니다.{$sum_ct_price} / {$all_price}";
        }
        if(
$mode_ok=="Y"){
            
$sum_pay_price $sum_ct_price+$deli_price+$deli_price2;
            if(
$visit_take=='1'){ // 방문수령 선택시
                
$freight_term '0'
                
$sale_ord_d[] = "insert into sale_ord_d set
                                            midx = '[midx]', seq = '
{$cnt}', pcode = '1', pname = '방문수령 ({$visit_take_day})',
                                            qty = '1', price = '0', sup_amt = '0', vat = '0',
                                            tot_amt = '0', tax_type = '1', input_type = '98', data_created = '"
.date("Y-m-d H:i:s",time())."';";        // 방문수령 선택시
                
$cnt++;
            }
            if(
$deli_price>0){ // 운임조건
                
$freight_term '1'
                
$vats vat_price_get("1","1",$deli_price);
                
$sale_ord_d[] = "insert into sale_ord_d set
                                            midx = '[midx]', seq = '
{$cnt}', pcode = '1', pname = '쇼핑몰배송비',
                                            qty = '1', price = '
{$deli_price}', sup_amt = '{$vats['ct_amt']}', vat = '{$vats['ct_vat']}',
                                            tot_amt = '
{$deli_price}', tax_type = '1', input_type = '98', data_created = '".date("Y-m-d H:i:s",time())."';";        // 배송비가 있을경우 임의상품으로 배송비 추가함
                
$cnt++;
            } else { 
                
$freight_term '0'
            } 
            if(
$deli_price2>0){ // 운임조건 2
                
$freight_term '1'
                
$vats vat_price_get("1","1",$deli_price2);
                
$sale_ord_d[] = "insert into sale_ord_d set
                                            midx = '[midx]', seq = '
{$cnt}', pcode = '1', pname = '도서/산간배송비',
                                            qty = '1', price = '
{$deli_price2}', sup_amt = '{$vats['ct_amt']}', vat = '{$vats['ct_vat']}',
                                            tot_amt = '
{$deli_price2}', tax_type = '1', input_type = '98', data_created = '".date("Y-m-d H:i:s",time())."';";        // 도서/산간 배송비가 있을경우 임의상품으로 배송비 추가함
            
}

            if(
$id_ccode=='0'){ // 비회원인결우 비회원 거래처 추가함
                
if(table_field_ck("sale_ord_s""order_id")){
                    
$id_cust 'GUEST';
                    
$sale_ord_s_add " , order_id = '{$id_cust}' ";
                }
                
$id_ccode $configshop['guest_ccode'];
            } else {
                
$sale_ord_s_add "";
            }

            
$sale_ord_m_sql "insert into sale_ord_m set
                        orddate = '"
.date("Y-m-d",time())."', deliverydate = '".date("Y-m-d",time())."', route = '1', ordstate = '0', ccode = '{$id_ccode}', 
                        ocode = '
{$configshop['office_code']}', input_type = '98', consignee_name = '{$consignee_name}', consignee_zipcode = '{$consignee_zipcode}', 
                        consignee_addr_m = '
{$consignee_addr_m}', consignee_addr_d = '{$consignee_addr_d}', consignee_telno = '{$consignee_telno}', consignee_hpno = '{$consignee_hpno}', 
                        transport_msg = '
{$transport_msg}', freight_term = '{$freight_term}', data_created = '".date("Y-m-d H:i:s",time())."';";
            
$res mysql_query($sale_ord_m_sql,$connect_j3); // 수발주 마스터에 저장
            
$midx mysql_insert_id($connect_j3);
            
insert_log("sale_ord_m"$midx$sale_ord_m_sql); // SQL 인서트 로그
            
            
foreach($sale_ord_d as $key=>$sql){
                
$sql str_replace("[midx]",$midx,$sql);
                
mysql_query($sql,$connect_j3); // 수발주 디테일에 저장
                
insert_log("sale_ord_d"$midx$sql); // SQL 인서트 로그
            
}

            if(
$pay_type=="무통장"){ 
                
$bb explode("^",$bankbook);
                
$s_app_info $bb[0]; 
                
$s_app_no $bb[1]; 
            } else {
                
$s_app_no "";
            }
            if(
is_mobile()){ $s_mobile "1"; } else { $s_mobile "0"; }

            
$sale_ord_s "insert into sale_ord_s set 
                                    midx = '
{$midx}', od_id = '{$od_id}', s_name = '{$s_name}', s_telno = '{$s_telno}', s_hpno = '{$s_hpno}', 
                                    s_zipcode = '
{$s_zipcode}', s_addr_m = '{$s_addr_m}', s_addr_d = '{$s_addr_d}', s_email = '{$s_email}', cart_price = '{$sum_ct_price}', 
                                    deli_price = '
{$deli_price}', deli_price2 = '{$deli_price2}', dc_price = '{$dc_price}', save_point = '{$sum_ct_point}', use_point = '{$use_pt}', pay_type = '{$pay_type}', 
                                    deposit = '0', income_name = '
{$income_name}', s_app_no = '{$s_app_no}', s_app_info = '{$s_app_info}', s_mobile = '{$s_mobile}', s_order_his = '' {$sale_ord_s_add} "
            
$res mysql_query($sale_ord_s,$connect_j3); // 수발주 쇼핑몰 테이블에 저장
            
insert_log("sale_ord_s"$midx$sale_ord_s); // SQL 인서트 로그

            
$sql "update shop_cart set ct_state = '2', midx = '{$midx}' where idx in ({$ct_idx_list}) ";
            
mysql_query($sql,$connect_j3); // 장바구니 정보 주문완료(2) 처리

            // 남은 장바구니 재 설정
            
$ss_od_id get_uniqid();
            
$_SESSION['ss_od_id'] = $ss_od_id// 주문완료후 새로운 주문번호를 딴다
            
init_cart($ss_od_id);

            
// 주문완료 메일 처리
            
$oinfo order_info_get($midx);
            
ob_start();
            include_once (
"{$j3_shop_path}/mail/order_mail.php");
            
$ma_content ob_get_contents();
            
ob_end_clean();

            
$ma_subject "{$oinfo['od_id']} 주문이 완료 되었습니다.";

            
$snd_email $config['admin_email'];
            
$rcv_email $oinfo['s_email'];
            
$mail = new PHPMailer;
            
$rtn email_send($mail$ma_subject$ma_content$snd_email$rcv_email);
            
// 주문완료 메일 처리 끝

            
if($order_mode=='orderform2'){ // 화환 주문시
                
$oinfo['sms_msg'] = "
[상품명] 
{$prod_title}
[주문자연락처] 
{$oinfo['s_hpno']}
[입금자명] 
{$oinfo['income_name']}
[수령자명] 
{$oinfo['consignee_name']}
[수령자연락처] 
{$oinfo['consignee_telno']}
[배송주소] (
{$oinfo['consignee_zipcode']}{$oinfo['consignee_addr_m']} {$oinfo['consignee_addr_d']}
[배송위치(메모)] 
{$oinfo['s_email']}
[리본내용]
{$oinfo['transport_msg']}
[배송희망일] 
{$oinfo['s_telno']}";
            }

            if(
$config['shop_sms_use2']=='1'){ // 주문시 회원에게 SMS 전송
                
$sms_msg sms_send_msg_conv("2"$oinfo); // 주문시 메시지 변환
                
$rtn call_sms_send($oinfo['s_hpno'], $config['send_hp'], $sms_msg);
            } else if(
$config['shop_sms_use2']=='2'){ // 주문시 회원에게 LMS 전송
                
$sms_msg sms_send_msg_conv("2"$oinfo); // 주문시 메시지 변환
                
$rtn call_lms_send($oinfo['s_hpno'], $config['send_hp'], $sms_msg);
            }

            if(
$config['shop_sms_use3']=='1'){ // 주문시 관리자에게 SMS 전송
                
$sms_msg sms_send_msg_conv("3"$oinfo); // 주문시 관리자에게 메시지 변환
                
$rtn call_sms_send($config['rtn_hpno'], $config['send_hp'], $sms_msg);
            } else if(
$config['shop_sms_use3']=='2'){ // 주문시 관리자에게 LMS 전송
                
$sms_msg sms_send_msg_conv("3"$oinfo); // 주문시 관리자에게 메시지 변환
                
$rtn call_lms_send($config['rtn_hpno'], $config['send_hp'], $sms_msg);
            }

            if(
$config['shop_kakao_use2']=='1'){ // 주문시 회원에게 알림톡 전송
                
$rtn call_kakako_send($oinfo['s_hpno'], $config['kakao_sender'], $oinfo'2');
            }
            if(
$config['shop_kakao_use3']=='1'){ // 주문시 관리자에게 알림톡 전송
                
$rtn call_kakako_send($config['kakao_reciever'], $config['kakao_sender'], $oinfo'3');
            }

            
//_pr($sale_ord_d);
        
}
    }
} else {
    
$mode_ok "N"$msg "주문정보가 변경되었습니다. 다시 주문하시기 바랍니다.2";
}


echo 
"<?php xml version='1.0' encoding='utf-8'?><output>";
echo 
"<mode>".$mode."</mode>";
echo 
"<mode_ok>".$mode_ok."</mode_ok>";
echo 
"<rtn_url>".$rtn_url."</rtn_url>";
echo 
"<msg>".$msg."</msg>";
echo 
"<midx>".$midx."</midx>";
echo 
"<pay_type>".$pay_type."</pay_type>";
//echo "<sql>".$all_sql."</sql>";
echo "</output>";
?>