/home/mjc1/public_html/otms_old/ajax.11.product_update.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
<?php
include("./_common.php");

$stime time();

$mode "update11";
$mode_ok "N";

if(
1==1){
    
$site "11";

    if(
$sel_del=='prod_get'){
        
$loginurl "http://api.11st.co.kr/rest/prodmarketservice/prodmarket/{$p_code}";

        
otms_api_log($site,"prodmarket",$loginurl,$logindata,""); // curl 로그 저장
        
$xml curl_call_get($loginurl,$apikey_11);
        
otms_api_log($site,"prodmarket","","",$xml); // xml 로그 저장
        
$res =  cur_11_rtn_conv($xml); // 배열로 변경
        
$result['product'][] = $res;
    } else {
        
$loginurl "http://api.11st.co.kr/rest/prodmarketservice/prodmarket";

        
$logindata '<?xml version="1.0" encoding="euc-kr" standalone="yes"?><SearchProduct><category1/><category2/><category3/><category4/><prdNo/><prdNm/><selStatCd/><selMthdCd/><schDateType/><schBgnDt/><schEndDt/><limit>10</limit><start>0</start><end/></SearchProduct>';

        
otms_api_log($site,"prodmarkets",$loginurl,$logindata,""); // curl 로그 저장
        
$xml curl_call_post($loginurl,$logindata,$apikey_11);
        
otms_api_log($site,"prodmarkets","","",$xml); // xml 로그 저장
        
$res =  cur_11_rtn_conv($xml); // 배열로 변경

        
foreach($res['product'] as $key=>$info){
            
$loginurl "http://api.11st.co.kr/rest/prodmarketservice/prodmarket/{$info['prdNo']}";

            
otms_api_log($site,"prodmarket",$loginurl,$logindata,""); // curl 로그 저장
            
$xml curl_call_get($loginurl,$apikey_11);
            
otms_api_log($site,"prodmarket","","",$xml); // xml 로그 저장
            
$res2 =  cur_11_rtn_conv($xml); // 배열로 변경
            
$result['product'][] = $res2;

        }
    }    

    foreach(
$result['product'] as $key=>$info){
        
$sql "select count(*) as cnt from zom_product where om_site = '{$site}' and p_code = '{$info['prdNo']}' ";
        
$row sql_fetch($sql,$connect_om);

        if(
$row['cnt']=='0'){
            
$sql "insert into zom_product set
                        om_site = '
{$site}', c_code = '{$info['dispCtgrNo']}', p_code = '{$info['prdNo']}', p_name = '{$info['prdNm']}',
                        p_price = '
{$info['selPrc']}', start_date = '{$info['aplBgnDy']}', end_date = '{$info['aplEndDy']}', p_state = '{$info['selStatNm']}', p_state_code = '{$info['selStatCd']}',
                        html_detail = '
{$info['htmlDetail']}', as_detail = '{$info['asDetail']}', bind_deli = '{$info['bndlDlvCnYn']}', sellerPrdCd = '{$info['sellerPrdCd']}', 
                        update_date = '"
.date("Y-m-d H:i:s",time())."'                    
            "
;
        } else {
            
$sql "update zom_product set
                        c_code = '
{$info['dispCtgrNo']}', p_name = '{$info['prdNm']}',
                        p_price = '
{$info['selPrc']}', start_date = '{$info['aplBgnDy']}', end_date = '{$info['aplEndDy']}', p_state = '{$info['selStatNm']}', p_state_code = '{$info['selStatCd']}',
                        html_detail = '
{$info['htmlDetail']}', as_detail = '{$info['asDetail']}', bind_deli = '{$info['bndlDlvCnYn']}', sellerPrdCd = '{$info['sellerPrdCd']}', 
                        update_date = '"
.date("Y-m-d H:i:s",time())."'
                    where om_site = '
{$site}' and p_code = '{$info['prdNo']}'
            "
;
        }
        
$res mysql_query($sql,$connect_om);

        
$loginurl "http://api.11st.co.kr/rest/prodmarketservice/prodmarket/stck/{$info['prdNo']}";

        
otms_api_log($site,"prodmarket_stck",$loginurl,"",""); // curl 로그 저장
        
$xml curl_call_get($loginurl,$apikey_11);
        
otms_api_log($site,"prodmarket_stck","","",$xml); // xml 로그 저장
        
$res_opt =  cur_11_rtn_conv($xml); // 배열로 변경

        //_pr($res_opt);

        
$sql "delete from zom_product_opt where om_site = '{$site}' and p_code = '{$info['prdNo']}' "// 기존 옵션 삭제
        
mysql_query($sql,$connect_om);


        if(
count($res_opt['ProductStock']['addPrc'])=='1'){ // 옵션이 없는 단일 상품일 경우
            
$opt $res_opt['ProductStock'];

            
$sql "insert into zom_product_opt set 
                        om_site = '
{$site}', p_code = '{$opt['prdNo']}', opt_id = '', 
                        opt_grp = '', opt_no = '
{$opt['mixOptNo']}', prdstockno = '{$opt['prdStckNo']}', 
                        opt_price = '0', opt_qty = '
{$opt['stckQty']}', seq = '0', update_date = '".date("Y-m-d H:i:s",time())."'
            "
;
            
//_pr($sql);
            
mysql_query($sql,$connect_om);
        } else { 
// 옵션 상품일 경우 처리
            
$opt_array $res_opt['ProductStock'];
            foreach(
$opt_array as $key=>$opt){

                
$sql "insert into zom_product_opt set 
                            om_site = '
{$site}', p_code = '{$info['prdNo']}', opt_id = '{$opt['mixDtlOptNm']}', 
                            opt_grp = '
{$opt['mixOptNm']}', opt_no = '{$opt['mixOptNo']}', prdstockno = '{$opt['prdStckNo']}', 
                            opt_price = '
{$opt['addPrc']}', opt_qty = '{$opt['stckQty']}', seq = '{$key}', update_date = '".date("Y-m-d H:i:s",time())."'
                "
;
                
//_pr($sql);
                
mysql_query($sql,$connect_om);
            }
        }

        
$addopt_array $res_opt['productComponents']['productComponent']; // 추가옵션 확인
        
if(count($addopt_array)>0){
            foreach(
$addopt_array as $key=>$opt){
                
$sql "insert into zom_product_opt set 
                            om_site = '
{$site}', p_code = '{$info['prdNo']}', opt_id = '{$opt['compPrdNm']}', 
                            opt_grp = '
{$opt['addPrdGrpNm']}', opt_no = 'addopt', prdstockno = '', 
                            opt_price = '
{$opt['addCompPrc']}', opt_qty = '{$opt['compPrdQty']}', seq = '{$key}', update_date = '".date("Y-m-d H:i:s",time())."'
                "
;
                
mysql_query($sql,$connect_om);
            }
        }
        
        
$cnt++;
    }

    
$prd_cnt $cnt;

}

$mode_ok "Y";

$etime time();
$use_time $etime-$stime;

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 
"<prd_cnt>".$prd_cnt."</prd_cnt>";
echo 
"<use_time>".$use_time."</use_time>";
//echo "<sql>".$all_sql."</sql>";
echo "</output>";

?>