source: branches/version-2_12-dev/data/class/SC_CustomerList.php @ 21755

Revision 21755, 18.0 KB checked in by shutta, 10 years ago (diff)

#515 PHP 5.3.0対応
PHP5.3以降で、非推奨関数となるereg系関数を書き換えた。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • Property svn:mime-type set to text/x-httpd-php; charset=UTF-8
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2011 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 */
27class SC_CustomerList extends SC_SelectSql_Ex {
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_Ex::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['search_customer_id'])) $this->arrSql['search_customer_id'] = '';
54        if (strlen($this->arrSql['search_customer_id']) > 0) {
55            $this->setWhere('customer_id =  ?');
56            $this->arrVal[] = $this->arrSql['search_customer_id'];
57        }
58
59        // 名前
60        if (!isset($this->arrSql['search_name'])) $this->arrSql['search_name'] = '';
61        if (strlen($this->arrSql['search_name']) > 0) {
62            $this->setWhere('(' . $dbFactory->concatColumn(array('name01', 'name02')) . ' LIKE ?)');
63            $searchName = $this->addSearchStr($this->arrSql['search_name']);
64            $this->arrVal[] = mb_ereg_replace('[  ]+','',$searchName);
65        }
66
67        // 名前(フリガナ)
68        if (!isset($this->arrSql['search_kana'])) $this->arrSql['search_kana'] = '';
69        if (strlen($this->arrSql['search_kana']) > 0) {
70            $this->setWhere('(' . $dbFactory->concatColumn(array('kana01', 'kana02')) . ' LIKE ?)');
71            $searchKana = $this->addSearchStr($this->arrSql['search_kana']);
72            $this->arrVal[] = mb_ereg_replace('[  ]+','',$searchKana);
73        }
74
75        // 都道府県
76        if (!isset($this->arrSql['search_pref'])) $this->arrSql['search_pref'] = '';
77        if (strlen($this->arrSql['search_pref']) > 0) {
78            $this->setWhere('pref = ?');
79            $this->arrVal[] = $this->arrSql['search_pref'];
80        }
81
82        // 電話番号
83        if (!isset($this->arrSql['search_tel'])) $this->arrSql['search_tel'] = '';
84        if (is_numeric($this->arrSql['search_tel'])) {
85            $this->setWhere('(' . $dbFactory->concatColumn(array('tel01', 'tel02', 'tel03')) . ' LIKE ?)');
86            $searchTel = $this->addSearchStr($this->arrSql['search_tel']);
87            $this->arrVal[] = str_replace('-', '', $searchTel);
88        }
89
90        // 性別
91        if (!isset($this->arrSql['search_sex'])) $this->arrSql['search_sex'] = '';
92        if (is_array($this->arrSql['search_sex'])) {
93            $arrSexVal = $this->setItemTerm($this->arrSql['search_sex'] ,'sex');
94            foreach ($arrSexVal as $data) {
95                $this->arrVal[] = $data;
96            }
97        }
98
99        // 職業
100        if (!isset($this->arrSql['search_job'])) $this->arrSql['search_job'] = '';
101        if (is_array($this->arrSql['search_job'])) {
102            if (in_array('不明', $this->arrSql['search_job'])) {
103                $arrJobVal = $this->setItemTermWithNull($this->arrSql['search_job'] ,'job');
104            } else {
105                $arrJobVal = $this->setItemTerm($this->arrSql['search_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['search_email'])) $this->arrSql['search_email'] = '';
116        if (strlen($this->arrSql['search_email']) > 0) {
117            //カンマ区切りで複数の条件指定可能に
118            $this->arrSql['search_email'] = explode(',', $this->arrSql['search_email']);
119            $sql_where = '';
120            foreach ($this->arrSql['search_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['search_email_mobile'])) $this->arrSql['search_email_mobile'] = '';
144
145        if (strlen($this->arrSql['search_email_mobile']) > 0) {
146            //カンマ区切りで複数の条件指定可能に
147            $this->arrSql['search_email_mobile'] = explode(',', $this->arrSql['search_email_mobile']);
148            $sql_where = '';
149            foreach ($this->arrSql['search_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['search_htmlmail'])) {
175                $this->setWhere('status = 2');
176                if (SC_Utils_Ex::sfIsInt($this->arrSql['search_htmlmail'])) {
177                    $this->setWhere('mailmaga_flg = ?');
178                    $this->arrVal[] = $this->arrSql['search_htmlmail'];
179                } else {
180                    // メルマガ購読拒否は省く
181                    $this->setWhere('mailmaga_flg <> 3');
182                }
183            }
184        }
185
186        // 配信メールアドレス種別
187        if ($mode == 'customer') {
188            if (isset($this->arrSql['search_mail_type'])) {
189                $sqlEmailMobileIsEmpty = "(dtb_customer.email_mobile IS NULL OR dtb_customer.email_mobile = '')";
190                switch ($this->arrSql['search_mail_type']) {
191                    // PCメールアドレス
192                    case 1:
193                        $this->setWhere("(dtb_customer.email <> dtb_customer.email_mobile OR $sqlEmailMobileIsEmpty)");
194                        break;
195                    // 携帯メールアドレス
196                    case 2:
197                        $this->setWhere("NOT $sqlEmailMobileIsEmpty");
198                        break;
199                    // PCメールアドレス (携帯メールアドレスを登録している会員は除外)
200                    case 3:
201                        $this->setWhere($sqlEmailMobileIsEmpty);
202                        break;
203                    // 携帯メールアドレス (PCメールアドレスを登録している会員は除外)
204                    case 4:
205                        $this->setWhere('dtb_customer.email = dtb_customer.email_mobile');
206                        break;
207                }
208            }
209        }
210
211        // 購入金額指定
212        if (!isset($this->arrSql['search_buy_total_from'])) $this->arrSql['search_buy_total_from'] = '';
213        if (!isset($this->arrSql['search_buy_total_to'])) $this->arrSql['search_buy_total_to'] = '';
214        if (is_numeric($this->arrSql['search_buy_total_from']) || is_numeric($this->arrSql['search_buy_total_to'])) {
215            $arrBuyTotal = $this->selectRange($this->arrSql['search_buy_total_from'], $this->arrSql['search_buy_total_to'], 'buy_total');
216            foreach ($arrBuyTotal as $data) {
217                $this->arrVal[] = $data;
218            }
219        }
220
221        // 購入回数指定
222        if (!isset($this->arrSql['search_buy_times_from'])) $this->arrSql['search_buy_times_from'] = '';
223        if (!isset($this->arrSql['search_buy_times_to'])) $this->arrSql['search_buy_times_to'] = '';
224        if (is_numeric($this->arrSql['search_buy_times_from']) || is_numeric($this->arrSql['search_buy_times_to'])) {
225            $arrBuyTimes = $this->selectRange($this->arrSql['search_buy_times_from'], $this->arrSql['search_buy_times_to'], 'buy_times');
226            foreach ($arrBuyTimes as $data) {
227                $this->arrVal[] = $data;
228            }
229        }
230
231        // 誕生日期間指定
232        if (!isset($this->arrSql['search_b_start_year'])) $this->arrSql['search_b_start_year'] = '';
233        if (!isset($this->arrSql['search_b_start_month'])) $this->arrSql['search_b_start_month'] = '';
234        if (!isset($this->arrSql['search_b_start_day'])) $this->arrSql['search_b_start_day'] = '';
235        if (!isset($this->arrSql['search_b_end_year'])) $this->arrSql['search_b_end_year'] = '';
236        if (!isset($this->arrSql['search_b_end_month'])) $this->arrSql['search_b_end_month'] = '';
237        if (!isset($this->arrSql['search_b_end_day'])) $this->arrSql['search_b_end_day'] = '';
238        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)
239            || strlen($this->arrSql['search_b_end_year']) > 0 && strlen($this->arrSql['search_b_end_month']) > 0 && strlen($this->arrSql['search_b_end_day']) > 0) {
240
241            $arrBirth = $this->selectTermRange($this->arrSql['search_b_start_year'], $this->arrSql['search_b_start_month'], $this->arrSql['search_b_start_day'],
242                                               $this->arrSql['search_b_end_year'], $this->arrSql['search_b_end_month'], $this->arrSql['search_b_end_day'], 'birth');
243            foreach ($arrBirth as $data) {
244                $this->arrVal[] = $data;
245            }
246        }
247
248        // 誕生月の検索
249        if (!isset($this->arrSql['search_birth_month'])) $this->arrSql['search_birth_month'] = '';
250        if (is_numeric($this->arrSql['search_birth_month'])) {
251            $this->setWhere(' EXTRACT(month from birth) = ?');
252            $this->arrVal[] = $this->arrSql['search_birth_month'];
253        }
254
255        // 登録期間指定
256        if (!isset($this->arrSql['search_start_year'])) $this->arrSql['search_start_year'] = '';
257        if (!isset($this->arrSql['search_start_month'])) $this->arrSql['search_start_month'] = '';
258        if (!isset($this->arrSql['search_start_day'])) $this->arrSql['search_start_day'] = '';
259        if (!isset($this->arrSql['search_end_year'])) $this->arrSql['search_end_year'] = '';
260        if (!isset($this->arrSql['search_end_month'])) $this->arrSql['search_end_month'] = '';
261        if (!isset($this->arrSql['search_end_day'])) $this->arrSql['search_end_day'] = '';
262        if ( (strlen($this->arrSql['search_start_year']) > 0 && strlen($this->arrSql['search_start_month']) > 0 && strlen($this->arrSql['search_start_day']) > 0) ||
263                (strlen($this->arrSql['search_end_year']) > 0 && strlen($this->arrSql['search_end_month']) >0 && strlen($this->arrSql['search_end_day']) > 0)) {
264
265            $arrRegistTime = $this->selectTermRange($this->arrSql['search_start_year'], $this->arrSql['search_start_month'], $this->arrSql['search_start_day']
266                            , $this->arrSql['search_end_year'], $this->arrSql['search_end_month'], $this->arrSql['search_end_day'], $regdate_col);
267            foreach ($arrRegistTime as $data) {
268                $this->arrVal[] = $data;
269            }
270        }
271
272        // 最終購入日指定
273        if (!isset($this->arrSql['search_buy_start_year'])) $this->arrSql['search_buy_start_year'] = '';
274        if (!isset($this->arrSql['search_buy_start_month'])) $this->arrSql['search_buy_start_month'] = '';
275        if (!isset($this->arrSql['search_buy_start_day'])) $this->arrSql['search_buy_start_day'] = '';
276        if (!isset($this->arrSql['search_buy_end_year'])) $this->arrSql['search_buy_end_year'] = '';
277        if (!isset($this->arrSql['search_buy_end_month'])) $this->arrSql['search_buy_end_month'] = '';
278        if (!isset($this->arrSql['search_buy_end_day'])) $this->arrSql['search_buy_end_day'] = '';
279
280        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) ||
281                (strlen($this->arrSql['search_buy_end_year']) > 0 && strlen($this->arrSql['search_buy_end_month']) >0 && strlen($this->arrSql['search_buy_end_day']) > 0)) {
282            $arrRegistTime = $this->selectTermRange($this->arrSql['search_buy_start_year'], $this->arrSql['search_buy_start_month'], $this->arrSql['search_buy_start_day']
283                            , $this->arrSql['search_buy_end_year'], $this->arrSql['search_buy_end_month'], $this->arrSql['search_buy_end_day'], 'last_buy_date');
284            foreach ($arrRegistTime as $data) {
285                $this->arrVal[] = $data;
286            }
287        }
288
289        // 購入商品コード
290        if (!isset($this->arrSql['search_buy_product_code'])) $this->arrSql['search_buy_product_code'] = '';
291        if (strlen($this->arrSql['search_buy_product_code']) > 0) {
292            $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)');
293            $search_buyproduct_code = $this->addSearchStr($this->arrSql['search_buy_product_code']);
294            $this->arrVal[] = $search_buyproduct_code;
295        }
296
297        // 購入商品名称
298        if (!isset($this->arrSql['search_buy_product_name'])) $this->arrSql['search_buy_product_name'] = '';
299        if (strlen($this->arrSql['search_buy_product_name']) > 0) {
300            $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)');
301            $search_buyproduct_name = $this->addSearchStr($this->arrSql['search_buy_product_name']);
302            $this->arrVal[] = $search_buyproduct_name;
303        }
304
305        // カテゴリを選択している場合のみ絞込検索を行う
306        if (!isset($this->arrSql['search_category_id'])) $this->arrSql['search_category_id'] = '';
307        if (strlen($this->arrSql['search_category_id']) > 0) {
308            // カテゴリで絞込検索を行うSQL文生成
309            list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['search_category_id']);
310
311            // カテゴリで絞込みが可能の場合
312            if ($tmp_where != '') {
313                $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)) ');
314                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
315            }
316        }
317
318        // 会員状態
319        if (!isset($this->arrSql['search_status'])) $this->arrSql['search_status'] = '';
320        if (is_array($this->arrSql['search_status'])) {
321            $arrStatusVal = $this->setItemTerm($this->arrSql['search_status'] ,'status');
322            foreach ($arrStatusVal as $data) {
323                $this->arrVal[] = $data;
324            }
325        }
326
327        $this->setOrder('customer_id DESC');
328    }
329
330    // 検索用SQL
331    function getList() {
332        $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 ';
333        return $this->getSql(0);
334    }
335
336    function getListMailMagazine($is_mobile = false) {
337
338        $colomn = $this->getMailMagazineColumn($is_mobile);
339        $this->select = "
340            SELECT
341                $colomn
342            FROM
343                dtb_customer";
344        return $this->getSql(0);
345    }
346
347    // 検索総数カウント用SQL
348    function getListCount() {
349        $this->select = 'SELECT COUNT(customer_id) FROM dtb_customer ';
350        return $this->getSql(1);
351    }
352
353    // CSVダウンロード用SQL
354    function getListCSV($arrColumnCSV) {
355        $this->arrColumnCSV = $arrColumnCSV;
356        $i = 0;
357        foreach ($this->arrColumnCSV as $val) {
358            if ($i != 0) $state .= ', ';
359            $state .= $val['sql'];
360            $i ++;
361        }
362
363        $this->select = 'SELECT ' .$state. ' FROM dtb_customer ';
364        return $this->getSql(2);
365    }
366
367    function getWhere() {
368        return array($this->where, $this->arrVal);
369    }
370}
Note: See TracBrowser for help on using the repository browser.