source: branches/version-2_5-dev/data/class/SC_CustomerList.php @ 19704

Revision 19704, 18.3 KB checked in by Seasoft, 13 years ago (diff)

#628(未使用処理・定義などの削除)

  • 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-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 */
27class 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            // 管理機能顧客検索の場合仮登録会員も検索
48            //$this->setWhere( "(status = 1 OR status = 2) AND del_flg = 0 ");
49            $this->setWhere( " del_flg = 0 ");
50            // 登録日を示すカラム
51            $regdate_col = 'dtb_customer.update_date';
52        }
53
54        // メールマガジンの場合
55        if($mode == "magazine") {
56            $this->setWhere("(del_flg = 0 OR del_flg IS NULL)");
57            $this->setWhere("status = 2");
58            // 登録日を示すカラム
59            $regdate_col = 'dtb_customer.create_date';
60        }
61
62        // 顧客ID
63        if (!isset($this->arrSql['customer_id'])) $this->arrSql['customer_id'] = "";
64        if ( strlen($this->arrSql['customer_id']) > 0 ) {
65            $this->setWhere( "customer_id =  ?" );
66            $this->arrVal[] = $this->arrSql['customer_id'];
67        }
68
69        // 名前
70        if (!isset($this->arrSql['name'])) $this->arrSql['name'] = "";
71        if ( strlen($this->arrSql['name']) > 0 ) {
72            $this->setWhere("(" . $dbFactory->concatColumn(array("name01", "name02")) . " LIKE ?)" );
73            $searchName = $this->addSearchStr($this->arrSql['name']);
74            $this->arrVal[] = mb_ereg_replace("[  ]+","",$searchName);
75        }
76
77        // 名前(カナ)
78        if (!isset($this->arrSql['kana'])) $this->arrSql['kana'] = "";
79        if ( strlen($this->arrSql['kana']) > 0 ) {
80            $this->setWhere("(" . $dbFactory->concatColumn(array("kana01", "kana02")) . " LIKE ?)" );
81            $searchKana = $this->addSearchStr($this->arrSql['kana']);
82            $this->arrVal[] = mb_ereg_replace("[  ]+","",$searchKana);
83        }
84
85        // 都道府県
86        if (!isset($this->arrSql['pref'])) $this->arrSql['pref'] = "";
87        if ( strlen($this->arrSql['pref']) > 0 ) {
88            $this->setWhere( "pref = ?" );
89            $this->arrVal[] = $this->arrSql['pref'];
90        }
91
92        // 電話番号
93        if (!isset($this->arrSql['tel'])) $this->arrSql['tel'] = "";
94        if ( is_numeric( $this->arrSql['tel'] ) ) {
95            $this->setWhere("(" . $dbFactory->concatColumn(array("tel01", "tel02", "tel03")) . " LIKE ?)" );
96            $searchTel = $this->addSearchStr($this->arrSql['tel']);
97            $this->arrVal[] = ereg_replace("-", "", $searchTel);
98        }
99
100        // 性別
101        if (!isset($this->arrSql['sex'])) $this->arrSql['sex'] = "";
102        if ( is_array( $this->arrSql['sex'] ) ){
103            $arrSexVal = $this->setItemTerm( $this->arrSql['sex'] ,"sex" );
104            foreach ($arrSexVal as $data) {
105                $this->arrVal[] = $data;
106            }
107        }
108
109        // 職業
110        if (!isset($this->arrSql['job'])) $this->arrSql['job'] = "";
111        if ( is_array( $this->arrSql['job'] ) ){
112            if ( in_array("不明", $this->arrSql['job'] ) ) {
113                $arrJobVal = $this->setItemTermWithNull( $this->arrSql['job'] ,"job" );
114            } else {
115                $arrJobVal = $this->setItemTerm( $this->arrSql['job'] ,"job" );
116            }
117            if (is_array($arrJobVal)) {
118                foreach ($arrJobVal as $data) {
119                    $this->arrVal[] = $data;
120                }
121            }
122        }
123
124        // E-MAIL
125        if (!isset($this->arrSql['email'])) $this->arrSql['email'] = "";
126        if (strlen($this->arrSql['email']) > 0) {
127            //カンマ区切りで複数の条件指定可能に
128            $this->arrSql['email'] = explode(",", $this->arrSql['email']);
129            $sql_where = "";
130            foreach($this->arrSql['email'] as $val) {
131                $val = trim($val);
132                //検索条件を含まない
133                if($this->arrSql['not_emailinc'] == '1') {
134                    if($sql_where == "") {
135                        $sql_where .= "dtb_customer.email NOT ILIKE ? ";
136                    } else {
137                        $sql_where .= "AND dtb_customer.email NOT ILIKE ? ";
138                    }
139                } else {
140                    if($sql_where == "") {
141                        $sql_where .= "dtb_customer.email ILIKE ? ";
142                    } else {
143                        $sql_where .= "OR dtb_customer.email ILIKE ? ";
144                    }
145                }
146                $searchEmail = $this->addSearchStr($val);
147                $this->arrVal[] = $searchEmail;
148            }
149            $this->setWhere($sql_where);
150        }
151
152        // E-MAIL(mobile)
153        if (!isset($this->arrSql['email_mobile'])) $this->arrSql['email_mobile'] = "";
154       
155        if (strlen($this->arrSql['email_mobile']) > 0) {
156            //カンマ区切りで複数の条件指定可能に
157            $this->arrSql['email_mobile'] = explode(",", $this->arrSql['email_mobile']);
158            $sql_where = "";
159            foreach($this->arrSql['email_mobile'] as $val) {
160                $val = trim($val);
161                //検索条件を含まない
162                if($this->arrSql['not_email_mobileinc'] == '1') {
163                    if($sql_where == "") {
164                        $sql_where .= "dtb_customer.email_mobile NOT ILIKE ? ";
165                    } else {
166                        $sql_where .= "AND dtb_customer.email_mobile NOT ILIKE ? ";
167                    }
168                } else {
169                    if($sql_where == "") {
170                        $sql_where .= "dtb_customer.email_mobile ILIKE ? ";
171                    } else {
172                        $sql_where .= "OR dtb_customer.email_mobile ILIKE ? ";
173                    }
174                }
175                $searchemail_mobile = $this->addSearchStr($val);
176                $this->arrVal[] = $searchemail_mobile;
177            }
178            $this->setWhere($sql_where);
179        }
180
181        // 配信メールアドレス種別
182        if ( $mode == 'magazine' ){
183            $sqlEmailMobileIsEmpty = "(dtb_customer.email_mobile IS NULL OR dtb_customer.email_mobile = '')";
184            if (!isset($this->arrSql['mail_type'])) $this->arrSql['mail_type'] = "";
185            switch ($this->arrSql['mail_type']) {
186                // PCメールアドレス
187                case 1:
188                    $this->setWhere("(dtb_customer.email <> dtb_customer.email_mobile OR $sqlEmailMobileIsEmpty)");
189                    break;
190                // 携帯メールアドレス
191                case 2:
192                    $this->setWhere("NOT $sqlEmailMobileIsEmpty");
193                    break;
194                // PCメールアドレス (携帯メールアドレスを登録している顧客は除外)
195                case 3:
196                    $this->setWhere($sqlEmailMobileIsEmpty);
197                    break;
198                // 携帯メールアドレス (PCメールアドレスを登録している顧客は除外)
199                case 4:
200                    $this->setWhere('dtb_customer.email = dtb_customer.email_mobile');
201                    break;
202            }
203        }
204
205        // HTML-mail
206        if ( $mode == 'magazine' ){
207            if (!isset($this->arrSql['htmlmail'])) $this->arrSql['htmlmail'] = "";
208            if ( strlen($this->arrSql['htmlmail']) > 0 ) {
209                $this->setWhere( " mailmaga_flg = ? ");
210                $this->arrVal[] = $this->arrSql['htmlmail'];
211            } else {
212                $this->setWhere( " (mailmaga_flg = 1 or mailmaga_flg = 2) ");
213            }
214        }
215
216        // 購入金額指定
217        if (!isset($this->arrSql['buy_total_from'])) $this->arrSql['buy_total_from'] = "";
218        if (!isset($this->arrSql['buy_total_to'])) $this->arrSql['buy_total_to'] = "";
219        if( is_numeric( $this->arrSql["buy_total_from"] ) || is_numeric( $this->arrSql["buy_total_to"] ) ) {
220            $arrBuyTotal = $this->selectRange($this->arrSql["buy_total_from"], $this->arrSql["buy_total_to"], "buy_total");
221            foreach ($arrBuyTotal as $data1) {
222                $this->arrVal[] = $data1;
223            }
224        }
225
226        // 購入回数指定
227        if (!isset($this->arrSql['buy_times_from'])) $this->arrSql['buy_times_from'] = "";
228        if (!isset($this->arrSql['buy_times_to'])) $this->arrSql['buy_times_to'] = "";
229        if( is_numeric( $this->arrSql["buy_times_from"] ) || is_numeric( $this->arrSql["buy_times_to"] ) ) {
230            $arrBuyTimes = $this->selectRange($this->arrSql["buy_times_from"], $this->arrSql["buy_times_to"], "buy_times");
231            foreach ($arrBuyTimes as $data2) {
232                $this->arrVal[] = $data2;
233            }
234        }
235
236        // 誕生日期間指定
237        if (!isset($this->arrSql['b_start_year'])) $this->arrSql['b_start_year'] = "";
238        if (!isset($this->arrSql['b_start_month'])) $this->arrSql['b_start_month'] = "";
239        if (!isset($this->arrSql['b_start_day'])) $this->arrSql['b_start_day'] = "";
240        if (!isset($this->arrSql['b_end_year'])) $this->arrSql['b_end_year'] = "";
241        if (!isset($this->arrSql['b_end_month'])) $this->arrSql['b_end_month'] = "";
242        if (!isset($this->arrSql['b_end_day'])) $this->arrSql['b_end_day'] = "";
243        if ( (strlen($this->arrSql['b_start_year']) > 0 && strlen($this->arrSql['b_start_month']) > 0 && strlen($this->arrSql['b_start_day']) > 0) ||
244              strlen($this->arrSql['b_end_year']) > 0 && strlen($this->arrSql['b_end_month']) > 0 && strlen($this->arrSql['b_end_day']) > 0) {
245
246            $arrBirth = $this->selectTermRange($this->arrSql['b_start_year'], $this->arrSql['b_start_month'], $this->arrSql['b_start_day']
247                      , $this->arrSql['b_end_year'], $this->arrSql['b_end_month'], $this->arrSql['b_end_day'], "birth");
248            if (is_array($arrBirth)) {
249                foreach ($arrBirth as $data3) {
250                    $this->arrVal[] = $data3;
251                }
252            }
253        }
254
255        // 誕生月の検索
256        if (!isset($this->arrSql['birth_month'])) $this->arrSql['birth_month'] = "";
257        if (is_numeric($this->arrSql["birth_month"])) {
258            $this->setWhere(" EXTRACT(month from birth) = ?");
259            $this->arrVal[] = $this->arrSql["birth_month"];
260        }
261
262        // 登録期間指定
263        if (!isset($this->arrSql['start_year'])) $this->arrSql['start_year'] = "";
264        if (!isset($this->arrSql['start_month'])) $this->arrSql['start_month'] = "";
265        if (!isset($this->arrSql['start_day'])) $this->arrSql['start_day'] = "";
266        if (!isset($this->arrSql['end_year'])) $this->arrSql['end_year'] = "";
267        if (!isset($this->arrSql['end_month'])) $this->arrSql['end_month'] = "";
268        if (!isset($this->arrSql['end_day'])) $this->arrSql['end_day'] = "";
269        if ( (strlen($this->arrSql['start_year']) > 0 && strlen($this->arrSql['start_month']) > 0 && strlen($this->arrSql['start_day']) > 0 ) ||
270                (strlen($this->arrSql['end_year']) > 0 && strlen($this->arrSql['end_month']) >0 && strlen($this->arrSql['end_day']) > 0) ) {
271
272            $arrRegistTime = $this->selectTermRange($this->arrSql['start_year'], $this->arrSql['start_month'], $this->arrSql['start_day']
273                            , $this->arrSql['end_year'], $this->arrSql['end_month'], $this->arrSql['end_day'], $regdate_col);
274            if (is_array($arrRegistTime)) {
275                foreach ($arrRegistTime as $data4) {
276                    $this->arrVal[] = $data4;
277                }
278            }
279        }
280
281        // 最終購入日指定
282        if (!isset($this->arrSql['buy_start_year'])) $this->arrSql['buy_start_year'] = "";
283        if (!isset($this->arrSql['buy_start_month'])) $this->arrSql['buy_start_month'] = "";
284        if (!isset($this->arrSql['buy_start_day'])) $this->arrSql['buy_start_day'] = "";
285        if (!isset($this->arrSql['buy_end_year'])) $this->arrSql['buy_end_year'] = "";
286        if (!isset($this->arrSql['buy_end_month'])) $this->arrSql['buy_end_month'] = "";
287        if (!isset($this->arrSql['buy_end_day'])) $this->arrSql['buy_end_day'] = "";
288
289        if ( (strlen($this->arrSql['buy_start_year']) > 0 && strlen($this->arrSql['buy_start_month']) > 0 && strlen($this->arrSql['buy_start_day']) > 0 ) ||
290                (strlen($this->arrSql['buy_end_year']) > 0 && strlen($this->arrSql['buy_end_month']) >0 && strlen($this->arrSql['buy_end_day']) > 0) ) {
291            $arrRegistTime = $this->selectTermRange($this->arrSql['buy_start_year'], $this->arrSql['buy_start_month'], $this->arrSql['buy_start_day']
292                            , $this->arrSql['buy_end_year'], $this->arrSql['buy_end_month'], $this->arrSql['buy_end_day'], "last_buy_date");
293            if (is_array($arrRegistTime)) {
294                foreach ($arrRegistTime as $data4) {
295                    $this->arrVal[] = $data4;
296                }
297            }
298        }
299
300        // 購入商品コード
301        if (!isset($this->arrSql['buy_product_code'])) $this->arrSql['buy_product_code'] = "";
302        if ( strlen($this->arrSql['buy_product_code']) > 0 ) {
303            $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 ? ))");
304            $search_buyproduct_code = $this->addSearchStr($this->arrSql['buy_product_code']);
305            $this->arrVal[] = $search_buyproduct_code;
306        }
307
308        // 購入商品名称
309        if (!isset($this->arrSql['buy_product_name'])) $this->arrSql['buy_product_name'] = "";
310        if ( strlen($this->arrSql['buy_product_name']) > 0 ) {
311            $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 ? ))");
312            $search_buyproduct_name = $this->addSearchStr($this->arrSql['buy_product_name']);
313            $this->arrVal[] = $search_buyproduct_name;
314        }
315
316        // カテゴリーを選択している場合のみ絞込検索を行う
317        if (!isset($this->arrSql['category_id'])) $this->arrSql['category_id'] = "";
318        if ( strlen($this->arrSql['category_id']) > 0){
319            // カテゴリーで絞込検索を行うSQL文生成
320            list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['category_id']);
321
322            // カテゴリーで絞込みが可能の場合
323            if($tmp_where != "") {
324                $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." ))) ");
325                $this->arrVal = array_merge((array)$this->arrVal, (array)$tmp_arrval);
326            }
327        }
328        // 携帯電話番号
329        if (!isset($this->arrSql['cell'])) $this->arrSql['cell'] = "";
330        if ( is_numeric( $this->arrSql['cell'] ) ) {
331            $this->setWhere( "(cell01 || cell02 || cell03 LIKE ?)" );
332            $searchTel = $this->addSearchStr($this->arrSql['cell']);
333            $this->arrVal[] = ereg_replace("-", "", $searchTel);
334        }
335
336        // 会員状態
337        if (!isset($this->arrSql['status'])) $this->arrSql['status'] = "";
338        if ( is_array( $this->arrSql['status'] ) ){
339            $arrStatusVal = $this->setItemTerm( $this->arrSql['status'] ,"status" );
340            foreach ($arrStatusVal as $data) {
341                $this->arrVal[] = $data;
342            }
343        }
344
345        $this->setOrder( "customer_id DESC" );
346    }
347
348    // 検索用SQL
349    function getList() {
350        $this->select = "SELECT customer_id,name01,name02,kana01,kana02,sex,email,tel01,tel02,tel03,pref,status FROM dtb_customer ";
351        return $this->getSql(0);
352    }
353
354    function getListMailMagazine($is_mobile = false) {
355
356        $colomn = $this->getMailMagazineColumn($is_mobile);
357        $this->select = "
358            SELECT
359                $colomn
360            FROM
361                dtb_customer";
362        return $this->getSql(0);
363    }
364
365    function getMailMagazineColumn($is_mobile= false) {
366        if($is_mobile == true) {
367            $email_column = "dtb_customer.email_mobile as email";
368        } else {
369            $email_column = "dtb_customer.email";
370        }
371
372        $column ="dtb_customer.customer_id,
373                dtb_customer.name01,
374                dtb_customer.name02,
375                dtb_customer.kana01,
376                dtb_customer.kana02,
377                dtb_customer.sex,
378                $email_column,
379                dtb_customer.tel01,
380                dtb_customer.tel02,
381                dtb_customer.tel03,
382                dtb_customer.pref,
383                dtb_customer.create_date,
384                dtb_customer.mailmaga_flg";
385
386        return $column;
387    }
388
389    // 検索総数カウント用SQL
390    function getListCount() {
391        $this->select = "SELECT COUNT(customer_id) FROM dtb_customer ";
392        return $this->getSql(1);
393    }
394
395    // CSVダウンロード用SQL
396    function getListCSV($arrColumnCSV) {
397        $this->arrColumnCSV = $arrColumnCSV;
398        $i = 0;
399        foreach ($this->arrColumnCSV as $val) {
400            if ($i != 0) $state .= ", ";
401            $state .= $val["sql"];
402            $i ++;
403        }
404
405        $this->select = "SELECT " .$state. " FROM dtb_customer ";
406        return $this->getSql(2);
407    }
408
409    function getWhere() {
410        return array($this->where, $this->arrVal);
411    }
412}
413?>
Note: See TracBrowser for help on using the repository browser.