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

Revision 223, 10.7 KB checked in by kakinaka, 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_mail.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            $this->setWhere("(kana01 || kana02 LIKE ?)");
93            $searchKana = $this->addSearchStr($this->arrSql['kana']);
94            $this->arrVal[] = mb_ereg_replace("[ ¡¡]+","",$searchKana);
95        }
96       
97        //¡¡ÅÔÆ»Éܸ©
98        if ( strlen($this->arrSql['pref']) > 0 ) {
99            $this->setWhere( "pref = ?" );
100            $this->arrVal[] = $this->arrSql['pref'];
101        }
102
103        //¡¡ÅÅÏÃÈÖ¹æ
104        if ( is_numeric( $this->arrSql['tel'] ) ) {
105            $this->setWhere( "(tel01 || tel02 || tel03 LIKE ?)" );
106            $searchTel = $this->addSearchStr($this->arrSql['tel']);
107            $this->arrVal[] = ereg_replace("-", "", $searchTel);
108        }
109       
110        //¡¡À­ÊÌ
111        if ( is_array( $this->arrSql['sex'] ) ){
112            $arrSexVal = $this->setItemTerm( $this->arrSql['sex'] ,"sex" );
113            foreach ($arrSexVal as $data) {
114                $this->arrVal[] = $data;
115            }
116        }
117
118        //¡¡¿¦¶È
119        if ( is_array( $this->arrSql['job'] ) ){
120            if ( in_array("ÉÔÌÀ", $this->arrSql['job'] ) ) {
121                $arrJobVal = $this->setItemTermWithNull( $this->arrSql['job'] ,"job" );
122            } else {
123                $arrJobVal = $this->setItemTerm( $this->arrSql['job'] ,"job" );
124            }
125            if (is_array($arrJobVal)) {
126                foreach ($arrJobVal as $data) {
127                    $this->arrVal[] = $data;
128                }
129            }
130        }
131
132        //¡¡E-MAIL
133        if (strlen($this->arrSql['email']) > 0) {
134            //¥«¥ó¥Þ¶èÀÚ¤ê¤ÇÊ£¿ô¤Î¾ò·ï»ØÄê²Äǽ¤Ë
135            $this->arrSql['email'] = explode(",", $this->arrSql['email']);
136            $sql_where = "";
137            foreach($this->arrSql['email'] as $val) {
138                $val = trim($val);
139                //¸¡º÷¾ò·ï¤ò´Þ¤Þ¤Ê¤¤
140                if($this->arrSql['not_emailinc'] == '1') {
141                    if($sql_where == "") {
142                        $sql_where .= "dtb_customer.email NOT ILIKE ? ";
143                    } else {
144                        $sql_where .= "AND dtb_customer.email NOT ILIKE ? ";
145                    }
146                } else {               
147                    if($sql_where == "") {
148                        $sql_where .= "dtb_customer.email ILIKE ? ";
149                    } else {
150                        $sql_where .= "OR dtb_customer.email ILIKE ? ";
151                    }
152                }
153                $searchEmail = $this->addSearchStr($val);
154                $this->arrVal[] = $searchEmail;
155            }
156            $this->setWhere($sql_where);
157        }
158        //¡¡HTML-mail
159        if ( $mode == 'magazine' ){
160            if ( strlen($this->arrSql['htmlmail']) > 0 ) {
161                $this->setWhere( " mail_flag = ? ");
162                $this->arrVal[] = $this->arrSql['htmlmail'];
163            } else {
164                $this->setWhere( " (mail_flag = 1 or mail_flag = 2) ");
165            }
166        }
167       
168        // ¹ØÆþ¶â³Û»ØÄê
169        if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) {
170            $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total");
171            foreach ($arrBuyTotal as $data1) {
172                $this->arrVal[] = $data1;
173            }
174        }
175
176        // ¹ØÆþ²ó¿ô»ØÄê
177        if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) {
178            $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times");
179            foreach ($arrBuyTimes as $data2) {
180                $this->arrVal[] = $data2;
181            }
182        }
183       
184        // ÃÂÀ¸Æü´ü´Ö»ØÄê
185        if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) ||
186              strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) {
187
188            $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day']
189                      , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth");
190            if (is_array($arrBirth)) {
191                foreach ($arrBirth as $data3) {
192                    $this->arrVal[] = $data3;
193                }
194            }
195        }
196               
197        // ÃÂÀ¸·î¤Î¸¡º÷
198        if (is_numeric($this->arrSql["birth_month"])) {
199            $this->setWhere(" EXTRACT(month from birth) = ?"); 
200            $this->arrVal[] = $this->arrSql["birth_month"];
201        }
202           
203        // ÅÐÏ¿´ü´Ö»ØÄê
204        if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) ||
205                (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) {
206
207            $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day']
208                            , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col);
209            if (is_array($arrRegistTime)) {
210                foreach ($arrRegistTime as $data4) {
211                    $this->arrVal[] = $data4;
212                }
213            }
214        }
215           
216        // ºÇ½ª¹ØÆþÆü»ØÄê
217        if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) ||
218                (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) {
219            $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day']
220                            , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date");
221            if (is_array($arrRegistTime)) {
222                foreach ($arrRegistTime as $data4) {
223                    $this->arrVal[] = $data4;
224                }
225            }
226        }
227       
228        //¹ØÆþ¾¦ÉÊ¥³¡¼¥É
229        if ( strlen($this->arrSql['buy_product_code']) > 0 ) {
230            $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 ? ))");
231            $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']);
232            $this->arrVal[] = $search_buyproduct_code;
233        }
234
235        //¹ØÆþ¾¦ÉÊ̾¾Î
236        if ( strlen($this->arrSql['buy_product_name']) > 0 ) {
237            $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 ? ))");
238            $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']);
239            $this->arrVal[] = $search_buyproduct_name;
240        }
241       
242        //¥«¥Æ¥´¥ê¡¼¤òÁªÂò¤·¤Æ¤¤¤ë¾ì¹ç¤Î¤ß¹Ê¹þ¸¡º÷¤ò¹Ô¤¦
243        if ( strlen($this->arrSql['category_id']) != ""){
244            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¸¡º÷¤ò¹Ô¤¦SQLʸÀ¸À®
245            list($tmp_where, $tmp_arrval) = sfGetCatWhere(sfManualEscape($this->arrSql['category_id']));
246
247            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¤ß¤¬²Äǽ¤Î¾ì¹ç
248            if($tmp_where != "") {
249                $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." ))) ");
250                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
251            }
252        }
253        //¡¡·ÈÂÓÅÅÏÃÈÖ¹æ
254        if ( is_numeric( $this->arrSql['cell'] ) ) {
255            $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" );
256            $searchTel = $this->addSearchStr($this->arrSql['cell']);
257            $this->arrVal[] = ereg_replace("-", "", $searchTel);
258        }
259
260        //¡¡¥­¥ã¥ó¥Ú¡¼¥ó
261        if ( is_numeric( $this->arrSql['campaign_id'] ) ) {
262            $this->setWhere( " customer_id IN (SELECT distinct customer_id FROM dtb_campaign_order WHERE campaign_id = ?)" );
263            $this->arrVal[] = $this->arrSql['campaign_id'];
264        }
265               
266        $this->setOrder( "customer_id DESC" );
267    }
268
269    // ¸¡º÷ÍÑSQL
270    function getList() {
271        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer ";
272        return $this->getSql(0);   
273    }
274
275    function getListMailMagazine() {
276        $this->select = "
277            SELECT
278                dtb_customer.customer_id,
279                dtb_customer.name01,
280                dtb_customer.name02,
281                dtb_customer.kana01,
282                dtb_customer.kana02,
283                dtb_customer.sex,
284                dtb_customer.email,
285                dtb_customer.tel01,
286                dtb_customer.tel02,
287                dtb_customer.tel03,
288                dtb_customer.pref,
289                dtb_customer_mail.mail_flag
290            FROM
291                dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)";
292        return $this->getSql(0);   
293    }
294   
295    function getListMailMagazineCount() {
296        $this->select = "SELECT COUNT(*) FROM dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)";
297        return $this->getSql(0);   
298    }
299    //¹ØÆþ¾¦ÉÊ¥³¡¼¥É¸¡º÷ÍÑSQL
300    function getBuyList(){
301        $this->select = "SELECT A.customer_id, A.name01, A.name02, A.kana01, A.kana02, A.sex, A.email, A.tel01, A.tel02, A.tel03, A.pref, A.mail_flag, B.order_email, B.order_id, C.product_code
302                        FROM (dtb_customer LEFT OUTER JOIN dtb_customer_mail USING (email)) AS A LEFT OUTER JOIN dtb_order AS B ON
303                        A.email=B.order_email LEFT OUTER JOIN dtb_order_detail AS C ON B.order_id = C.order_id";
304    }
305
306    //¡¡¸¡º÷Áí¿ô¥«¥¦¥ó¥ÈÍÑSQL
307    function getListCount() {
308        $this->select = "SELECT COUNT(customer_id) FROM dtb_customer ";
309        return $this->getSql(1);
310    }
311
312    //¡¡CSV¥À¥¦¥ó¥í¡¼¥ÉÍÑSQL
313    function getListCSV($arrColumnCSV) {
314        $this->arrColumnCSV = $arrColumnCSV;
315        $i = 0;
316        foreach ($this->arrColumnCSV as $val) {
317            if ($i != 0) $state .= ", ";
318            $state .= $val["sql"];
319            $i ++;
320        }
321
322        $this->select = "SELECT " .$state. " FROM dtb_customer ";
323        return $this->getSql(2);   
324    }
325   
326    function getWhere() {
327        return array($this->where, $this->arrVal);
328    }
329}
330?>
Note: See TracBrowser for help on using the repository browser.