source: branches/version-2_13-dev/data/class/SC_CustomerList.php @ 23620

Revision 23620, 18.2 KB checked in by miyamura, 10 years ago (diff)

#2622 メルマガ拒否している会員にも、重要なお知らせはメール配信できるようにする

  • 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-2014 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_Ex
28{
29    public $arrColumnCSV;
30
31    public function __construct($array, $mode = '')
32    {
33        parent::__construct($array);
34
35        $objDb = new SC_Helper_DB_Ex();
36        $dbFactory = SC_DB_DBFactory_Ex::getInstance();
37
38        if ($mode == '') {
39            // 会員本登録会員で削除していない会員
40            $this->setWhere('status = 2 AND del_flg = 0 ');
41            // 登録日を示すカラム
42            $regdate_col = 'dtb_customer.update_date';
43        }
44
45        if ($mode == 'customer') {
46            $this->setWhere(' del_flg = 0 ');
47            // 登録日を示すカラム
48            $regdate_col = 'dtb_customer.update_date';
49        }
50
51        // 会員ID
52        if (!isset($this->arrSql['search_customer_id'])) $this->arrSql['search_customer_id'] = '';
53        if (strlen($this->arrSql['search_customer_id']) > 0) {
54            $this->setWhere('customer_id =  ?');
55            $this->arrVal[] = $this->arrSql['search_customer_id'];
56        }
57
58        // 名前
59        if (!isset($this->arrSql['search_name'])) $this->arrSql['search_name'] = '';
60        if (strlen($this->arrSql['search_name']) > 0) {
61            $this->setWhere('(' . $dbFactory->concatColumn(array('name01', 'name02')) . ' LIKE ?)');
62            $searchName = $this->addSearchStr($this->arrSql['search_name']);
63            $this->arrVal[] = preg_replace('/[  ]+/u', '', $searchName);
64        }
65
66        // 名前(フリガナ)
67        if (!isset($this->arrSql['search_kana'])) $this->arrSql['search_kana'] = '';
68        if (strlen($this->arrSql['search_kana']) > 0) {
69            $this->setWhere('(' . $dbFactory->concatColumn(array('kana01', 'kana02')) . ' LIKE ?)');
70            $searchKana = $this->addSearchStr($this->arrSql['search_kana']);
71            $this->arrVal[] = preg_replace('/[  ]+/u', '', $searchKana);
72        }
73
74        // 都道府県
75        if (!isset($this->arrSql['search_pref'])) $this->arrSql['search_pref'] = '';
76        if (strlen($this->arrSql['search_pref']) > 0) {
77            $this->setWhere('pref = ?');
78            $this->arrVal[] = $this->arrSql['search_pref'];
79        }
80
81        // 電話番号
82        if (!isset($this->arrSql['search_tel'])) $this->arrSql['search_tel'] = '';
83        if (is_numeric($this->arrSql['search_tel'])) {
84            $this->setWhere('(' . $dbFactory->concatColumn(array('tel01', 'tel02', 'tel03')) . ' LIKE ?)');
85            $searchTel = $this->addSearchStr($this->arrSql['search_tel']);
86            $this->arrVal[] = str_replace('-', '', $searchTel);
87        }
88
89        // 性別
90        if (!isset($this->arrSql['search_sex'])) $this->arrSql['search_sex'] = '';
91        if (is_array($this->arrSql['search_sex'])) {
92            $arrSexVal = $this->setItemTerm($this->arrSql['search_sex'], 'sex');
93            foreach ($arrSexVal as $data) {
94                $this->arrVal[] = $data;
95            }
96        }
97
98        // 職業
99        if (!isset($this->arrSql['search_job'])) $this->arrSql['search_job'] = '';
100        if (is_array($this->arrSql['search_job'])) {
101            if (in_array('不明', $this->arrSql['search_job'])) {
102                $arrJobVal = $this->setItemTermWithNull($this->arrSql['search_job'], 'job');
103            } else {
104                $arrJobVal = $this->setItemTerm($this->arrSql['search_job'], 'job');
105            }
106            if (is_array($arrJobVal)) {
107                foreach ($arrJobVal as $data) {
108                    $this->arrVal[] = $data;
109                }
110            }
111        }
112
113        // E-MAIL
114        if (!isset($this->arrSql['search_email'])) $this->arrSql['search_email'] = '';
115        if (strlen($this->arrSql['search_email']) > 0) {
116            //カンマ区切りで複数の条件指定可能に
117            $this->arrSql['search_email'] = explode(',', $this->arrSql['search_email']);
118            $sql_where = '';
119            foreach ($this->arrSql['search_email'] as $val) {
120                $val = trim($val);
121                //検索条件を含まない
122                if ($this->arrSql['not_emailinc'] == '1') {
123                    if ($sql_where == '') {
124                        $sql_where .= 'dtb_customer.email NOT ILIKE ? ';
125                    } else {
126                        $sql_where .= 'AND dtb_customer.email NOT ILIKE ? ';
127                    }
128                } else {
129                    if ($sql_where == '') {
130                        $sql_where .= 'dtb_customer.email ILIKE ? ';
131                    } else {
132                        $sql_where .= 'OR dtb_customer.email ILIKE ? ';
133                    }
134                }
135                $searchEmail = $this->addSearchStr($val);
136                $this->arrVal[] = $searchEmail;
137            }
138            $this->setWhere($sql_where);
139        }
140
141        // E-MAIL(mobile)
142        if (!isset($this->arrSql['search_email_mobile'])) $this->arrSql['search_email_mobile'] = '';
143
144        if (strlen($this->arrSql['search_email_mobile']) > 0) {
145            //カンマ区切りで複数の条件指定可能に
146            $this->arrSql['search_email_mobile'] = explode(',', $this->arrSql['search_email_mobile']);
147            $sql_where = '';
148            foreach ($this->arrSql['search_email_mobile'] as $val) {
149                $val = trim($val);
150                //検索条件を含まない
151                if ($this->arrSql['not_email_mobileinc'] == '1') {
152                    if ($sql_where == '') {
153                        $sql_where .= 'dtb_customer.email_mobile NOT ILIKE ? ';
154                    } else {
155                        $sql_where .= 'AND dtb_customer.email_mobile NOT ILIKE ? ';
156                    }
157                } else {
158                    if ($sql_where == '') {
159                        $sql_where .= 'dtb_customer.email_mobile ILIKE ? ';
160                    } else {
161                        $sql_where .= 'OR dtb_customer.email_mobile ILIKE ? ';
162                    }
163                }
164                $searchemail_mobile = $this->addSearchStr($val);
165                $this->arrVal[] = $searchemail_mobile;
166            }
167            $this->setWhere($sql_where);
168        }
169
170        // メールマガジンの場合
171        if ($mode == 'customer') {
172            // メルマガ受け取りの選択項目がフォームに存在する場合
173            if (isset($this->arrSql['search_htmlmail'])) {
174                $this->setWhere('status = 2');
175                if (SC_Utils_Ex::sfIsInt($this->arrSql['search_htmlmail'])) {
176                    // メルマガ拒否している会員も含む場合は、条件を付加しない
177                    if ($this->arrSql['search_htmlmail'] != 99) {
178                        $this->setWhere('mailmaga_flg = ?');
179                        $this->arrVal[] = $this->arrSql['search_htmlmail'];
180                    }
181                } else {
182                    // メルマガ購読拒否は省く
183                    $this->setWhere('mailmaga_flg <> 3');
184                }
185            }
186        }
187
188        // 配信メールアドレス種別
189        if ($mode == 'customer') {
190            if (isset($this->arrSql['search_mail_type'])) {
191                $sqlEmailMobileIsEmpty = "(dtb_customer.email_mobile IS NULL OR dtb_customer.email_mobile = '')";
192                switch ($this->arrSql['search_mail_type']) {
193                    // PCメールアドレス
194                    case 1:
195                        $this->setWhere("(dtb_customer.email <> dtb_customer.email_mobile OR $sqlEmailMobileIsEmpty)");
196                        break;
197                    // 携帯メールアドレス
198                    case 2:
199                        $this->setWhere("NOT $sqlEmailMobileIsEmpty");
200                        break;
201                    // PCメールアドレス (携帯メールアドレスを登録している会員は除外)
202                    case 3:
203                        $this->setWhere($sqlEmailMobileIsEmpty);
204                        break;
205                    // 携帯メールアドレス (PCメールアドレスを登録している会員は除外)
206                    case 4:
207                        $this->setWhere('dtb_customer.email = dtb_customer.email_mobile');
208                        break;
209                }
210            }
211        }
212
213        // 購入金額指定
214        if (!isset($this->arrSql['search_buy_total_from'])) $this->arrSql['search_buy_total_from'] = '';
215        if (!isset($this->arrSql['search_buy_total_to'])) $this->arrSql['search_buy_total_to'] = '';
216        if (is_numeric($this->arrSql['search_buy_total_from']) || is_numeric($this->arrSql['search_buy_total_to'])) {
217            $arrBuyTotal = $this->selectRange($this->arrSql['search_buy_total_from'], $this->arrSql['search_buy_total_to'], 'buy_total');
218            foreach ($arrBuyTotal as $data) {
219                $this->arrVal[] = $data;
220            }
221        }
222
223        // 購入回数指定
224        if (!isset($this->arrSql['search_buy_times_from'])) $this->arrSql['search_buy_times_from'] = '';
225        if (!isset($this->arrSql['search_buy_times_to'])) $this->arrSql['search_buy_times_to'] = '';
226        if (is_numeric($this->arrSql['search_buy_times_from']) || is_numeric($this->arrSql['search_buy_times_to'])) {
227            $arrBuyTimes = $this->selectRange($this->arrSql['search_buy_times_from'], $this->arrSql['search_buy_times_to'], 'buy_times');
228            foreach ($arrBuyTimes as $data) {
229                $this->arrVal[] = $data;
230            }
231        }
232
233        // 誕生日期間指定
234        if (!isset($this->arrSql['search_b_start_year'])) $this->arrSql['search_b_start_year'] = '';
235        if (!isset($this->arrSql['search_b_start_month'])) $this->arrSql['search_b_start_month'] = '';
236        if (!isset($this->arrSql['search_b_start_day'])) $this->arrSql['search_b_start_day'] = '';
237        if (!isset($this->arrSql['search_b_end_year'])) $this->arrSql['search_b_end_year'] = '';
238        if (!isset($this->arrSql['search_b_end_month'])) $this->arrSql['search_b_end_month'] = '';
239        if (!isset($this->arrSql['search_b_end_day'])) $this->arrSql['search_b_end_day'] = '';
240        if ((strlen($this->arrSql['search_b_start_year']) > 0 && strlen($this->arrSql['search_b_start_month']) > 0 && strlen($this->arrSql['search_b_start_day']) > 0)
241            || strlen($this->arrSql['search_b_end_year']) > 0 && strlen($this->arrSql['search_b_end_month']) > 0 && strlen($this->arrSql['search_b_end_day']) > 0) {
242            $arrBirth = $this->selectTermRange($this->arrSql['search_b_start_year'], $this->arrSql['search_b_start_month'], $this->arrSql['search_b_start_day'],
243                                               $this->arrSql['search_b_end_year'], $this->arrSql['search_b_end_month'], $this->arrSql['search_b_end_day'], 'birth');
244            foreach ($arrBirth as $data) {
245                $this->arrVal[] = $data;
246            }
247        }
248
249        // 誕生月の検索
250        if (!isset($this->arrSql['search_birth_month'])) $this->arrSql['search_birth_month'] = '';
251        if (is_numeric($this->arrSql['search_birth_month'])) {
252            $this->setWhere(' EXTRACT(month from birth) = ?');
253            $this->arrVal[] = $this->arrSql['search_birth_month'];
254        }
255
256        // 登録期間指定
257        if (!isset($this->arrSql['search_start_year'])) $this->arrSql['search_start_year'] = '';
258        if (!isset($this->arrSql['search_start_month'])) $this->arrSql['search_start_month'] = '';
259        if (!isset($this->arrSql['search_start_day'])) $this->arrSql['search_start_day'] = '';
260        if (!isset($this->arrSql['search_end_year'])) $this->arrSql['search_end_year'] = '';
261        if (!isset($this->arrSql['search_end_month'])) $this->arrSql['search_end_month'] = '';
262        if (!isset($this->arrSql['search_end_day'])) $this->arrSql['search_end_day'] = '';
263        if ( (strlen($this->arrSql['search_start_year']) > 0 && strlen($this->arrSql['search_start_month']) > 0 && strlen($this->arrSql['search_start_day']) > 0) ||
264                (strlen($this->arrSql['search_end_year']) > 0 && strlen($this->arrSql['search_end_month']) >0 && strlen($this->arrSql['search_end_day']) > 0)) {
265            $arrRegistTime = $this->selectTermRange($this->arrSql['search_start_year'], $this->arrSql['search_start_month'], $this->arrSql['search_start_day'],
266                            $this->arrSql['search_end_year'], $this->arrSql['search_end_month'], $this->arrSql['search_end_day'], $regdate_col);
267            foreach ($arrRegistTime as $data) {
268                $this->arrVal[] = $data;
269            }
270        }
271
272        // 最終購入日指定
273        if (!isset($this->arrSql['search_buy_start_year'])) $this->arrSql['search_buy_start_year'] = '';
274        if (!isset($this->arrSql['search_buy_start_month'])) $this->arrSql['search_buy_start_month'] = '';
275        if (!isset($this->arrSql['search_buy_start_day'])) $this->arrSql['search_buy_start_day'] = '';
276        if (!isset($this->arrSql['search_buy_end_year'])) $this->arrSql['search_buy_end_year'] = '';
277        if (!isset($this->arrSql['search_buy_end_month'])) $this->arrSql['search_buy_end_month'] = '';
278        if (!isset($this->arrSql['search_buy_end_day'])) $this->arrSql['search_buy_end_day'] = '';
279
280        if ( (strlen($this->arrSql['search_buy_start_year']) > 0 && strlen($this->arrSql['search_buy_start_month']) > 0 && strlen($this->arrSql['search_buy_start_day']) > 0) ||
281                (strlen($this->arrSql['search_buy_end_year']) > 0 && strlen($this->arrSql['search_buy_end_month']) >0 && strlen($this->arrSql['search_buy_end_day']) > 0)) {
282            $arrRegistTime = $this->selectTermRange($this->arrSql['search_buy_start_year'], $this->arrSql['search_buy_start_month'], $this->arrSql['search_buy_start_day'],
283                            $this->arrSql['search_buy_end_year'], $this->arrSql['search_buy_end_month'], $this->arrSql['search_buy_end_day'], 'last_buy_date');
284            foreach ($arrRegistTime as $data) {
285                $this->arrVal[] = $data;
286            }
287        }
288
289        // 購入商品コード
290        if (!isset($this->arrSql['search_buy_product_code'])) $this->arrSql['search_buy_product_code'] = '';
291        if (strlen($this->arrSql['search_buy_product_code']) > 0) {
292            $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 ?) AND del_flg = 0)');
293            $search_buyproduct_code = $this->addSearchStr($this->arrSql['search_buy_product_code']);
294            $this->arrVal[] = $search_buyproduct_code;
295        }
296
297        // 購入商品名称
298        if (!isset($this->arrSql['search_buy_product_name'])) $this->arrSql['search_buy_product_name'] = '';
299        if (strlen($this->arrSql['search_buy_product_name']) > 0) {
300            $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 ?) AND del_flg = 0)');
301            $search_buyproduct_name = $this->addSearchStr($this->arrSql['search_buy_product_name']);
302            $this->arrVal[] = $search_buyproduct_name;
303        }
304
305        // カテゴリを選択している場合のみ絞込検索を行う
306        if (!isset($this->arrSql['search_category_id'])) $this->arrSql['search_category_id'] = '';
307        if (strlen($this->arrSql['search_category_id']) > 0) {
308            // カテゴリで絞込検索を行うSQL文生成
309            list($tmp_where, $tmp_arrval) = $objDb->sfGetCatWhere($this->arrSql['search_category_id']);
310
311            // カテゴリで絞込みが可能の場合
312            if ($tmp_where != '') {
313                $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.') AND del_flg = 0)) ');
314                $this->arrVal = array_merge((array) $this->arrVal, (array) $tmp_arrval);
315            }
316        }
317
318        // 会員状態
319        if (!isset($this->arrSql['search_status'])) $this->arrSql['search_status'] = '';
320        if (is_array($this->arrSql['search_status'])) {
321            $arrStatusVal = $this->setItemTerm($this->arrSql['search_status'], 'status');
322            foreach ($arrStatusVal as $data) {
323                $this->arrVal[] = $data;
324            }
325        }
326
327        $this->setOrder('customer_id DESC');
328    }
329
330    // 検索用SQL
331    public function getList()
332    {
333        $this->select = 'SELECT customer_id,name01,name02,kana01,kana02,sex,email,email_mobile,tel01,tel02,tel03,pref,status,update_date,mailmaga_flg FROM dtb_customer ';
334
335        return $this->getSql(2);
336    }
337
338    public function getListMailMagazine($is_mobile = false)
339    {
340        $colomn = $this->getMailMagazineColumn($is_mobile);
341        $this->select = "
342            SELECT
343                $colomn
344            FROM
345                dtb_customer";
346
347        return $this->getSql(0);
348    }
349
350    // 検索総数カウント用SQL
351    public function getListCount()
352    {
353        $this->select = 'SELECT COUNT(customer_id) FROM dtb_customer ';
354
355        return $this->getSql(1);
356    }
357
358    // CSVダウンロード用SQL
359    public function getListCSV($arrColumnCSV)
360    {
361        $this->arrColumnCSV = $arrColumnCSV;
362        $i = 0;
363        foreach ($this->arrColumnCSV as $val) {
364            if ($i != 0) $state .= ', ';
365            $state .= $val['sql'];
366            $i ++;
367        }
368
369        $this->select = 'SELECT ' .$state. ' FROM dtb_customer ';
370
371        return $this->getSql(2);
372    }
373
374    public function getWhere()
375    {
376        return array(parent::getWhere(), $this->arrVal);
377    }
378}
Note: See TracBrowser for help on using the repository browser.