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

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