source: branches/feature-module-update/data/class/SC_CustomerList.php @ 15642

Revision 15642, 18.1 KB checked in by nanasess, 17 years ago (diff)

未定義変数の修正

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