1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 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_Ex { |
---|
28 | |
---|
29 | var $arrColumnCSV; |
---|
30 | |
---|
31 | function __construct($array, $mode = '') { |
---|
32 | parent::__construct($array); |
---|
33 | |
---|
34 | $objDb = new SC_Helper_DB_Ex(); |
---|
35 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
36 | |
---|
37 | if ($mode == '') { |
---|
38 | // 会員本登録会員で削除していない会員 |
---|
39 | $this->setWhere('status = 2 AND del_flg = 0 '); |
---|
40 | // 登録日を示すカラム |
---|
41 | $regdate_col = 'dtb_customer.update_date'; |
---|
42 | } |
---|
43 | |
---|
44 | if ($mode == 'customer') { |
---|
45 | $this->setWhere(' del_flg = 0 '); |
---|
46 | // 登録日を示すカラム |
---|
47 | $regdate_col = 'dtb_customer.update_date'; |
---|
48 | } |
---|
49 | |
---|
50 | // 会員ID |
---|
51 | if (!isset($this->arrSql['search_customer_id'])) $this->arrSql['search_customer_id'] = ''; |
---|
52 | if (strlen($this->arrSql['search_customer_id']) > 0) { |
---|
53 | $this->setWhere('customer_id = ?'); |
---|
54 | $this->arrVal[] = $this->arrSql['search_customer_id']; |
---|
55 | } |
---|
56 | |
---|
57 | // 名前 |
---|
58 | if (!isset($this->arrSql['search_name'])) $this->arrSql['search_name'] = ''; |
---|
59 | if (strlen($this->arrSql['search_name']) > 0) { |
---|
60 | $this->setWhere('(' . $dbFactory->concatColumn(array('name01', 'name02')) . ' LIKE ?)'); |
---|
61 | $searchName = $this->addSearchStr($this->arrSql['search_name']); |
---|
62 | $this->arrVal[] = mb_ereg_replace('[ ]+','',$searchName); |
---|
63 | } |
---|
64 | |
---|
65 | // 名前(フリガナ) |
---|
66 | if (!isset($this->arrSql['search_kana'])) $this->arrSql['search_kana'] = ''; |
---|
67 | if (strlen($this->arrSql['search_kana']) > 0) { |
---|
68 | $this->setWhere('(' . $dbFactory->concatColumn(array('kana01', 'kana02')) . ' LIKE ?)'); |
---|
69 | $searchKana = $this->addSearchStr($this->arrSql['search_kana']); |
---|
70 | $this->arrVal[] = mb_ereg_replace('[ ]+','',$searchKana); |
---|
71 | } |
---|
72 | |
---|
73 | // 都道府県 |
---|
74 | if (!isset($this->arrSql['search_pref'])) $this->arrSql['search_pref'] = ''; |
---|
75 | if (strlen($this->arrSql['search_pref']) > 0) { |
---|
76 | $this->setWhere('pref = ?'); |
---|
77 | $this->arrVal[] = $this->arrSql['search_pref']; |
---|
78 | } |
---|
79 | |
---|
80 | // 電話番号 |
---|
81 | if (!isset($this->arrSql['search_tel'])) $this->arrSql['search_tel'] = ''; |
---|
82 | if (is_numeric($this->arrSql['search_tel'])) { |
---|
83 | $this->setWhere('(' . $dbFactory->concatColumn(array('tel01', 'tel02', 'tel03')) . ' LIKE ?)'); |
---|
84 | $searchTel = $this->addSearchStr($this->arrSql['search_tel']); |
---|
85 | $this->arrVal[] = str_replace('-', '', $searchTel); |
---|
86 | } |
---|
87 | |
---|
88 | // 性別 |
---|
89 | if (!isset($this->arrSql['search_sex'])) $this->arrSql['search_sex'] = ''; |
---|
90 | if (is_array($this->arrSql['search_sex'])) { |
---|
91 | $arrSexVal = $this->setItemTerm($this->arrSql['search_sex'] ,'sex'); |
---|
92 | foreach ($arrSexVal as $data) { |
---|
93 | $this->arrVal[] = $data; |
---|
94 | } |
---|
95 | } |
---|
96 | |
---|
97 | // 職業 |
---|
98 | if (!isset($this->arrSql['search_job'])) $this->arrSql['search_job'] = ''; |
---|
99 | if (is_array($this->arrSql['search_job'])) { |
---|
100 | if (in_array('不明', $this->arrSql['search_job'])) { |
---|
101 | $arrJobVal = $this->setItemTermWithNull($this->arrSql['search_job'] ,'job'); |
---|
102 | } else { |
---|
103 | $arrJobVal = $this->setItemTerm($this->arrSql['search_job'] ,'job'); |
---|
104 | } |
---|
105 | if (is_array($arrJobVal)) { |
---|
106 | foreach ($arrJobVal as $data) { |
---|
107 | $this->arrVal[] = $data; |
---|
108 | } |
---|
109 | } |
---|
110 | } |
---|
111 | |
---|
112 | // E-MAIL |
---|
113 | if (!isset($this->arrSql['search_email'])) $this->arrSql['search_email'] = ''; |
---|
114 | if (strlen($this->arrSql['search_email']) > 0) { |
---|
115 | //カンマ区切りで複数の条件指定可能に |
---|
116 | $this->arrSql['search_email'] = explode(',', $this->arrSql['search_email']); |
---|
117 | $sql_where = ''; |
---|
118 | foreach ($this->arrSql['search_email'] as $val) { |
---|
119 | $val = trim($val); |
---|
120 | //検索条件を含まない |
---|
121 | if ($this->arrSql['not_emailinc'] == '1') { |
---|
122 | if ($sql_where == '') { |
---|
123 | $sql_where .= 'dtb_customer.email NOT ILIKE ? '; |
---|
124 | } else { |
---|
125 | $sql_where .= 'AND dtb_customer.email NOT ILIKE ? '; |
---|
126 | } |
---|
127 | } else { |
---|
128 | if ($sql_where == '') { |
---|
129 | $sql_where .= 'dtb_customer.email ILIKE ? '; |
---|
130 | } else { |
---|
131 | $sql_where .= 'OR dtb_customer.email ILIKE ? '; |
---|
132 | } |
---|
133 | } |
---|
134 | $searchEmail = $this->addSearchStr($val); |
---|
135 | $this->arrVal[] = $searchEmail; |
---|
136 | } |
---|
137 | $this->setWhere($sql_where); |
---|
138 | } |
---|
139 | |
---|
140 | // E-MAIL(mobile) |
---|
141 | if (!isset($this->arrSql['search_email_mobile'])) $this->arrSql['search_email_mobile'] = ''; |
---|
142 | |
---|
143 | if (strlen($this->arrSql['search_email_mobile']) > 0) { |
---|
144 | //カンマ区切りで複数の条件指定可能に |
---|
145 | $this->arrSql['search_email_mobile'] = explode(',', $this->arrSql['search_email_mobile']); |
---|
146 | $sql_where = ''; |
---|
147 | foreach ($this->arrSql['search_email_mobile'] as $val) { |
---|
148 | $val = trim($val); |
---|
149 | //検索条件を含まない |
---|
150 | if ($this->arrSql['not_email_mobileinc'] == '1') { |
---|
151 | if ($sql_where == '') { |
---|
152 | $sql_where .= 'dtb_customer.email_mobile NOT ILIKE ? '; |
---|
153 | } else { |
---|
154 | $sql_where .= 'AND dtb_customer.email_mobile NOT ILIKE ? '; |
---|
155 | } |
---|
156 | } else { |
---|
157 | if ($sql_where == '') { |
---|
158 | $sql_where .= 'dtb_customer.email_mobile ILIKE ? '; |
---|
159 | } else { |
---|
160 | $sql_where .= 'OR dtb_customer.email_mobile ILIKE ? '; |
---|
161 | } |
---|
162 | } |
---|
163 | $searchemail_mobile = $this->addSearchStr($val); |
---|
164 | $this->arrVal[] = $searchemail_mobile; |
---|
165 | } |
---|
166 | $this->setWhere($sql_where); |
---|
167 | } |
---|
168 | |
---|
169 | // メールマガジンの場合 |
---|
170 | if ($mode == 'customer') { |
---|
171 | // メルマガ受け取りの選択項目がフォームに存在する場合 |
---|
172 | if (isset($this->arrSql['search_htmlmail'])) { |
---|
173 | $this->setWhere('status = 2'); |
---|
174 | if (SC_Utils_Ex::sfIsInt($this->arrSql['search_htmlmail'])) { |
---|
175 | $this->setWhere('mailmaga_flg = ?'); |
---|
176 | $this->arrVal[] = $this->arrSql['search_htmlmail']; |
---|
177 | } else { |
---|
178 | // メルマガ購読拒否は省く |
---|
179 | $this->setWhere('mailmaga_flg <> 3'); |
---|
180 | } |
---|
181 | } |
---|
182 | } |
---|
183 | |
---|
184 | // 配信メールアドレス種別 |
---|
185 | if ($mode == 'customer') { |
---|
186 | if (isset($this->arrSql['search_mail_type'])) { |
---|
187 | $sqlEmailMobileIsEmpty = "(dtb_customer.email_mobile IS NULL OR dtb_customer.email_mobile = '')"; |
---|
188 | switch ($this->arrSql['search_mail_type']) { |
---|
189 | // PCメールアドレス |
---|
190 | case 1: |
---|
191 | $this->setWhere("(dtb_customer.email <> dtb_customer.email_mobile OR $sqlEmailMobileIsEmpty)"); |
---|
192 | break; |
---|
193 | // 携帯メールアドレス |
---|
194 | case 2: |
---|
195 | $this->setWhere("NOT $sqlEmailMobileIsEmpty"); |
---|
196 | break; |
---|
197 | // PCメールアドレス (携帯メールアドレスを登録している会員は除外) |
---|
198 | case 3: |
---|
199 | $this->setWhere($sqlEmailMobileIsEmpty); |
---|
200 | break; |
---|
201 | // 携帯メールアドレス (PCメールアドレスを登録している会員は除外) |
---|
202 | case 4: |
---|
203 | $this->setWhere('dtb_customer.email = dtb_customer.email_mobile'); |
---|
204 | break; |
---|
205 | } |
---|
206 | } |
---|
207 | } |
---|
208 | |
---|
209 | // 購入金額指定 |
---|
210 | if (!isset($this->arrSql['search_buy_total_from'])) $this->arrSql['search_buy_total_from'] = ''; |
---|
211 | if (!isset($this->arrSql['search_buy_total_to'])) $this->arrSql['search_buy_total_to'] = ''; |
---|
212 | if (is_numeric($this->arrSql['search_buy_total_from']) || is_numeric($this->arrSql['search_buy_total_to'])) { |
---|
213 | $arrBuyTotal = $this->selectRange($this->arrSql['search_buy_total_from'], $this->arrSql['search_buy_total_to'], 'buy_total'); |
---|
214 | foreach ($arrBuyTotal as $data) { |
---|
215 | $this->arrVal[] = $data; |
---|
216 | } |
---|
217 | } |
---|
218 | |
---|
219 | // 購入回数指定 |
---|
220 | if (!isset($this->arrSql['search_buy_times_from'])) $this->arrSql['search_buy_times_from'] = ''; |
---|
221 | if (!isset($this->arrSql['search_buy_times_to'])) $this->arrSql['search_buy_times_to'] = ''; |
---|
222 | if (is_numeric($this->arrSql['search_buy_times_from']) || is_numeric($this->arrSql['search_buy_times_to'])) { |
---|
223 | $arrBuyTimes = $this->selectRange($this->arrSql['search_buy_times_from'], $this->arrSql['search_buy_times_to'], 'buy_times'); |
---|
224 | foreach ($arrBuyTimes as $data) { |
---|
225 | $this->arrVal[] = $data; |
---|
226 | } |
---|
227 | } |
---|
228 | |
---|
229 | // 誕生日期間指定 |
---|
230 | if (!isset($this->arrSql['search_b_start_year'])) $this->arrSql['search_b_start_year'] = ''; |
---|
231 | if (!isset($this->arrSql['search_b_start_month'])) $this->arrSql['search_b_start_month'] = ''; |
---|
232 | if (!isset($this->arrSql['search_b_start_day'])) $this->arrSql['search_b_start_day'] = ''; |
---|
233 | if (!isset($this->arrSql['search_b_end_year'])) $this->arrSql['search_b_end_year'] = ''; |
---|
234 | if (!isset($this->arrSql['search_b_end_month'])) $this->arrSql['search_b_end_month'] = ''; |
---|
235 | if (!isset($this->arrSql['search_b_end_day'])) $this->arrSql['search_b_end_day'] = ''; |
---|
236 | 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) |
---|
237 | || strlen($this->arrSql['search_b_end_year']) > 0 && strlen($this->arrSql['search_b_end_month']) > 0 && strlen($this->arrSql['search_b_end_day']) > 0) { |
---|
238 | |
---|
239 | $arrBirth = $this->selectTermRange($this->arrSql['search_b_start_year'], $this->arrSql['search_b_start_month'], $this->arrSql['search_b_start_day'], |
---|
240 | $this->arrSql['search_b_end_year'], $this->arrSql['search_b_end_month'], $this->arrSql['search_b_end_day'], 'birth'); |
---|
241 | foreach ($arrBirth as $data) { |
---|
242 | $this->arrVal[] = $data; |
---|
243 | } |
---|
244 | } |
---|
245 | |
---|
246 | // 誕生月の検索 |
---|
247 | if (!isset($this->arrSql['search_birth_month'])) $this->arrSql['search_birth_month'] = ''; |
---|
248 | if (is_numeric($this->arrSql['search_birth_month'])) { |
---|
249 | $this->setWhere(' EXTRACT(month from birth) = ?'); |
---|
250 | $this->arrVal[] = $this->arrSql['search_birth_month']; |
---|
251 | } |
---|
252 | |
---|
253 | // 登録期間指定 |
---|
254 | if (!isset($this->arrSql['search_start_year'])) $this->arrSql['search_start_year'] = ''; |
---|
255 | if (!isset($this->arrSql['search_start_month'])) $this->arrSql['search_start_month'] = ''; |
---|
256 | if (!isset($this->arrSql['search_start_day'])) $this->arrSql['search_start_day'] = ''; |
---|
257 | if (!isset($this->arrSql['search_end_year'])) $this->arrSql['search_end_year'] = ''; |
---|
258 | if (!isset($this->arrSql['search_end_month'])) $this->arrSql['search_end_month'] = ''; |
---|
259 | if (!isset($this->arrSql['search_end_day'])) $this->arrSql['search_end_day'] = ''; |
---|
260 | if ( (strlen($this->arrSql['search_start_year']) > 0 && strlen($this->arrSql['search_start_month']) > 0 && strlen($this->arrSql['search_start_day']) > 0) || |
---|
261 | (strlen($this->arrSql['search_end_year']) > 0 && strlen($this->arrSql['search_end_month']) >0 && strlen($this->arrSql['search_end_day']) > 0)) { |
---|
262 | |
---|
263 | $arrRegistTime = $this->selectTermRange($this->arrSql['search_start_year'], $this->arrSql['search_start_month'], $this->arrSql['search_start_day'] |
---|
264 | , $this->arrSql['search_end_year'], $this->arrSql['search_end_month'], $this->arrSql['search_end_day'], $regdate_col); |
---|
265 | foreach ($arrRegistTime as $data) { |
---|
266 | $this->arrVal[] = $data; |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|
270 | // 最終購入日指定 |
---|
271 | if (!isset($this->arrSql['search_buy_start_year'])) $this->arrSql['search_buy_start_year'] = ''; |
---|
272 | if (!isset($this->arrSql['search_buy_start_month'])) $this->arrSql['search_buy_start_month'] = ''; |
---|
273 | if (!isset($this->arrSql['search_buy_start_day'])) $this->arrSql['search_buy_start_day'] = ''; |
---|
274 | if (!isset($this->arrSql['search_buy_end_year'])) $this->arrSql['search_buy_end_year'] = ''; |
---|
275 | if (!isset($this->arrSql['search_buy_end_month'])) $this->arrSql['search_buy_end_month'] = ''; |
---|
276 | if (!isset($this->arrSql['search_buy_end_day'])) $this->arrSql['search_buy_end_day'] = ''; |
---|
277 | |
---|
278 | 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) || |
---|
279 | (strlen($this->arrSql['search_buy_end_year']) > 0 && strlen($this->arrSql['search_buy_end_month']) >0 && strlen($this->arrSql['search_buy_end_day']) > 0)) { |
---|
280 | $arrRegistTime = $this->selectTermRange($this->arrSql['search_buy_start_year'], $this->arrSql['search_buy_start_month'], $this->arrSql['search_buy_start_day'] |
---|
281 | , $this->arrSql['search_buy_end_year'], $this->arrSql['search_buy_end_month'], $this->arrSql['search_buy_end_day'], 'last_buy_date'); |
---|
282 | foreach ($arrRegistTime as $data) { |
---|
283 | $this->arrVal[] = $data; |
---|
284 | } |
---|
285 | } |
---|
286 | |
---|
287 | // 購入商品コード |
---|
288 | if (!isset($this->arrSql['search_buy_product_code'])) $this->arrSql['search_buy_product_code'] = ''; |
---|
289 | if (strlen($this->arrSql['search_buy_product_code']) > 0) { |
---|
290 | $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 ?) AND del_flg = 0)'); |
---|
291 | $search_buyproduct_code = $this->addSearchStr($this->arrSql['search_buy_product_code']); |
---|
292 | $this->arrVal[] = $search_buyproduct_code; |
---|
293 | } |
---|
294 | |
---|
295 | // 購入商品名称 |
---|
296 | if (!isset($this->arrSql['search_buy_product_name'])) $this->arrSql['search_buy_product_name'] = ''; |
---|
297 | if (strlen($this->arrSql['search_buy_product_name']) > 0) { |
---|
298 | $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 ?) AND del_flg = 0)'); |
---|
299 | $search_buyproduct_name = $this->addSearchStr($this->arrSql['search_buy_product_name']); |
---|
300 | $this->arrVal[] = $search_buyproduct_name; |
---|
301 | } |
---|
302 | |
---|
303 | // カテゴリを選択している場合のみ絞込検索を行う |
---|
304 | if (!isset($this->arrSql['search_category_id'])) $this->arrSql['search_category_id'] = ''; |
---|
305 | if (strlen($this->arrSql['search_category_id']) > 0) { |
---|
306 | // カテゴリで絞込検索を行うSQL文生成 |
---|
307 | list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['search_category_id']); |
---|
308 | |
---|
309 | // カテゴリで絞込みが可能の場合 |
---|
310 | if ($tmp_where != '') { |
---|
311 | $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.') AND del_flg = 0)) '); |
---|
312 | $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval); |
---|
313 | } |
---|
314 | } |
---|
315 | |
---|
316 | // 会員状態 |
---|
317 | if (!isset($this->arrSql['search_status'])) $this->arrSql['search_status'] = ''; |
---|
318 | if (is_array($this->arrSql['search_status'])) { |
---|
319 | $arrStatusVal = $this->setItemTerm($this->arrSql['search_status'] ,'status'); |
---|
320 | foreach ($arrStatusVal as $data) { |
---|
321 | $this->arrVal[] = $data; |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | $this->setOrder('customer_id DESC'); |
---|
326 | } |
---|
327 | |
---|
328 | // 検索用SQL |
---|
329 | function getList() { |
---|
330 | $this->select = 'SELECT customer_id,name01,name02,kana01,kana02,sex,email,email_mobile,tel01,tel02,tel03,pref,status,update_date,mailmaga_flg FROM dtb_customer '; |
---|
331 | return $this->getSql(0); |
---|
332 | } |
---|
333 | |
---|
334 | function getListMailMagazine($is_mobile = false) { |
---|
335 | |
---|
336 | $colomn = $this->getMailMagazineColumn($is_mobile); |
---|
337 | $this->select = " |
---|
338 | SELECT |
---|
339 | $colomn |
---|
340 | FROM |
---|
341 | dtb_customer"; |
---|
342 | return $this->getSql(0); |
---|
343 | } |
---|
344 | |
---|
345 | // 検索総数カウント用SQL |
---|
346 | function getListCount() { |
---|
347 | $this->select = 'SELECT COUNT(customer_id) FROM dtb_customer '; |
---|
348 | return $this->getSql(1); |
---|
349 | } |
---|
350 | |
---|
351 | // CSVダウンロード用SQL |
---|
352 | function getListCSV($arrColumnCSV) { |
---|
353 | $this->arrColumnCSV = $arrColumnCSV; |
---|
354 | $i = 0; |
---|
355 | foreach ($this->arrColumnCSV as $val) { |
---|
356 | if ($i != 0) $state .= ', '; |
---|
357 | $state .= $val['sql']; |
---|
358 | $i ++; |
---|
359 | } |
---|
360 | |
---|
361 | $this->select = 'SELECT ' .$state. ' FROM dtb_customer '; |
---|
362 | return $this->getSql(2); |
---|
363 | } |
---|
364 | |
---|
365 | function getWhere() { |
---|
366 | return array($this->where, $this->arrVal); |
---|
367 | } |
---|
368 | } |
---|