source: branches/version-2_13-dev/data/class/SC_CustomerList.php @ 23124

Revision 23124, 18.0 KB checked in by kimoto, 11 years ago (diff)

#2043 typo修正・ソース整形・ソースコメントの改善 for 2.13.0
PHP4的な書き方の修正

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