source: branches/beta/data/class/SC_CustomerList.php @ 15362

Revision 15362, 12.6 KB checked in by adachi, 17 years ago (diff)

conf.phpが2重にrequireしていたのを修正

RevLine 
[8]1<?php
2/*
[17]3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
[8]4 *
5 * http://www.lockon.co.jp/
6 */
[15362]7
[8]8/*  [̾¾Î] SC_CustomerList
9 *  [³µÍ×] ²ñ°÷¸¡º÷ÍÑ¥¯¥é¥¹
10 */
11class SC_CustomerList extends SC_SelectSql {
12
13    var $arrColumnCSV;
[15362]14
[8]15    function SC_CustomerList($array, $mode = '') {
16        parent::SC_SelectSql($array);
[15362]17
[8]18        if($mode == "") {
19            // ²ñ°÷ËÜÅÐÏ¿²ñ°÷¤Çºï½ü¤·¤Æ¤¤¤Ê¤¤²ñ°÷
[15362]20            $this->setWhere("status = 2 AND del_flg = 0 ");
[8]21            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
22            $regdate_col = 'dtb_customer.update_date';
23        }
[15362]24
[8]25        if($mode == "customer") {
26            // ´ÉÍý¼Ô¥Ú¡¼¥¸¸ÜµÒ¸¡º÷¤Î¾ì¹ç²¾ÅÐÏ¿²ñ°÷¤â¸¡º÷
[15362]27            $this->setWhere( "(status = 1 OR status = 2) AND del_flg = 0 ");
[8]28            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
29            $regdate_col = 'dtb_customer.update_date';
30        }
[15362]31
32        // ¥á¡¼¥ë¥Þ¥¬¥¸¥ó¤Î¾ì¹ç
[8]33        if($mode == "magazine") {
34            $this->setWhere("(del_flg = 0 OR del_flg IS NULL)");
35            $this->setWhere("status = 2");
[15362]36
[8]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 ";
[15362]43                    }
[8]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            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
[11611]69            $regdate_col = 'dtb_customer.create_date';
[8]70        }
[15362]71
[8]72        // ¸ÜµÒID
73        if ( strlen($this->arrSql['customer_id']) > 0 ) {
74            $this->setWhere( "customer_id =  ?" );
75            $this->arrVal[] = $this->arrSql['customer_id'];
76        }
[15362]77
[8]78        // ̾Á°
79        if ( strlen($this->arrSql['name']) > 0 ) {
[222]80            if(DB_TYPE == "pgsql"){
81                $this->setWhere("(name01 || name02 LIKE ?)" );
82            }elseif(DB_TYPE == "mysql"){
[223]83                $this->setWhere("concat(name01,name02) LIKE ?" );
[222]84            }
85
[8]86            $searchName = $this->addSearchStr($this->arrSql['name']);
87            $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchName);
88        }
89
90        //¡¡Ì¾Á°¡Ê¥«¥Ê¡Ë
91        if ( strlen($this->arrSql['kana']) > 0 ) {
[224]92            if(DB_TYPE == "pgsql"){
93                $this->setWhere("(kana01 || kana02 LIKE ?)");
94            }elseif(DB_TYPE == "mysql"){
95                $this->setWhere("concat(kana01,kana02) LIKE ?" );
96            }
[8]97            $searchKana = $this->addSearchStr($this->arrSql['kana']);
98            $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchKana);
99        }
[15362]100
[8]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'] ) ) {
[224]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            }
[8]114            $searchTel = $this->addSearchStr($this->arrSql['tel']);
115            $this->arrVal[] = ereg_replace("-", "", $searchTel);
116        }
[15362]117
[8]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            $this->arrSql['email'] = explode(",", $this->arrSql['email']);
144            $sql_where = "";
145            foreach($this->arrSql['email'] as $val) {
146                $val = trim($val);
147                //¸¡º÷¾ò·ï¤ò´Þ¤Þ¤Ê¤¤
148                if($this->arrSql['not_emailinc'] == '1') {
[11741]149                    if($sql_where == "") {
150                        $sql_where .= "dtb_customer.email NOT ILIKE ? ";
[8]151                    } else {
[11741]152                        $sql_where .= "AND dtb_customer.email NOT ILIKE ? ";
[8]153                    }
[15362]154                } else {
[11741]155                    if($sql_where == "") {
156                        $sql_where .= "dtb_customer.email ILIKE ? ";
[8]157                    } else {
[11741]158                        $sql_where .= "OR dtb_customer.email ILIKE ? ";
[8]159                    }
160                }
161                $searchEmail = $this->addSearchStr($val);
[11741]162                $this->arrVal[] = $searchEmail;
[8]163            }
[11642]164            $this->setWhere($sql_where);
[8]165        }
[11771]166
167        //¡¡E-MAIL(mobile)
168        if (strlen($this->arrSql['email_mobile']) > 0) {
169            //¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊ£¿ô¤Î¾ò·ï»ØÄê²Äǽ¤Ë
170            $this->arrSql['email_mobile'] = explode(",", $this->arrSql['email_mobile']);
171            $sql_where = "";
172            foreach($this->arrSql['email_mobile'] as $val) {
173                $val = trim($val);
174                //¸¡º÷¾ò·ï¤ò´Þ¤Þ¤Ê¤¤
175                if($this->arrSql['not_email_mobileinc'] == '1') {
176                    if($sql_where == "") {
177                        $sql_where .= "dtb_customer.email_mobile NOT ILIKE ? ";
178                    } else {
179                        $sql_where .= "AND dtb_customer.email_mobile NOT ILIKE ? ";
180                    }
[15362]181                } else {
[11771]182                    if($sql_where == "") {
183                        $sql_where .= "dtb_customer.email_mobile ILIKE ? ";
184                    } else {
185                        $sql_where .= "OR dtb_customer.email_mobile ILIKE ? ";
186                    }
187                }
188                $searchemail_mobile = $this->addSearchStr($val);
189                $this->arrVal[] = $searchemail_mobile;
190            }
191            $this->setWhere($sql_where);
192        }
[14676]193
[15362]194/*      2007/05/28  °ìö¡¢Ää»ß¤·¤Þ¤¹¡£
[14676]195 *      //¡¡ÇÛ¿®¥á¡¼¥ë¥¢¥É¥ì¥¹¼ïÊÌ
196 *      if ( $mode == 'magazine' ){
197 *          if ( strlen($this->arrSql['mail_type']) > 0 && $this->arrSql['mail_type'] == 2) {
198 *              $this->setWhere( " dtb_customer.email_mobile <> ''  ");
199 *          }
200 *      }
201 */
202
203        if($mode == 'magazine'){
204            global $arrDomainType;
205            $sql_where = "";
206            //¥É¥á¥¤¥ó»ØÄê¡££±¤Ï£Ð£Ã¡¢£²¤Ï·ÈÂÓ
207            if ( $this->arrSql['domain'] > 0 ) {
208                foreach($arrDomainType as $val) {
209                    if($this->arrSql['domain'] == 1) {
210                        if($sql_where == "") {
211                            $sql_where .= "dtb_customer.email NOT ILIKE ? ";
212                        } else {
213                            $sql_where .= "AND dtb_customer.email NOT ILIKE ? " ;
214                        }
215                    } elseif($this->arrSql['domain'] == 2) {
216                        if($sql_where == "") {
217                            $sql_where .= "dtb_customer.email ILIKE ? ";
218                        } else {
219                            $sql_where .= "OR dtb_customer.email LIKE ? " ;
220                        }
221                        $sql_where = "(".$sql_where.")";
222                    }
223                    $searchDomain = $this->addSearchStr($val);
224                    $this->arrVal[] = $searchDomain;
225                }
226                $this->setWhere($sql_where);
227            }
228        }
229
230        //¡¡HTML-mail¡ÊÇÛ¿®Êý¼°)
231        if( $mode == 'magazine' ){
[8]232            if ( strlen($this->arrSql['htmlmail']) > 0 ) {
[11577]233                $this->setWhere( " mailmaga_flg = ? ");
[8]234                $this->arrVal[] = $this->arrSql['htmlmail'];
235            } else {
[11577]236                $this->setWhere( " (mailmaga_flg = 1 or mailmaga_flg = 2) ");
[8]237            }
238        }
[15362]239
[8]240        // ¹ØÆþ¶â³Û»ØÄê
241        if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) {
242            $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total");
243            foreach ($arrBuyTotal as $data1) {
244                $this->arrVal[] = $data1;
245            }
246        }
247
248        // ¹ØÆþ²ó¿ô»ØÄê
249        if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) {
250            $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times");
251            foreach ($arrBuyTimes as $data2) {
252                $this->arrVal[] = $data2;
253            }
254        }
[15362]255
[8]256        // ÃÂÀ¸Æü´ü´Ö»ØÄê
257        if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) ||
258              strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) {
259
260            $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day']
261                      , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth");
262            if (is_array($arrBirth)) {
263                foreach ($arrBirth as $data3) {
264                    $this->arrVal[] = $data3;
265                }
266            }
267        }
[15362]268
[8]269        // ÃÂÀ¸·î¤Î¸¡º÷
270        if (is_numeric($this->arrSql["birth_month"])) {
[15362]271            $this->setWhere(" EXTRACT(month from birth) = ?");
[8]272            $this->arrVal[] = $this->arrSql["birth_month"];
273        }
[15362]274
[8]275        // ÅÐÏ¿´ü´Ö»ØÄê
[15362]276        if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) ||
[8]277                (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) {
278
279            $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day']
280                            , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col);
281            if (is_array($arrRegistTime)) {
282                foreach ($arrRegistTime as $data4) {
283                    $this->arrVal[] = $data4;
284                }
285            }
286        }
[15362]287
[8]288        // ºÇ½ª¹ØÆþÆü»ØÄê
[15362]289        if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) ||
[8]290                (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) {
291            $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day']
292                            , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date");
293            if (is_array($arrRegistTime)) {
294                foreach ($arrRegistTime as $data4) {
295                    $this->arrVal[] = $data4;
296                }
297            }
298        }
[15362]299
[8]300        //¹ØÆþ¾¦ÉÊ¥³¡¼¥É
301        if ( strlen($this->arrSql['buy_product_code']) > 0 ) {
302            $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 ? ))");
303            $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']);
304            $this->arrVal[] = $search_buyproduct_code;
305        }
306
307        //¹ØÆþ¾¦ÉÊ̾¾Î
308        if ( strlen($this->arrSql['buy_product_name']) > 0 ) {
309            $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 ? ))");
310            $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']);
311            $this->arrVal[] = $search_buyproduct_name;
312        }
[15362]313
[8]314        //¥«¥Æ¥´¥ê¡¼¤òÁªÂò¤·¤Æ¤¤¤ë¾ì¹ç¤Î¤ß¹Ê¹þ¸¡º÷¤ò¹Ô¤¦
315        if ( strlen($this->arrSql['category_id']) != ""){
316            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¸¡º÷¤ò¹Ô¤¦SQLʸÀ¸À®
317            list($tmp_where, $tmp_arrval) = sfGetCatWhere(sfManualEscape($this->arrSql['category_id']));
318
319            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¤ß¤¬²Äǽ¤Î¾ì¹ç
320            if($tmp_where != "") {
321                $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." ))) ");
322                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
323            }
324        }
325        //¡¡·ÈÂÓÅÅÏÃÈÖ¹æ
326        if ( is_numeric( $this->arrSql['cell'] ) ) {
327            $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" );
328            $searchTel = $this->addSearchStr($this->arrSql['cell']);
329            $this->arrVal[] = ereg_replace("-", "", $searchTel);
330        }
331
332        //¡¡¥­¥ã¥ó¥Ú¡¼¥ó
333        if ( is_numeric( $this->arrSql['campaign_id'] ) ) {
334            $this->setWhere( " customer_id IN (SELECT distinct customer_id FROM dtb_campaign_order WHERE campaign_id = ?)" );
335            $this->arrVal[] = $this->arrSql['campaign_id'];
336        }
[15362]337
[8]338        $this->setOrder( "customer_id DESC" );
339    }
340
341    // ¸¡º÷ÍÑSQL
342    function getList() {
343        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer ";
[15362]344        return $this->getSql(0);
[8]345    }
346
[11747]347    function getListMailMagazine($is_mobile = false) {
[15362]348
[11755]349        $colomn = $this->getMailMagazineColumn($is_mobile);
350        $this->select = "
[15362]351            SELECT
[11755]352                $colomn
[15362]353            FROM
[11755]354                dtb_customer";
[15362]355        return $this->getSql(0);
[11755]356    }
[15362]357
[11755]358    function getMailMagazineColumn($is_mobile= false) {
[11747]359        if($is_mobile == true) {
[11748]360            $email_column = "dtb_customer.email_mobile as email";
[11747]361        } else {
[15362]362            $email_column = "dtb_customer.email";
[11747]363        }
[15362]364
[11755]365        $column ="dtb_customer.customer_id,
[8]366                dtb_customer.name01,
367                dtb_customer.name02,
368                dtb_customer.kana01,
369                dtb_customer.kana02,
370                dtb_customer.sex,
[15362]371                $email_column,
[8]372                dtb_customer.tel01,
373                dtb_customer.tel02,
374                dtb_customer.tel03,
[15362]375                dtb_customer.pref,
[11755]376                dtb_customer.mailmaga_flg";
[15362]377
[11755]378        return $column;
[8]379    }
[15362]380
[8]381    //¡¡¸¡º÷Áí¿ô¥«¥¦¥ó¥ÈÍÑSQL
382    function getListCount() {
[15362]383        $this->select = "SELECT COUNT(customer_id) FROM dtb_customer ";
[8]384        return $this->getSql(1);
385    }
386
387    //¡¡CSV¥À¥¦¥ó¥í¡¼¥ÉÍÑSQL
388    function getListCSV($arrColumnCSV) {
389        $this->arrColumnCSV = $arrColumnCSV;
390        $i = 0;
391        foreach ($this->arrColumnCSV as $val) {
392            if ($i != 0) $state .= ", ";
393            $state .= $val["sql"];
394            $i ++;
395        }
396
397        $this->select = "SELECT " .$state. " FROM dtb_customer ";
[15362]398        return $this->getSql(2);
[8]399    }
[15362]400
[8]401    function getWhere() {
402        return array($this->where, $this->arrVal);
403    }
404}
405?>
Note: See TracBrowser for help on using the repository browser.