source: temp/trunk/data/class/SC_CustomerList.php @ 1328

Revision 1328, 9.7 KB checked in by naka, 20 years ago (diff)

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1<?php
2
3/*  [̾¾Î] SC_CustomerList
4 *  [³µÍ×] ²ñ°÷¸¡º÷ÍÑ¥¯¥é¥¹
5 */
6class SC_CustomerList extends SC_SelectSql {
7
8    var $arrColumnCSV;
9   
10    function SC_CustomerList($array, $mode = '') {
11        parent::SC_SelectSql($array);
12       
13        if($mode == "") {
14            // ²ñ°÷ËÜÅÐÏ¿²ñ°÷¤Çºï½ü¤·¤Æ¤¤¤Ê¤¤²ñ°÷
15            $this->setWhere("status = 2 AND delete = 0 ");     
16            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
17            $regdate_col = 'dtb_customer.update_date';
18        }
19        if($mode == "customer") {
20            // ´ÉÍý¼Ô¥Ú¡¼¥¸¸ÜµÒ¸¡º÷¤Î¾ì¹ç²¾ÅÐÏ¿²ñ°÷¤â¸¡º÷
21            $this->setWhere( "(status = 1 OR status = 2) AND delete = 0 ");     
22            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
23            $regdate_col = 'dtb_customer.update_date';
24        }
25       
26        // ¥á¡¼¥ë¥Þ¥¬¥¸¥ó¤Î¾ì¹ç     
27        if($mode == "magazine") {
28            $this->setWhere("(delete = 0 OR delete IS NULL)");
29           
30            if(is_array($this->arrSql['customer'])) {
31                $tmp_where = "";
32                foreach($this->arrSql['customer'] as $val) {
33                    if($tmp_where != "") {
34                        $tmp_where.= " OR ";
35                    }                   
36                    switch($val) {
37                    // ²ñ°÷
38                    case '1':
39                        $tmp_where.= "status = 2";
40                        break;
41                    // ¥á¥ë¥Þ¥¬ÅÐÏ¿
42                    case '2':
43                        // dtb_customer_mail¤Ë¤Î¤ßÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¥ì¥³¡¼¥É¤òÃê½Ð
44                        $tmp_where.= "customer_id IS NULL ";
45                        break;
46                    // CSVÅÐÏ¿
47                    case '3':
48                        // dtb_customer_mail¤Ë¤Î¤ßÅÐÏ¿¤µ¤ì¤Æ¤¤¤ë¥ì¥³¡¼¥É¤òÃê½Ð
49                        $tmp_where.= "customer_id IS NULL";
50                        break;
51                    default:
52                        $tmp_where = "";
53                        break;
54                    }
55                }
56                if($tmp_where != "") {
57                    $tmp_where = "(" . $tmp_where . ")";
58                }
59                $this->setWhere($tmp_where);
60            }
61            // ÅÐÏ¿Æü¤ò¼¨¤¹¥«¥é¥à
62            $regdate_col = 'dtb_customer_mail.create_date';
63        }
64               
65        // ¸ÜµÒID
66        if ( strlen($this->arrSql['search_customer_id']) > 0 ) {
67            $this->setWhere( "customer_id =  ?" );
68            $this->arrVal[] = $this->arrSql['search_customer_id'];
69        }
70       
71        // ̾Á°
72        if ( strlen($this->arrSql['search_name']) > 0 ) {
73            $this->setWhere("(name01 || name02 LIKE ?)" );
74            $searchName = $this->addSearchStr($this->arrSql['search_name']);
75            $this->arrVal[] = ereg_replace("[ ¡¡]+","",$searchName);
76        }
77
78        //¡¡Ì¾Á°¡Ê¥«¥Ê¡Ë
79        if ( strlen($this->arrSql['search_kana']) > 0 ) {
80            $this->setWhere("(kana01 || kana02 LIKE ?)");
81            $searchKana = $this->addSearchStr($this->arrSql['search_kana']);
82            $this->arrVal[] = ereg_replace("[ ¡¡]+","",$searchKana);
83        }
84       
85        //¡¡ÅÔÆ»Éܸ©
86        if ( strlen($this->arrSql['search_pref']) > 0 ) {
87            $this->setWhere( "pref = ?" );
88            $this->arrVal[] = $this->arrSql['search_pref'];
89        }
90
91        //¡¡ÅÅÏÃÈÖ¹æ
92        if ( is_numeric( $this->arrSql['search_tel'] ) ) {
93            $this->setWhere( "(tel01 || tel02 || tel03 LIKE ?)" );
94            $searchTel = $this->addSearchStr($this->arrSql['search_tel']);
95            $this->arrVal[] = ereg_replace("-", "", $searchTel);
96        }
97       
98        //¡¡À­ÊÌ
99        if ( is_array( $this->arrSql['search_sex'] ) ){
100            $arrSexVal = $this->setItemTerm( $this->arrSql['search_sex'] ,"sex" );
101            foreach ($arrSexVal as $data) {
102                $this->arrVal[] = $data;
103            }
104        }
105
106        //¡¡¿¦¶È
107        if ( is_array( $this->arrSql['search_job'] ) ){
108            if ( in_array("ÉÔÌÀ", $this->arrSql['search_job'] ) ) {
109                $arrJobVal = $this->setItemTermWithNull( $this->arrSql['search_job'] ,"job" );
110            } else {
111                $arrJobVal = $this->setItemTerm( $this->arrSql['search_job'] ,"job" );
112            }
113            if (is_array($arrJobVal)) {
114                foreach ($arrJobVal as $data) {
115                    $this->arrVal[] = $data;
116                }
117            }
118        }
119
120        //¡¡E-MAIL
121        if ( strlen($this->arrSql['search_email']) > 0 ) {
122            $this->setWhere( "email ILIKE ? " );
123            $searchEmail = $this->addSearchStr($this->arrSql['search_email']);
124            $this->arrVal[] = $searchEmail;
125        }
126
127        //¡¡HTML-mail
128        if ( $mode == 'magazine' ){
129            if ( strlen($this->arrSql['search_htmlmail']) > 0 ) {
130                $this->setWhere( " mail_flag = ? ");
131                $this->arrVal[] = $this->arrSql['search_htmlmail'];
132            } else {
133                $this->setWhere( " (mail_flag = 1 or mail_flag = 2) ");
134            }
135        }
136       
137        // ¹ØÆþ¶â³Û»ØÄê
138        if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) {
139            $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total");
140            foreach ($arrBuyTotal as $data1) {
141                $this->arrVal[] = $data1;
142            }
143        }
144
145        // ¹ØÆþ²ó¿ô»ØÄê
146        if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) {
147            $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times");
148            foreach ($arrBuyTimes as $data2) {
149                $this->arrVal[] = $data2;
150            }
151        }
152       
153        // ÃÂÀ¸Æü´ü´Ö»ØÄê
154        if ( (strlen($this->arrSql['search_b_start_year']) > 0 && strlen($this->arrSql['search_b_start_month']) > 0 && strlen($this->arrSql['search_b_start_day']) > 0) ||
155              strlen($this->arrSql['search_b_end_year']) > 0 && strlen($this->arrSql['search_b_end_month']) > 0 && strlen($this->arrSql['search_b_end_day']) > 0) {
156
157            $arrBirth = $this->selectTermRange($this->arrSql['search_b_start_year'], $this->arrSql['search_b_start_month'], $this->arrSql['search_b_start_day']
158                      , $this->arrSql['search_b_end_year'], $this->arrSql['search_b_end_month'], $this->arrSql['search_b_end_day'], "birth");
159            if (is_array($arrBirth)) {
160                foreach ($arrBirth as $data3) {
161                    $this->arrVal[] = $data3;
162                }
163            }
164        }
165
166        // ÃÂÀ¸·î¤Î¸¡º÷
167        if (is_numeric($this->arrSql["birth_month"])) {
168            $this->setWhere(" EXTRACT(month from birth) = ?"); 
169            $this->arrVal[] = $this->arrSql["birth_month"];
170        }
171
172        // ÅÐÏ¿´ü´Ö»ØÄê
173        if ( (strlen($this->arrSql['search_start_year']) > 0 && strlen($this->arrSql['search_start_month']) > 0 && strlen($this->arrSql['search_start_day']) > 0 ) ||
174                (strlen($this->arrSql['search_end_year']) > 0 && strlen($this->arrSql['search_end_month']) >0 && strlen($this->arrSql['search_end_day']) > 0) ) {
175
176            $arrRegistTime = $this->selectTermRange($this->arrSql['search_start_year'], $this->arrSql['search_start_month'], $this->arrSql['search_start_day']
177                            , $this->arrSql['search_end_year'], $this->arrSql['search_end_month'], $this->arrSql['search_end_day'], $regdate_col);
178            if (is_array($arrRegistTime)) {
179                foreach ($arrRegistTime as $data4) {
180                    $this->arrVal[] = $data4;
181                }
182            }
183        }
184
185        // ºÇ½ª¹ØÆþÆü»ØÄê
186        if ( (strlen($this->arrSql['search_buy_start_year']) > 0 && strlen($this->arrSql['search_buy_start_month']) > 0 && strlen($this->arrSql['search_buy_start_day']) > 0 ) ||
187                (strlen($this->arrSql['search_buy_end_year']) > 0 && strlen($this->arrSql['search_buy_end_month']) >0 && strlen($this->arrSql['search_buy_end_day']) > 0) ) {
188            $arrRegistTime = $this->selectTermRange($this->arrSql['search_buy_start_year'], $this->arrSql['search_buy_start_month'], $this->arrSql['search_buy_start_day']
189                            , $this->arrSql['search_buy_end_year'], $this->arrSql['search_buy_end_month'], $this->arrSql['search_buy_end_day'], "last_buy_date");
190            if (is_array($arrRegistTime)) {
191                foreach ($arrRegistTime as $data4) {
192                    $this->arrVal[] = $data4;
193                }
194            }
195        }
196       
197        //¹ØÆþ¾¦ÉÊ¥³¡¼¥É
198        if ( strlen($this->arrSql['search_buy_product_code']) > 0 ) {
199            $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 ? ))");
200            $search_buyproduct_code = $this->addSearchStr($this->arrSql['search_buy_product_code']);
201            $this->arrVal[] = $search_buyproduct_code;
202        }
203
204        //¹ØÆþ¾¦ÉÊ̾¾Î
205        if ( strlen($this->arrSql['search_buy_product_name']) > 0 ) {
206            $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 ? ))");
207            $search_buyproduct_name = $this->addSearchStr($this->arrSql['search_buy_product_name']);
208            $this->arrVal[] = $search_buyproduct_name;
209        }
210       
211        //¥«¥Æ¥´¥ê¡¼¤òÁªÂò¤·¤Æ¤¤¤ë¾ì¹ç¤Î¤ß¹Ê¹þ¸¡º÷¤ò¹Ô¤¦
212        if ( strlen($this->arrSql['search_category_id']) != ""){
213            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¸¡º÷¤ò¹Ô¤¦SQLʸÀ¸À®
214            list($tmp_where, $tmp_arrval) = sfGetCatWhere(sfManualEscape($this->arrSql['search_category_id']));
215
216            //¥«¥Æ¥´¥ê¡¼¤Ç¹Ê¹þ¤ß¤¬²Äǽ¤Î¾ì¹ç
217            if($tmp_where != "") {
218                $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." ))) ");
219                $this->arrVal = array_merge($this->arrVal, $tmp_arrval);
220            }
221        }
222
223        $this->setOrder( "customer_id DESC" );
224    }
225
226    // ¸¡º÷ÍÑSQL
227    function getList() {
228        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer ";
229        return $this->getSql(0);   
230    }
231
232    function getListMailMagazine() {
233        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref, mail_flag FROM dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)";
234        return $this->getSql(0);   
235    }
236   
237    function getListMailMagazineCount() {
238        $this->select = "SELECT COUNT(*) FROM dtb_customer_mail LEFT OUTER JOIN dtb_customer USING(email)";
239        return $this->getSql(0);   
240    }
241    //¹ØÆþ¾¦ÉÊ¥³¡¼¥É¸¡º÷ÍÑSQL
242    function getBuyList(){
243        $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
244                        FROM (dtb_customer LEFT OUTER JOIN dtb_customer_mail USING (email)) AS A LEFT OUTER JOIN dtb_order AS B ON
245                        A.email=B.order_email LEFT OUTER JOIN dtb_order_detail AS C ON B.order_id = C.order_id";
246    }
247
248    //¡¡¸¡º÷Áí¿ô¥«¥¦¥ó¥ÈÍÑSQL
249    function getListCount() {
250        $this->select = "SELECT COUNT (customer_id) FROM dtb_customer ";   
251        return $this->getSql(1);
252    }
253
254    //¡¡CSV¥À¥¦¥ó¥í¡¼¥ÉÍÑSQL
255    function getListCSV($arrColumnCSV) {
256        $this->arrColumnCSV = $arrColumnCSV;
257        $i = 0;
258        foreach ($this->arrColumnCSV as $val) {
259            if ($i != 0) $state .= ", ";
260            $state .= $val["sql"];
261            $i ++;
262        }
263
264        $this->select = "SELECT " .$state. " FROM dtb_customer ";
265        return $this->getSql(2);   
266    }
267   
268    function getWhere() {
269        return array($this->where, $this->arrVal);
270    }
271   
272}
273
274?>
Note: See TracBrowser for help on using the repository browser.