source: branches/dev/data/class/SC_CustomerList.php @ 11637

Revision 11637, 11.4 KB checked in by uehara, 19 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8/*  [̾¾Î] SC_CustomerList
9 *  [³µÍ×] ²ñ°÷¸¡º÷ÍÑ¥¯¥é¥¹
10 */
11class SC_CustomerList extends SC_SelectSql {
12
13    var $arrColumnCSV;
14   
15    function SC_CustomerList($array, $mode = '') {
16        parent::SC_SelectSql($array);
17       
18        if($mode == "") {
19            // ²ñ°÷ËÜÅÐÏ¿²ñ°÷¤Çºï½ü¤·¤Æ¤¤¤Ê¤¤²ñ°÷
20            $this->setWhere("status = 2 AND del_flg = 0 ");     
21            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
22            $regdate_col = 'dtb_customer.update_date';
23        }
24       
25        if($mode == "customer") {
26            // ´ÉÍý¼Ô¥Ú¡¼¥¸¸ÜµÒ¸¡º÷¤Î¾ì¹ç²¾ÅÐÏ¿²ñ°÷¤â¸¡º÷
27            $this->setWhere( "(status = 1 OR status = 2) AND del_flg = 0 ");       
28            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
29            $regdate_col = 'dtb_customer.update_date';
30        }
31               
32        // ¥á¡¼¥ë¥Þ¥¬¥¸¥ó¤Î¾ì¹ç     
33        if($mode == "magazine") {
34            $this->setWhere("(del_flg = 0 OR del_flg IS NULL)");
35            $this->setWhere("status = 2");
36           
37            /*¡¡²ñ°÷¤Î¤ßÂоݤȤ¹¤ë¤¿¤áºï½ü
38            if(is_array($this->arrSql['customer'])) {
39                $tmp_where = "";
40                foreach($this->arrSql['customer'] as $val) {
41                    if($tmp_where != "") {
42                        $tmp_where.= " OR ";
43                    }                   
44                    switch($val) {
45                    // ²ñ°÷
46                    case '1':
47                        $tmp_where.= "status = 2";
48                        break;
49                    // ¥á¥ë¥Þ¥¬ÅÐÏ¿
50                    case '2':
51                        $tmp_where.= "customer_id IS NULL";
52                        break;
53                    // CSVÅÐÏ¿
54                    case '3':
55                        $tmp_where.= "customer_id IS NULL";
56                        break;
57                    default:
58                        $tmp_where = "";
59                        break;
60                    }
61                }
62                if($tmp_where != "") {
63                    $tmp_where = "(" . $tmp_where . ")";
64                }
65                $this->setWhere($tmp_where);
66            }
67            */
68            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
69            $regdate_col = 'dtb_customer.create_date';
70        }
71               
72        // ¸ÜµÒID
73        if ( strlen($this->arrSql['customer_id']) > 0 ) {
74            $this->setWhere( "customer_id =  ?" );
75            $this->arrVal[] = $this->arrSql['customer_id'];
76        }
77       
78        // ̾Á°
79        if ( strlen($this->arrSql['name']) > 0 ) {
80            if(DB_TYPE == "pgsql"){
81                $this->setWhere("(name01 || name02 LIKE ?)" );
82            }elseif(DB_TYPE == "mysql"){
83                $this->setWhere("concat(name01,name02) LIKE ?" );
84            }
85
86            $searchName = $this->addSearchStr($this->arrSql['name']);
87            $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchName);
88        }
89
90        //¡¡Ì¾Á°¡Ê¥«¥Ê¡Ë
91        if ( strlen($this->arrSql['kana']) > 0 ) {
92            if(DB_TYPE == "pgsql"){
93                $this->setWhere("(kana01 || kana02 LIKE ?)");
94            }elseif(DB_TYPE == "mysql"){
95                $this->setWhere("concat(kana01,kana02) LIKE ?" );
96            }
97            $searchKana = $this->addSearchStr($this->arrSql['kana']);
98            $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchKana);
99        }
100       
101        //¡¡ÅÔÆ»Éܸ©
102        if ( strlen($this->arrSql['pref']) > 0 ) {
103            $this->setWhere( "pref = ?" );
104            $this->arrVal[] = $this->arrSql['pref'];
105        }
106
107        //¡¡ÅÅÏÃÈÖ¹æ
108        if ( is_numeric( $this->arrSql['tel'] ) ) {
109            if(DB_TYPE == "pgsql"){
110                $this->setWhere( "(tel01 || tel02 || tel03 LIKE ?)" );
111            }elseif(DB_TYPE == "mysql"){
112                $this->setWhere("concat(tel01,tel02,tel03) LIKE ?" );
113            }
114            $searchTel = $this->addSearchStr($this->arrSql['tel']);
115            $this->arrVal[] = ereg_replace("-", "", $searchTel);
116        }
117       
118        //¡¡À­ÊÌ
119        if ( is_array( $this->arrSql['sex'] ) ){
120            $arrSexVal = $this->setItemTerm( $this->arrSql['sex'] ,"sex" );
121            foreach ($arrSexVal as $data) {
122                $this->arrVal[] = $data;
123            }
124        }
125
126        //¡¡¿¦¶È
127        if ( is_array( $this->arrSql['job'] ) ){
128            if ( in_array("ÉÔÌÀ", $this->arrSql['job'] ) ) {
129                $arrJobVal = $this->setItemTermWithNull( $this->arrSql['job'] ,"job" );
130            } else {
131                $arrJobVal = $this->setItemTerm( $this->arrSql['job'] ,"job" );
132            }
133            if (is_array($arrJobVal)) {
134                foreach ($arrJobVal as $data) {
135                    $this->arrVal[] = $data;
136                }
137            }
138        }
139
140        //¡¡E-MAIL
141        if (strlen($this->arrSql['email']) > 0) {
142
143            $search_all = 'all';
144            $search_pc = 'email';
145            $search_mobile = 'email_mobile';
146           
147            //¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊ£¿ô¤Î¾ò·ï»ØÄê²Äǽ¤Ë
148            $this->arrSql['email'] = explode(",", $this->arrSql['email']);
149           
150            //¡¡¥á¡¼¥ë¼ïÊÌ
151            if ( is_array( $this->arrSql['mail_type'] ) ){
152
153                if(in_array(MAIL_TYPE_PC, $this->arrSql['mail_type']) && !in_array(MAIL_TYPE_MOBILE, $this->arrSql['mail_type'])) {
154                    // PC¤Î¤ß¸¡º÷
155                    $search_patern = $search_pc;           
156                } else if(!in_array(MAIL_TYPE_PC, $this->arrSql['mail_type']) && in_array(MAIL_TYPE_MOBILE, $this->arrSql['mail_type'])) {
157                    // ¥â¥Ð¥¤¥ë¤Î¤ß¸¡º÷
158                    $search_patern = $search_mobile;
159                } else {
160                    // Á´¸¡º÷
161                    $search_patern = $search_all;
162                }
163               
164            } else {
165                // Á´¸¡º÷
166                $search_patern = $search_all;               
167            }
168
169
170            $sql_where = "";
171           
172            foreach($this->arrSql['email'] as $val) {
173                $val = trim($val);
174                //¸¡º÷¾ò·ï¤ò´Þ¤Þ¤Ê¤¤
175                if($this->arrSql['not_emailinc'] == '1') {
176                   
177                    if($sql_where != "") {
178                        $sql_where .= "AND ";
179                    }                       
180                   
181                    if($search_patern == $search_all) {
182                        $sql_where .= "(dtb_customer.$search_pc NOT ILIKE ? OR dtb_customer.$search_mobile NOT ILIKE ?) ";
183                    } else {
184                        $sql_where .= "dtb_customer.$search_patern NOT ILIKE ? ";                       
185                    }
186                   
187                } else {               
188                    if($sql_where != "") {
189                        $sql_where .= "OR ";
190                    }
191                       
192                    if($search_patern == $search_all) {
193                        $sql_where .= "(dtb_customer.$search_pc ILIKE ? OR dtb_customer.$search_mobile ILIKE ?) ";
194                    } else {
195                        $sql_where .= "dtb_customer.$search_patern ILIKE ?  ";
196                    }
197                }
198                $searchEmail = $this->addSearchStr($val);
199               
200                if($search_patern == $search_all) {
201                    $this->arrVal[] = $searchEmail;
202                    $this->arrVal[] = $searchEmail;
203                } else {
204                    $this->arrVal[] = $searchEmail;                 
205                }
206            }
207            $this->setWhere($sql_where);
208        }
209                   
210        //¡¡HTML-mail
211        if ( $mode == 'magazine' ){
212            if ( strlen($this->arrSql['htmlmail']) > 0 ) {
213                $this->setWhere( " mailmaga_flg = ? ");
214                $this->arrVal[] = $this->arrSql['htmlmail'];
215            } else {
216                $this->setWhere( " (mailmaga_flg = 1 or mailmaga_flg = 2) ");
217            }
218        }
219       
220        // ¹ØÆþ¶â³Û»ØÄê
221        if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) {
222            $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total");
223            foreach ($arrBuyTotal as $data1) {
224                $this->arrVal[] = $data1;
225            }
226        }
227
228        // ¹ØÆþ²ó¿ô»ØÄê
229        if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) {
230            $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times");
231            foreach ($arrBuyTimes as $data2) {
232                $this->arrVal[] = $data2;
233            }
234        }
235       
236        // ÃÂÀ¸Æü´ü´Ö»ØÄê
237        if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) ||
238              strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) {
239
240            $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day']
241                      , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth");
242            if (is_array($arrBirth)) {
243                foreach ($arrBirth as $data3) {
244                    $this->arrVal[] = $data3;
245                }
246            }
247        }
248               
249        // ÃÂÀ¸·î¤Î¸¡º÷
250        if (is_numeric($this->arrSql["birth_month"])) {
251            $this->setWhere(" EXTRACT(month from birth) = ?"); 
252            $this->arrVal[] = $this->arrSql["birth_month"];
253        }
254           
255        // ÅÐÏ¿´ü´Ö»ØÄê
256        if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) ||
257                (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) {
258
259            $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day']
260                            , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col);
261            if (is_array($arrRegistTime)) {
262                foreach ($arrRegistTime as $data4) {
263                    $this->arrVal[] = $data4;
264                }
265            }
266        }
267           
268        // ºÇ½ª¹ØÆþÆü»ØÄê
269        if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) ||
270                (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) {
271            $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day']
272                            , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date");
273            if (is_array($arrRegistTime)) {
274                foreach ($arrRegistTime as $data4) {
275                    $this->arrVal[] = $data4;
276                }
277            }
278        }
279       
280        //¹ØÆþ¾¦ÉÊ¥³¡¼¥É
281        if ( strlen($this->arrSql['buy_product_code']) > 0 ) {
282            $this->setWhere( "customer_id IN (SELECT customer_id FROM dtb_order WHERE order_id IN (SELECT order_id FROM dtb_order_detail WHERE product_code LIKE ? ))");
283            $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']);
284            $this->arrVal[] = $search_buyproduct_code;
285        }
286
287        //¹ØÆþ¾¦ÉÊ̾¾Î
288        if ( strlen($this->arrSql['buy_product_name']) > 0 ) {
289            $this->setWhere( "customer_id IN (SELECT customer_id FROM dtb_order WHERE order_id IN (SELECT order_id FROM dtb_order_detail WHERE product_name LIKE ? ))");
290            $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']);
291            $this->arrVal[] = $search_buyproduct_name;
292        }
293       
294        //¥«¥Æ¥´¥ê¡¼¤òÁªÂò¤·¤Æ¤¤¤ë¾ì¹ç¤Î¤ß¹Ê¹þ¸¡º÷¤ò¹Ô¤¦
295        if ( strlen($this->arrSql['category_id']) != ""){
296            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¸¡º÷¤ò¹Ô¤¦SQLʸÀ¸À®
297            list($tmp_where, $tmp_arrval) = sfGetCatWhere(sfManualEscape($this->arrSql['category_id']));
298
299            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¤ß¤¬²Äǽ¤Î¾ì¹ç
300            if($tmp_where != "") {
301                $this->setWhere( " customer_id IN (SELECT distinct customer_id FROM dtb_order WHERE order_id IN (SELECT distinct order_id FROM dtb_order_detail WHERE product_id IN (SELECT product_id FROM dtb_products WHERE ".$tmp_where." ))) ");
302                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
303            }
304        }
305        //¡¡·ÈÂÓÅÅÏÃÈÖ¹æ
306        if ( is_numeric( $this->arrSql['cell'] ) ) {
307            $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" );
308            $searchTel = $this->addSearchStr($this->arrSql['cell']);
309            $this->arrVal[] = ereg_replace("-", "", $searchTel);
310        }
311
312        //¡¡¥­¥ã¥ó¥Ú¡¼¥ó
313        if ( is_numeric( $this->arrSql['campaign_id'] ) ) {
314            $this->setWhere( " customer_id IN (SELECT distinct customer_id FROM dtb_campaign_order WHERE campaign_id = ?)" );
315            $this->arrVal[] = $this->arrSql['campaign_id'];
316        }
317               
318        $this->setOrder( "customer_id DESC" );
319    }
320
321    // ¸¡º÷ÍÑSQL
322    function getList() {
323        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer ";
324        return $this->getSql(0);   
325    }
326
327    function getListMailMagazine() {
328        $this->select = "
329            SELECT
330                dtb_customer.customer_id,
331                dtb_customer.name01,
332                dtb_customer.name02,
333                dtb_customer.kana01,
334                dtb_customer.kana02,
335                dtb_customer.sex,
336                dtb_customer.email,
337                dtb_customer.tel01,
338                dtb_customer.tel02,
339                dtb_customer.tel03,
340                dtb_customer.pref,
341                dtb_customer.mailmaga_flg
342            FROM
343                dtb_customer";
344        return $this->getSql(0);   
345    }
346   
347    //¡¡¸¡º÷Áí¿ô¥«¥¦¥ó¥ÈÍÑSQL
348    function getListCount() {
349        $this->select = "SELECT COUNT(customer_id) FROM dtb_customer ";
350        return $this->getSql(1);
351    }
352
353    //¡¡CSV¥À¥¦¥ó¥í¡¼¥ÉÍÑSQL
354    function getListCSV($arrColumnCSV) {
355        $this->arrColumnCSV = $arrColumnCSV;
356        $i = 0;
357        foreach ($this->arrColumnCSV as $val) {
358            if ($i != 0) $state .= ", ";
359            $state .= $val["sql"];
360            $i ++;
361        }
362
363        $this->select = "SELECT " .$state. " FROM dtb_customer ";
364        return $this->getSql(2);   
365    }
366   
367    function getWhere() {
368        return array($this->where, $this->arrVal);
369    }
370}
371?>
Note: See TracBrowser for help on using the repository browser.