1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | |
---|
24 | /* [名称] SC_CustomerList |
---|
25 | * [概要] 会員検索用クラス |
---|
26 | */ |
---|
27 | class SC_CustomerList extends SC_SelectSql { |
---|
28 | |
---|
29 | var $arrColumnCSV; |
---|
30 | |
---|
31 | function SC_CustomerList($array, $mode = '') { |
---|
32 | parent::SC_SelectSql($array); |
---|
33 | |
---|
34 | $masterData = new SC_DB_MasterData_Ex(); |
---|
35 | |
---|
36 | $objDb = new SC_Helper_DB_Ex(); |
---|
37 | $dbFactory = SC_DB_DBFactory::getInstance(); |
---|
38 | |
---|
39 | if($mode == "") { |
---|
40 | // 会員本登録会員で削除していない会員 |
---|
41 | $this->setWhere("status = 2 AND del_flg = 0 "); |
---|
42 | // 登録日を示すカラム |
---|
43 | $regdate_col = 'dtb_customer.update_date'; |
---|
44 | } |
---|
45 | |
---|
46 | if($mode == "customer") { |
---|
47 | $this->setWhere( " del_flg = 0 "); |
---|
48 | // 登録日を示すカラム |
---|
49 | $regdate_col = 'dtb_customer.update_date'; |
---|
50 | } |
---|
51 | |
---|
52 | // 顧客ID |
---|
53 | if (!isset($this->arrSql['customer_id'])) $this->arrSql['customer_id'] = ""; |
---|
54 | if ( strlen($this->arrSql['customer_id']) > 0 ) { |
---|
55 | $this->setWhere( "customer_id = ?" ); |
---|
56 | $this->arrVal[] = $this->arrSql['customer_id']; |
---|
57 | } |
---|
58 | |
---|
59 | // 名前 |
---|
60 | if (!isset($this->arrSql['name'])) $this->arrSql['name'] = ""; |
---|
61 | if ( strlen($this->arrSql['name']) > 0 ) { |
---|
62 | $this->setWhere("(" . $dbFactory->concatColumn(array("name01", "name02")) . " LIKE ?)" ); |
---|
63 | $searchName = $this->addSearchStr($this->arrSql['name']); |
---|
64 | $this->arrVal[] = mb_ereg_replace("[ ]+","",$searchName); |
---|
65 | } |
---|
66 | |
---|
67 | // 名前(カナ) |
---|
68 | if (!isset($this->arrSql['kana'])) $this->arrSql['kana'] = ""; |
---|
69 | if ( strlen($this->arrSql['kana']) > 0 ) { |
---|
70 | $this->setWhere("(" . $dbFactory->concatColumn(array("kana01", "kana02")) . " LIKE ?)" ); |
---|
71 | $searchKana = $this->addSearchStr($this->arrSql['kana']); |
---|
72 | $this->arrVal[] = mb_ereg_replace("[ ]+","",$searchKana); |
---|
73 | } |
---|
74 | |
---|
75 | // 都道府県 |
---|
76 | if (!isset($this->arrSql['pref'])) $this->arrSql['pref'] = ""; |
---|
77 | if ( strlen($this->arrSql['pref']) > 0 ) { |
---|
78 | $this->setWhere( "pref = ?" ); |
---|
79 | $this->arrVal[] = $this->arrSql['pref']; |
---|
80 | } |
---|
81 | |
---|
82 | // 電話番号 |
---|
83 | if (!isset($this->arrSql['tel'])) $this->arrSql['tel'] = ""; |
---|
84 | if ( is_numeric( $this->arrSql['tel'] ) ) { |
---|
85 | $this->setWhere("(" . $dbFactory->concatColumn(array("tel01", "tel02", "tel03")) . " LIKE ?)" ); |
---|
86 | $searchTel = $this->addSearchStr($this->arrSql['tel']); |
---|
87 | $this->arrVal[] = ereg_replace("-", "", $searchTel); |
---|
88 | } |
---|
89 | |
---|
90 | // 性別 |
---|
91 | if (!isset($this->arrSql['sex'])) $this->arrSql['sex'] = ""; |
---|
92 | if ( is_array( $this->arrSql['sex'] ) ){ |
---|
93 | $arrSexVal = $this->setItemTerm( $this->arrSql['sex'] ,"sex" ); |
---|
94 | foreach ($arrSexVal as $data) { |
---|
95 | $this->arrVal[] = $data; |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | // 職業 |
---|
100 | if (!isset($this->arrSql['job'])) $this->arrSql['job'] = ""; |
---|
101 | if ( is_array( $this->arrSql['job'] ) ){ |
---|
102 | if ( in_array("不明", $this->arrSql['job'] ) ) { |
---|
103 | $arrJobVal = $this->setItemTermWithNull( $this->arrSql['job'] ,"job" ); |
---|
104 | } else { |
---|
105 | $arrJobVal = $this->setItemTerm( $this->arrSql['job'] ,"job" ); |
---|
106 | } |
---|
107 | if (is_array($arrJobVal)) { |
---|
108 | foreach ($arrJobVal as $data) { |
---|
109 | $this->arrVal[] = $data; |
---|
110 | } |
---|
111 | } |
---|
112 | } |
---|
113 | |
---|
114 | // E-MAIL |
---|
115 | if (!isset($this->arrSql['email'])) $this->arrSql['email'] = ""; |
---|
116 | if (strlen($this->arrSql['email']) > 0) { |
---|
117 | //カンマ区切りで複数の条件指定可能に |
---|
118 | $this->arrSql['email'] = explode(",", $this->arrSql['email']); |
---|
119 | $sql_where = ""; |
---|
120 | foreach($this->arrSql['email'] as $val) { |
---|
121 | $val = trim($val); |
---|
122 | //検索条件を含まない |
---|
123 | if($this->arrSql['not_emailinc'] == '1') { |
---|
124 | if($sql_where == "") { |
---|
125 | $sql_where .= "dtb_customer.email NOT ILIKE ? "; |
---|
126 | } else { |
---|
127 | $sql_where .= "AND dtb_customer.email NOT ILIKE ? "; |
---|
128 | } |
---|
129 | } else { |
---|
130 | if($sql_where == "") { |
---|
131 | $sql_where .= "dtb_customer.email ILIKE ? "; |
---|
132 | } else { |
---|
133 | $sql_where .= "OR dtb_customer.email ILIKE ? "; |
---|
134 | } |
---|
135 | } |
---|
136 | $searchEmail = $this->addSearchStr($val); |
---|
137 | $this->arrVal[] = $searchEmail; |
---|
138 | } |
---|
139 | $this->setWhere($sql_where); |
---|
140 | } |
---|
141 | |
---|
142 | // E-MAIL(mobile) |
---|
143 | if (!isset($this->arrSql['email_mobile'])) $this->arrSql['email_mobile'] = ""; |
---|
144 | |
---|
145 | if (strlen($this->arrSql['email_mobile']) > 0) { |
---|
146 | //カンマ区切りで複数の条件指定可能に |
---|
147 | $this->arrSql['email_mobile'] = explode(",", $this->arrSql['email_mobile']); |
---|
148 | $sql_where = ""; |
---|
149 | foreach($this->arrSql['email_mobile'] as $val) { |
---|
150 | $val = trim($val); |
---|
151 | //検索条件を含まない |
---|
152 | if($this->arrSql['not_email_mobileinc'] == '1') { |
---|
153 | if($sql_where == "") { |
---|
154 | $sql_where .= "dtb_customer.email_mobile NOT ILIKE ? "; |
---|
155 | } else { |
---|
156 | $sql_where .= "AND dtb_customer.email_mobile NOT ILIKE ? "; |
---|
157 | } |
---|
158 | } else { |
---|
159 | if($sql_where == "") { |
---|
160 | $sql_where .= "dtb_customer.email_mobile ILIKE ? "; |
---|
161 | } else { |
---|
162 | $sql_where .= "OR dtb_customer.email_mobile ILIKE ? "; |
---|
163 | } |
---|
164 | } |
---|
165 | $searchemail_mobile = $this->addSearchStr($val); |
---|
166 | $this->arrVal[] = $searchemail_mobile; |
---|
167 | } |
---|
168 | $this->setWhere($sql_where); |
---|
169 | } |
---|
170 | |
---|
171 | // メールマガジンの場合 |
---|
172 | if($mode == "customer") { |
---|
173 | // メルマガ受け取りの選択項目がフォームに存在する場合 |
---|
174 | if ( isset($this->arrSql['htmlmail'])){ |
---|
175 | if (SC_Utils_Ex::sfIsInt($this->arrSql['htmlmail'])){ |
---|
176 | $this->setWhere("mailmaga_flg = ?"); |
---|
177 | $this->arrVal[] = $this->arrSql['htmlmail']; |
---|
178 | } else { |
---|
179 | // メルマガ購読拒否は省く |
---|
180 | $this->setWhere("mailmaga_flg <> 3"); |
---|
181 | } |
---|
182 | } |
---|
183 | } |
---|
184 | |
---|
185 | // 配信メールアドレス種別 |
---|
186 | if ( $mode == 'customer' ){ |
---|
187 | if (isset($this->arrSql['mail_type'])){ |
---|
188 | $sqlEmailMobileIsEmpty = "(dtb_customer.email_mobile IS NULL OR dtb_customer.email_mobile = '')"; |
---|
189 | switch ($this->arrSql['mail_type']) { |
---|
190 | // PCメールアドレス |
---|
191 | case 1: |
---|
192 | $this->setWhere("(dtb_customer.email <> dtb_customer.email_mobile OR $sqlEmailMobileIsEmpty)"); |
---|
193 | break; |
---|
194 | // 携帯メールアドレス |
---|
195 | case 2: |
---|
196 | $this->setWhere("NOT $sqlEmailMobileIsEmpty"); |
---|
197 | break; |
---|
198 | // PCメールアドレス (携帯メールアドレスを登録している顧客は除外) |
---|
199 | case 3: |
---|
200 | $this->setWhere($sqlEmailMobileIsEmpty); |
---|
201 | break; |
---|
202 | // 携帯メールアドレス (PCメールアドレスを登録している顧客は除外) |
---|
203 | case 4: |
---|
204 | $this->setWhere('dtb_customer.email = dtb_customer.email_mobile'); |
---|
205 | break; |
---|
206 | } |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | // 購入金額指定 |
---|
211 | if (!isset($this->arrSql['buy_total_from'])) $this->arrSql['buy_total_from'] = ""; |
---|
212 | if (!isset($this->arrSql['buy_total_to'])) $this->arrSql['buy_total_to'] = ""; |
---|
213 | if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) { |
---|
214 | $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total"); |
---|
215 | foreach ($arrBuyTotal as $data1) { |
---|
216 | $this->arrVal[] = $data1; |
---|
217 | } |
---|
218 | } |
---|
219 | |
---|
220 | // 購入回数指定 |
---|
221 | if (!isset($this->arrSql['buy_times_from'])) $this->arrSql['buy_times_from'] = ""; |
---|
222 | if (!isset($this->arrSql['buy_times_to'])) $this->arrSql['buy_times_to'] = ""; |
---|
223 | if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) { |
---|
224 | $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times"); |
---|
225 | foreach ($arrBuyTimes as $data2) { |
---|
226 | $this->arrVal[] = $data2; |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | // 誕生日期間指定 |
---|
231 | if (!isset($this->arrSql['b_start_year'])) $this->arrSql['b_start_year'] = ""; |
---|
232 | if (!isset($this->arrSql['b_start_month'])) $this->arrSql['b_start_month'] = ""; |
---|
233 | if (!isset($this->arrSql['b_start_day'])) $this->arrSql['b_start_day'] = ""; |
---|
234 | if (!isset($this->arrSql['b_end_year'])) $this->arrSql['b_end_year'] = ""; |
---|
235 | if (!isset($this->arrSql['b_end_month'])) $this->arrSql['b_end_month'] = ""; |
---|
236 | if (!isset($this->arrSql['b_end_day'])) $this->arrSql['b_end_day'] = ""; |
---|
237 | if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) || |
---|
238 | strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) { |
---|
239 | |
---|
240 | $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day'] |
---|
241 | , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth"); |
---|
242 | if (is_array($arrBirth)) { |
---|
243 | foreach ($arrBirth as $data3) { |
---|
244 | $this->arrVal[] = $data3; |
---|
245 | } |
---|
246 | } |
---|
247 | } |
---|
248 | |
---|
249 | // 誕生月の検索 |
---|
250 | if (!isset($this->arrSql['birth_month'])) $this->arrSql['birth_month'] = ""; |
---|
251 | if (is_numeric($this->arrSql["birth_month"])) { |
---|
252 | $this->setWhere(" EXTRACT(month from birth) = ?"); |
---|
253 | $this->arrVal[] = $this->arrSql["birth_month"]; |
---|
254 | } |
---|
255 | |
---|
256 | // 登録期間指定 |
---|
257 | if (!isset($this->arrSql['start_year'])) $this->arrSql['start_year'] = ""; |
---|
258 | if (!isset($this->arrSql['start_month'])) $this->arrSql['start_month'] = ""; |
---|
259 | if (!isset($this->arrSql['start_day'])) $this->arrSql['start_day'] = ""; |
---|
260 | if (!isset($this->arrSql['end_year'])) $this->arrSql['end_year'] = ""; |
---|
261 | if (!isset($this->arrSql['end_month'])) $this->arrSql['end_month'] = ""; |
---|
262 | if (!isset($this->arrSql['end_day'])) $this->arrSql['end_day'] = ""; |
---|
263 | if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) || |
---|
264 | (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) { |
---|
265 | |
---|
266 | $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day'] |
---|
267 | , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col); |
---|
268 | if (is_array($arrRegistTime)) { |
---|
269 | foreach ($arrRegistTime as $data4) { |
---|
270 | $this->arrVal[] = $data4; |
---|
271 | } |
---|
272 | } |
---|
273 | } |
---|
274 | |
---|
275 | // 最終購入日指定 |
---|
276 | if (!isset($this->arrSql['buy_start_year'])) $this->arrSql['buy_start_year'] = ""; |
---|
277 | if (!isset($this->arrSql['buy_start_month'])) $this->arrSql['buy_start_month'] = ""; |
---|
278 | if (!isset($this->arrSql['buy_start_day'])) $this->arrSql['buy_start_day'] = ""; |
---|
279 | if (!isset($this->arrSql['buy_end_year'])) $this->arrSql['buy_end_year'] = ""; |
---|
280 | if (!isset($this->arrSql['buy_end_month'])) $this->arrSql['buy_end_month'] = ""; |
---|
281 | if (!isset($this->arrSql['buy_end_day'])) $this->arrSql['buy_end_day'] = ""; |
---|
282 | |
---|
283 | if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) || |
---|
284 | (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) { |
---|
285 | $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day'] |
---|
286 | , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date"); |
---|
287 | if (is_array($arrRegistTime)) { |
---|
288 | foreach ($arrRegistTime as $data4) { |
---|
289 | $this->arrVal[] = $data4; |
---|
290 | } |
---|
291 | } |
---|
292 | } |
---|
293 | |
---|
294 | // 購入商品コード |
---|
295 | if (!isset($this->arrSql['buy_product_code'])) $this->arrSql['buy_product_code'] = ""; |
---|
296 | if ( strlen($this->arrSql['buy_product_code']) > 0 ) { |
---|
297 | $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 ? ))"); |
---|
298 | $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']); |
---|
299 | $this->arrVal[] = $search_buyproduct_code; |
---|
300 | } |
---|
301 | |
---|
302 | // 購入商品名称 |
---|
303 | if (!isset($this->arrSql['buy_product_name'])) $this->arrSql['buy_product_name'] = ""; |
---|
304 | if ( strlen($this->arrSql['buy_product_name']) > 0 ) { |
---|
305 | $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 ? ))"); |
---|
306 | $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']); |
---|
307 | $this->arrVal[] = $search_buyproduct_name; |
---|
308 | } |
---|
309 | |
---|
310 | // カテゴリーを選択している場合のみ絞込検索を行う |
---|
311 | if (!isset($this->arrSql['category_id'])) $this->arrSql['category_id'] = ""; |
---|
312 | if ( strlen($this->arrSql['category_id']) > 0){ |
---|
313 | // カテゴリーで絞込検索を行うSQL文生成 |
---|
314 | list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['category_id']); |
---|
315 | |
---|
316 | // カテゴリーで絞込みが可能の場合 |
---|
317 | if($tmp_where != "") { |
---|
318 | $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_product_categories WHERE ".$tmp_where." ))) "); |
---|
319 | $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval); |
---|
320 | } |
---|
321 | } |
---|
322 | // 携帯電話番号 |
---|
323 | if (!isset($this->arrSql['cell'])) $this->arrSql['cell'] = ""; |
---|
324 | if ( is_numeric( $this->arrSql['cell'] ) ) { |
---|
325 | $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" ); |
---|
326 | $searchTel = $this->addSearchStr($this->arrSql['cell']); |
---|
327 | $this->arrVal[] = ereg_replace("-", "", $searchTel); |
---|
328 | } |
---|
329 | |
---|
330 | // 会員状態 |
---|
331 | if (!isset($this->arrSql['status'])) $this->arrSql['status'] = ""; |
---|
332 | if ( is_array( $this->arrSql['status'] ) ){ |
---|
333 | $arrStatusVal = $this->setItemTerm( $this->arrSql['status'] ,"status" ); |
---|
334 | foreach ($arrStatusVal as $data) { |
---|
335 | $this->arrVal[] = $data; |
---|
336 | } |
---|
337 | } |
---|
338 | |
---|
339 | $this->setOrder( "customer_id DESC" ); |
---|
340 | } |
---|
341 | |
---|
342 | // 検索用SQL |
---|
343 | function getList() { |
---|
344 | $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status,update_date,mailmaga_flg FROM dtb_customer "; |
---|
345 | return $this->getSql(0); |
---|
346 | } |
---|
347 | |
---|
348 | function getListMailMagazine($is_mobile = false) { |
---|
349 | |
---|
350 | $colomn = $this->getMailMagazineColumn($is_mobile); |
---|
351 | $this->select = " |
---|
352 | SELECT |
---|
353 | $colomn |
---|
354 | FROM |
---|
355 | dtb_customer"; |
---|
356 | return $this->getSql(0); |
---|
357 | } |
---|
358 | |
---|
359 | // 検索総数カウント用SQL |
---|
360 | function getListCount() { |
---|
361 | $this->select = "SELECT COUNT(customer_id) FROM dtb_customer "; |
---|
362 | return $this->getSql(1); |
---|
363 | } |
---|
364 | |
---|
365 | // CSVダウンロード用SQL |
---|
366 | function getListCSV($arrColumnCSV) { |
---|
367 | $this->arrColumnCSV = $arrColumnCSV; |
---|
368 | $i = 0; |
---|
369 | foreach ($this->arrColumnCSV as $val) { |
---|
370 | if ($i != 0) $state .= ", "; |
---|
371 | $state .= $val["sql"]; |
---|
372 | $i ++; |
---|
373 | } |
---|
374 | |
---|
375 | $this->select = "SELECT " .$state. " FROM dtb_customer "; |
---|
376 | return $this->getSql(2); |
---|
377 | } |
---|
378 | |
---|
379 | function getWhere() { |
---|
380 | return array($this->where, $this->arrVal); |
---|
381 | } |
---|
382 | } |
---|
383 | ?> |
---|