source: branches/version-2/data/class/SC_CustomerList.php @ 17218

Revision 17218, 18.4 KB checked in by satou, 15 years ago (diff)

#267 【管理画面>メルマガ管理>配信内容設定】検索一覧に登録日が表示されない不具合を改修。

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