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

Revision 2702, 10.0 KB checked in by kakinaka, 20 years ago (diff)

blank

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