/home/mjc1/public_html/otms_old/ajax.11.category_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
136
137
138
139
140
141
142
143
144
145
146
147
<?php
include("./_common.php");

$stime time();

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

if(
1==1){

    
$site "11";

    
$loginurl "http://api.11st.co.kr/rest/cateservice/category";

    
otms_api_log($site,"category",$loginurl,$logindata,""); // curl 로그 저장
    
$xml curl_call_get($loginurl);
    
otms_api_log($site,"category","","",$xml); // xml 로그 저장
    
$result =  cur_11_rtn_conv($xml); // 배열로 변경

    
$sql "delete from zom_category where 1=1 ";
    
$res mysql_query($sql,$connect_om);

    
$cnt 0;

    foreach(
$result['category'] as $key=>$info){
    
//    $info['dispNm'] = iconv("euckr","utf-8",$info['dispNm']);
        /*$sql = "select count(*) as cnt from zom_category where om_site = '{$site}' and c_code = '{$info['dispNo']}' ";
        $row = sql_fetch($sql,$connect_om);

        if($row['cnt']=='0'){*/
            
$sql "insert into zom_category set 
                        om_site = '
$site', c_code = '{$info['dispNo']}', c_depth = '{$info['depth']}', c_name = '{$info['dispNm']}', c_parent = '{$info['parentDispNo']}', update_date = '".date("Y-m-d H:i:s",time())."' 
            "
;
        
/*} else {
            $sql = "update zom_category set 
                        c_depth = '{$info['depth']}', c_name = '{$info['dispNm']}', c_parent = '{$info['parentDispNo']}', update_date = '".date("Y-m-d H:i:s",time())."' 
                    where om_site = '$site' and c_code = '{$info['dispNo']}'
            ";
        }*/
        //_pr($sql);
        
$res mysql_query($sql,$connect_om);

        
$cnt++;
    }

    
$cate_cnt $cnt;

    
/*$sql = "update zom_category set c_sort = '' ";
    $res = mysql_query($sql,$connect_om);*/

    
$sql "select * from zom_category where om_site = '11' and c_depth = '1' order by c_code"// 1차분류 처리
    
$res mysql_query($sql,$connect_om);
    while(
$info=mysql_fetch_array($res)){
        
$cate_array[] = $info;
    }

    
$cnt 1;
    foreach(
$cate_array as $key=>$info){
        
$padd1 str_pad($cnt,3,"0",STR_PAD_LEFT);
        if(
$info['c_depth']=='1'){
            
$c_sort str_pad($padd1,12,"0",STR_PAD_RIGHT);
        }
        
$sql "update zom_category set c_sort = '{$c_sort}' where idx = '{$info['idx']}' ";
        
mysql_query($sql,$connect_om);
        
$cnt++;
    }

    
$cate_array null;
    
$sql "select a.*, ifnull(b.c_sort,'') as pc_sort from zom_category a left join zom_category b on a.c_parent = b.c_code where a.om_site = '11' and a.c_depth = '2' and b.c_sort <> '' order by a.c_parent, a.c_code;"// 2차분류 처리
    
$res mysql_query($sql,$connect_om);
    while(
$info=mysql_fetch_array($res)){
        
$cate_array[] = $info;
    }

    
$tmp_parent '';
    foreach(
$cate_array as $key=>$info){
        if(
$tmp_parent!=$info['c_parent']){
            
$cnt=1$tmp_parent $info['c_parent'];
        }
        
$padd1 str_pad($cnt,3,"0",STR_PAD_LEFT);
        
$c_sort substr($info['pc_sort'],0,3).$padd1."000000";

        
$sql "update zom_category set c_sort = '{$c_sort}' where idx = '{$info['idx']}' ";
        
mysql_query($sql,$connect_om);

        
$cnt++;
    }

    
$cate_array null;
    
$sql "select a.*, ifnull(b.c_sort,'') as pc_sort from zom_category a left join zom_category b on a.c_parent = b.c_code where a.om_site = '11' and a.c_depth = '3' and b.c_sort <> '' order by a.c_parent, a.c_code;"// 3차분류 처리
    
$res mysql_query($sql,$connect_om);
    while(
$info=mysql_fetch_array($res)){
        
$cate_array[] = $info;
    }

    
$tmp_parent '';
    foreach(
$cate_array as $key=>$info){
        if(
$tmp_parent!=$info['c_parent']){
            
$cnt=1$tmp_parent $info['c_parent'];
        }
        
$padd1 str_pad($cnt,3,"0",STR_PAD_LEFT);
        
$c_sort substr($info['pc_sort'],0,6).$padd1."000";

        
$sql "update zom_category set c_sort = '{$c_sort}' where idx = '{$info['idx']}' ";
        
mysql_query($sql,$connect_om);

        
$cnt++;
    }

    
$cate_array null;
    
$sql "select a.*, ifnull(b.c_sort,'') as pc_sort from zom_category a left join zom_category b on a.c_parent = b.c_code where a.om_site = '11' and a.c_depth = '4' and b.c_sort <> '' order by a.c_parent, a.c_code;"// 4차분류 처리
    
$res mysql_query($sql,$connect_om);
    while(
$info=mysql_fetch_array($res)){
        
$cate_array[] = $info;
    }

    
$tmp_parent '';
    foreach(
$cate_array as $key=>$info){
        if(
$tmp_parent!=$info['c_parent']){
            
$cnt=1$tmp_parent $info['c_parent'];
        }
        
$padd1 str_pad($cnt,3,"0",STR_PAD_LEFT);
        
$c_sort substr($info['pc_sort'],0,9).$padd1;

        
$sql "update zom_category set c_sort = '{$c_sort}' where idx = '{$info['idx']}' ";
        
mysql_query($sql,$connect_om);

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

?>