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

Revision 18701, 19.1 KB checked in by nanasess, 16 years ago (diff)

Copyright の更新(#601)

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