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