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

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