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

Revision 16309, 17.6 KB checked in by naka, 17 years ago (diff)

メルマガ管理でPC用アドレスを検索した時に、
モバイルドメインを含めない

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