source: branches/version-2_12-dev/data/class/SC_Customer.php @ 21684

Revision 21684, 12.5 KB checked in by Seasoft, 12 years ago (diff)

#1613 (typo修正・ソース整形・ソースコメントの改善)

  • 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-2011 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_Customer
25 *  [概要] 会員管理クラス
26 */
27class SC_Customer {
28
29    /** 会員情報 */
30    var $customer_data;
31
32    function SC_Customer() {
33    }
34
35    function getCustomerDataFromEmailPass($pass, $email, $mobile = false) {
36        // 小文字に変換
37        $email = strtolower($email);
38        $sql_mobile = $mobile ? ' OR email_mobile = ?' : '';
39        $arrValues = array($email);
40        if ($mobile) {
41            $arrValues[] = $email;
42        }
43        // 本登録された会員のみ
44        $sql = 'SELECT * FROM dtb_customer WHERE (email = ?' . $sql_mobile . ') AND del_flg = 0 AND status = 2';
45        $objQuery = new SC_Query_Ex();
46        $result = $objQuery->getAll($sql, $arrValues);
47        if (empty($result)) {
48            return false;
49        } else {
50            $data = $result[0];
51        }
52
53        // パスワードが合っていれば会員情報をcustomer_dataにセットしてtrueを返す
54        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt'])) {
55            $this->customer_data = $data;
56            $this->startSession();
57            return true;
58        }
59        return false;
60    }
61
62    /**
63     * 会員の登録住所を取得する.
64     *
65     * 配列の1番目に会員登録住所, 追加登録住所が存在する場合は2番目以降に
66     * 設定される.
67     *
68     * @param integer $customer_id 会員ID
69     * @return array 会員登録住所, 追加登録住所の配列
70     */
71    function getCustomerAddress($customer_id) {
72        $objQuery =& SC_Query_Ex::getSingletonInstance();
73
74        $from = <<< __EOS__
75            (
76                SELECT NULL AS other_deliv_id,
77                    customer_id,
78                    name01, name02,
79                    kana01, kana02,
80                    zip01, zip02,
81                    pref,
82                    addr01, addr02,
83                    email, email_mobile,
84                    tel01, tel02, tel03,
85                    fax01, fax02, fax03
86                FROM dtb_customer
87                WHERE customer_id = ?
88                UNION ALL
89                SELECT other_deliv_id,
90                    customer_id,
91                    name01, name02,
92                    kana01, kana02,
93                    zip01, zip02,
94                    pref,
95                    addr01, addr02,
96                    NULL AS email, NULL AS email_mobile,
97                    tel01, tel02, tel03,
98                    NULL AS fax01, NULL AS fax02, NULL AS fax03
99                FROM dtb_other_deliv
100                WHERE customer_id = ?
101            ) AS addrs
102__EOS__;
103        $objQuery->setOrder('other_deliv_id IS NULL DESC, other_deliv_id DESC');
104        return $objQuery->select('*', $from, '', array($customer_id, $customer_id));
105    }
106
107    /**
108     * 携帯端末IDが一致する会員が存在するかどうかをチェックする。
109     * FIXME
110     * @return boolean 該当する会員が存在する場合は true、それ以外の場合
111     *                 は false を返す。
112     */
113    function checkMobilePhoneId() {
114        //docomo用にデータを取り出す。
115        if (SC_MobileUserAgent_Ex::getCarrier() == 'docomo') {
116            if ($_SESSION['mobile']['phone_id'] == '' && strlen($_SESSION['mobile']['phone_id']) == 0) {
117                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
118            }
119        }
120        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
121            return false;
122        }
123
124        // 携帯端末IDが一致し、本登録された会員を検索する。
125        $objQuery = new SC_Query_Ex();
126        $exists = $objQuery->exists('dtb_customer', 'mobile_phone_id = ? AND del_flg = 0 AND status = 2', array($_SESSION['mobile']['phone_id']));
127        return $exists;
128    }
129
130    /**
131     * 携帯端末IDを使用して会員を検索し、パスワードの照合を行う。
132     * パスワードが合っている場合は会員情報を取得する。
133     *
134     * @param string $pass パスワード
135     * @return boolean 該当する会員が存在し、パスワードが合っている場合は true、
136     *                 それ以外の場合は false を返す。
137     */
138    function getCustomerDataFromMobilePhoneIdPass($pass) {
139        //docomo用にデータを取り出す。
140        if (SC_MobileUserAgent_Ex::getCarrier() == 'docomo') {
141            if ($_SESSION['mobile']['phone_id'] == '' && strlen($_SESSION['mobile']['phone_id']) == 0) {
142                $_SESSION['mobile']['phone_id'] = SC_MobileUserAgent_Ex::getId();
143            }
144        }
145        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
146            return false;
147        }
148
149        // 携帯端末IDが一致し、本登録された会員を検索する。
150        $sql = 'SELECT * FROM dtb_customer WHERE mobile_phone_id = ? AND del_flg = 0 AND status = 2';
151        $objQuery = new SC_Query_Ex();
152        @list($data) = $objQuery->getAll($sql, array($_SESSION['mobile']['phone_id']));
153
154        // パスワードが合っている場合は、会員情報をcustomer_dataに格納してtrueを返す。
155        if (SC_Utils_Ex::sfIsMatchHashPassword($pass, $data['password'], $data['salt'])) {
156            $this->customer_data = $data;
157            $this->startSession();
158            return true;
159        }
160        return false;
161    }
162
163    /**
164     * 携帯端末IDを登録する。
165     *
166     * @return void
167     */
168    function updateMobilePhoneId() {
169        if (!isset($_SESSION['mobile']['phone_id']) || $_SESSION['mobile']['phone_id'] === false) {
170            return;
171        }
172
173        if ($this->customer_data['mobile_phone_id'] == $_SESSION['mobile']['phone_id']) {
174            return;
175        }
176
177        $objQuery = new SC_Query_Ex();
178        $sqlval = array('mobile_phone_id' => $_SESSION['mobile']['phone_id']);
179        $where = 'customer_id = ? AND del_flg = 0 AND status = 2';
180        $objQuery->update('dtb_customer', $sqlval, $where, array($this->customer_data['customer_id']));
181
182        $this->customer_data['mobile_phone_id'] = $_SESSION['mobile']['phone_id'];
183    }
184
185    // パスワードを確認せずにログイン
186    function setLogin($email) {
187        // 本登録された会員のみ
188        $sql = 'SELECT * FROM dtb_customer WHERE (email = ? OR email_mobile = ?) AND del_flg = 0 AND status = 2';
189        $objQuery = new SC_Query_Ex();
190        $result = $objQuery->getAll($sql, array($email, $email));
191        $data = isset($result[0]) ? $result[0] : '';
192        $this->customer_data = $data;
193        $this->startSession();
194    }
195
196    // セッション情報を最新の情報に更新する
197    function updateSession() {
198        $sql = 'SELECT * FROM dtb_customer WHERE customer_id = ? AND del_flg = 0';
199        $customer_id = $this->getValue('customer_id');
200        $objQuery = new SC_Query_Ex();
201        $arrRet = $objQuery->getAll($sql, array($customer_id));
202        $this->customer_data = isset($arrRet[0]) ? $arrRet[0] : '';
203        $_SESSION['customer'] = $this->customer_data;
204    }
205
206    // ログイン情報をセッションに登録し、ログに書き込む
207    function startSession() {
208        $_SESSION['customer'] = $this->customer_data;
209        // セッション情報の保存
210        GC_Utils_Ex::gfPrintLog('access : user='.$this->customer_data['customer_id'] ."\t".'ip='. $this->getRemoteHost(), CUSTOMER_LOG_REALFILE, false);
211    }
212
213    // ログアウト $_SESSION['customer']を解放し、ログに書き込む
214    function EndSession() {
215        // $_SESSION['customer']の解放
216        unset($_SESSION['customer']);
217        // セッションの配送情報を全て破棄する
218        SC_Helper_Purchase_Ex::unsetAllShippingTemp(true);
219        // トランザクショントークンの破棄
220        SC_Helper_Session_Ex::destroyToken();
221        $objSiteSess = new SC_SiteSession_Ex();
222        $objSiteSess->unsetUniqId();
223        // ログに記録する
224        GC_Utils_Ex::gfPrintLog('logout : user='.$this->customer_data['customer_id'] ."\t".'ip='. $this->getRemoteHost(), CUSTOMER_LOG_REALFILE, false);
225    }
226
227    // ログインに成功しているか判定する。
228    function isLoginSuccess($dont_check_email_mobile = false) {
229        // ログイン時のメールアドレスとDBのメールアドレスが一致している場合
230        if (isset($_SESSION['customer']['customer_id'])
231            && SC_Utils_Ex::sfIsInt($_SESSION['customer']['customer_id'])
232        ) {
233            $objQuery = new SC_Query_Ex();
234            $email = $objQuery->get('email', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
235            if ($email == $_SESSION['customer']['email']) {
236                // モバイルサイトの場合は携帯のメールアドレスが登録されていることもチェックする。
237                // ただし $dont_check_email_mobile が true の場合はチェックしない。
238                if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE && !$dont_check_email_mobile) {
239                    $email_mobile = $objQuery->get('email_mobile', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
240                    return isset($email_mobile);
241                }
242                return true;
243            }
244        }
245        return false;
246    }
247
248    // パラメーターの取得
249    function getValue($keyname) {
250        // ポイントはリアルタイム表示
251        if ($keyname == 'point') {
252            $objQuery =& SC_Query_Ex::getSingletonInstance();
253            $point = $objQuery->get('point', 'dtb_customer', 'customer_id = ?', array($_SESSION['customer']['customer_id']));
254            $_SESSION['customer']['point'] = $point;
255            return $point;
256        } else {
257            return isset($_SESSION['customer'][$keyname]) ? $_SESSION['customer'][$keyname] : '';
258        }
259    }
260
261    // パラメーターのセット
262    function setValue($keyname, $val) {
263        $_SESSION['customer'][$keyname] = $val;
264    }
265
266    // パラメーターがNULLかどうかの判定
267    function hasValue($keyname) {
268        if (isset($_SESSION['customer'][$keyname])) {
269            return !SC_Utils_Ex::isBlank($_SESSION['customer'][$keyname]);
270        }
271        return false;
272    }
273
274    // 誕生日月であるかどうかの判定
275    function isBirthMonth() {
276        if (isset($_SESSION['customer']['birth'])) {
277            $arrRet = preg_split('|[- :/]|', $_SESSION['customer']['birth']);
278            $birth_month = intval($arrRet[1]);
279            $now_month = intval(date('m'));
280
281            if ($birth_month == $now_month) {
282                return true;
283            }
284        }
285        return false;
286    }
287
288    /**
289     * $_SERVER['REMOTE_HOST'] または $_SERVER['REMOTE_ADDR'] を返す.
290     *
291     * $_SERVER['REMOTE_HOST'] が取得できない場合は $_SERVER['REMOTE_ADDR']
292     * を返す.
293     *
294     * @return string $_SERVER['REMOTE_HOST'] 又は $_SERVER['REMOTE_ADDR']の文字列
295     */
296    function getRemoteHost() {
297
298        if (!empty($_SERVER['REMOTE_HOST'])) {
299            return $_SERVER['REMOTE_HOST'];
300        } elseif (!empty($_SERVER['REMOTE_ADDR'])) {
301            return $_SERVER['REMOTE_ADDR'];
302        } else {
303            return '';
304        }
305    }
306
307    //受注関連の会員情報を更新
308    function updateOrderSummary($customer_id) {
309        $objQuery = new SC_Query_Ex();
310        $arrOrderSummary =  $objQuery->getRow('SUM( payment_total) as buy_total, COUNT(order_id) as buy_times,MAX( create_date) as last_buy_date, MIN(create_date) as first_buy_date','dtb_order','customer_id = ? AND del_flg = 0 AND status <> ?',array($customer_id,ORDER_CANCEL));
311        $objQuery->update('dtb_customer',$arrOrderSummary,'customer_id = ?',array($customer_id));
312    }
313}
Note: See TracBrowser for help on using the repository browser.