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

Revision 21527, 17.9 KB checked in by Seasoft, 11 years ago (diff)

#1613 (ソース整形・ソースコメントの改善)

  • Zend Framework PHP 標準コーディング規約への準拠を高めた
  • 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[] = ereg_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                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
240            $arrBirth = $this->selectTermRange($this->arrSql['search_b_start_year'], $this->arrSql['search_b_start_month'], $this->arrSql['search_b_start_day'],
241                                               $this->arrSql['search_b_end_year'], $this->arrSql['search_b_end_month'], $this->arrSql['search_b_end_day'], 'birth');
242            foreach ($arrBirth as $data) {
243                $this->arrVal[] = $data;
244            }
245        }
246
247        // 誕生月の検索
248        if (!isset($this->arrSql['search_birth_month'])) $this->arrSql['search_birth_month'] = '';
249        if (is_numeric($this->arrSql['search_birth_month'])) {
250            $this->setWhere(' EXTRACT(month from birth) = ?');
251            $this->arrVal[] = $this->arrSql['search_birth_month'];
252        }
253
254        // 登録期間指定
255        if (!isset($this->arrSql['search_start_year'])) $this->arrSql['search_start_year'] = '';
256        if (!isset($this->arrSql['search_start_month'])) $this->arrSql['search_start_month'] = '';
257        if (!isset($this->arrSql['search_start_day'])) $this->arrSql['search_start_day'] = '';
258        if (!isset($this->arrSql['search_end_year'])) $this->arrSql['search_end_year'] = '';
259        if (!isset($this->arrSql['search_end_month'])) $this->arrSql['search_end_month'] = '';
260        if (!isset($this->arrSql['search_end_day'])) $this->arrSql['search_end_day'] = '';
261        if ( (strlen($this->arrSql['search_start_year']) > 0 && strlen($this->arrSql['search_start_month']) > 0 && strlen($this->arrSql['search_start_day']) > 0) ||
262                (strlen($this->arrSql['search_end_year']) > 0 && strlen($this->arrSql['search_end_month']) >0 && strlen($this->arrSql['search_end_day']) > 0)) {
263
264            $arrRegistTime = $this->selectTermRange($this->arrSql['search_start_year'], $this->arrSql['search_start_month'], $this->arrSql['search_start_day']
265                            , $this->arrSql['search_end_year'], $this->arrSql['search_end_month'], $this->arrSql['search_end_day'], $regdate_col);
266            foreach ($arrRegistTime as $data) {
267                $this->arrVal[] = $data;
268            }
269        }
270
271        // 最終購入日指定
272        if (!isset($this->arrSql['search_buy_start_year'])) $this->arrSql['search_buy_start_year'] = '';
273        if (!isset($this->arrSql['search_buy_start_month'])) $this->arrSql['search_buy_start_month'] = '';
274        if (!isset($this->arrSql['search_buy_start_day'])) $this->arrSql['search_buy_start_day'] = '';
275        if (!isset($this->arrSql['search_buy_end_year'])) $this->arrSql['search_buy_end_year'] = '';
276        if (!isset($this->arrSql['search_buy_end_month'])) $this->arrSql['search_buy_end_month'] = '';
277        if (!isset($this->arrSql['search_buy_end_day'])) $this->arrSql['search_buy_end_day'] = '';
278
279        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) ||
280                (strlen($this->arrSql['search_buy_end_year']) > 0 && strlen($this->arrSql['search_buy_end_month']) >0 && strlen($this->arrSql['search_buy_end_day']) > 0)) {
281            $arrRegistTime = $this->selectTermRange($this->arrSql['search_buy_start_year'], $this->arrSql['search_buy_start_month'], $this->arrSql['search_buy_start_day']
282                            , $this->arrSql['search_buy_end_year'], $this->arrSql['search_buy_end_month'], $this->arrSql['search_buy_end_day'], 'last_buy_date');
283            foreach ($arrRegistTime as $data) {
284                $this->arrVal[] = $data;
285            }
286        }
287
288        // 購入商品コード
289        if (!isset($this->arrSql['search_buy_product_code'])) $this->arrSql['search_buy_product_code'] = '';
290        if (strlen($this->arrSql['search_buy_product_code']) > 0) {
291            $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)');
292            $search_buyproduct_code = $this->addSearchStr($this->arrSql['search_buy_product_code']);
293            $this->arrVal[] = $search_buyproduct_code;
294        }
295
296        // 購入商品名称
297        if (!isset($this->arrSql['search_buy_product_name'])) $this->arrSql['search_buy_product_name'] = '';
298        if (strlen($this->arrSql['search_buy_product_name']) > 0) {
299            $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)');
300            $search_buyproduct_name = $this->addSearchStr($this->arrSql['search_buy_product_name']);
301            $this->arrVal[] = $search_buyproduct_name;
302        }
303
304        // カテゴリを選択している場合のみ絞込検索を行う
305        if (!isset($this->arrSql['search_category_id'])) $this->arrSql['search_category_id'] = '';
306        if (strlen($this->arrSql['search_category_id']) > 0) {
307            // カテゴリで絞込検索を行うSQL文生成
308            list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['search_category_id']);
309
310            // カテゴリで絞込みが可能の場合
311            if ($tmp_where != '') {
312                $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)) ');
313                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
314            }
315        }
316
317        // 会員状態
318        if (!isset($this->arrSql['search_status'])) $this->arrSql['search_status'] = '';
319        if (is_array($this->arrSql['search_status'])) {
320            $arrStatusVal = $this->setItemTerm($this->arrSql['search_status'] ,'status');
321            foreach ($arrStatusVal as $data) {
322                $this->arrVal[] = $data;
323            }
324        }
325
326        $this->setOrder('customer_id DESC');
327    }
328
329    // 検索用SQL
330    function getList() {
331        $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 ';
332        return $this->getSql(0);
333    }
334
335    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        return $this->getSql(0);
344    }
345
346    // 検索総数カウント用SQL
347    function getListCount() {
348        $this->select = 'SELECT COUNT(customer_id) FROM dtb_customer ';
349        return $this->getSql(1);
350    }
351
352    // CSVダウンロード用SQL
353    function getListCSV($arrColumnCSV) {
354        $this->arrColumnCSV = $arrColumnCSV;
355        $i = 0;
356        foreach ($this->arrColumnCSV as $val) {
357            if ($i != 0) $state .= ', ';
358            $state .= $val['sql'];
359            $i ++;
360        }
361
362        $this->select = 'SELECT ' .$state. ' FROM dtb_customer ';
363        return $this->getSql(2);
364    }
365
366    function getWhere() {
367        return array($this->where, $this->arrVal);
368    }
369}
Note: See TracBrowser for help on using the repository browser.