1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2010 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 | /** |
---|
25 | * 会員情報の登録・編集・検索ヘルパークラス. |
---|
26 | * |
---|
27 | * |
---|
28 | * @package Helper |
---|
29 | * @author Hirokazu Fukuda |
---|
30 | * @version $Id$ |
---|
31 | */ |
---|
32 | class SC_Helper_Customer { |
---|
33 | |
---|
34 | |
---|
35 | /** |
---|
36 | * 会員編集登録処理を行う. |
---|
37 | * |
---|
38 | * @param array $array パラメータの配列 |
---|
39 | * @param array $arrRegistColumn 登録するカラムの配列 |
---|
40 | * @return void |
---|
41 | * @deprecated |
---|
42 | * @todo sfEditCustomerData に統一。LC_Page_Admin_Customer_Edit から呼び出されているだけ |
---|
43 | */ |
---|
44 | function sfEditCustomerDataAdmin($array, $arrRegistColumn) { |
---|
45 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
46 | |
---|
47 | foreach ($arrRegistColumn as $data) { |
---|
48 | if ($data["column"] != "password" && $data["column"] != "reminder_answer" ) { |
---|
49 | if($array[ $data['column'] ] != "") { |
---|
50 | $arrRegist[ $data["column"] ] = $array[ $data["column"] ]; |
---|
51 | } else { |
---|
52 | $arrRegist[ $data['column'] ] = NULL; |
---|
53 | } |
---|
54 | } |
---|
55 | } |
---|
56 | if (strlen($array["year"]) > 0 && strlen($array["month"]) > 0 && strlen($array["day"]) > 0) { |
---|
57 | $arrRegist["birth"] = $array["year"] ."/". $array["month"] ."/". $array["day"] ." 00:00:00"; |
---|
58 | } else { |
---|
59 | $arrRegist["birth"] = NULL; |
---|
60 | } |
---|
61 | |
---|
62 | //-- パスワードの更新がある場合は暗号化。(更新がない場合はUPDATE文を構成しない) |
---|
63 | $salt = ""; |
---|
64 | if ($array["password"] != DEFAULT_PASSWORD) { |
---|
65 | $salt = SC_Utils_Ex::sfGetRandomString(10); |
---|
66 | $arrRegist["salt"] = $salt; |
---|
67 | $arrRegist["password"] = SC_Utils_Ex::sfGetHashString($array["password"], $salt); |
---|
68 | } |
---|
69 | if ($array["reminder_answer"] != DEFAULT_PASSWORD) { |
---|
70 | if($salt == "") { |
---|
71 | $salt = $objQuery->get("salt", "dtb_customer", "customer_id = ? ", array($array['customer_id'])); |
---|
72 | } |
---|
73 | $arrRegist["reminder_answer"] = SC_Utils_Ex::sfGetHashString($array["reminder_answer"], $salt); |
---|
74 | } |
---|
75 | |
---|
76 | $arrRegist["update_date"] = "NOW()"; |
---|
77 | |
---|
78 | //-- 編集登録実行 |
---|
79 | $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); |
---|
80 | } |
---|
81 | |
---|
82 | /** |
---|
83 | * 会員編集登録処理を行う. |
---|
84 | * |
---|
85 | * @param array $array 登録するデータの配列(SC_FormParamのgetDbArrayの戻り値) |
---|
86 | * @param array $customer_id nullの場合はinsert, 存在する場合はupdate |
---|
87 | * @access public |
---|
88 | * @return integer 登録編集したユーザーのcustomer_id |
---|
89 | */ |
---|
90 | function sfEditCustomerData($array, $customer_id = null) { |
---|
91 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
92 | |
---|
93 | $array["update_date"] = "now()"; // 更新日 |
---|
94 | |
---|
95 | // salt値の生成(insert時)または取得(update時)。 |
---|
96 | if(is_numeric($customer_id)) { |
---|
97 | $salt = $objQuery->get("salt", "dtb_customer", "customer_id = ? ", array($customer_id)); |
---|
98 | }else{ |
---|
99 | $salt = SC_Utils_Ex::sfGetRandomString(10); |
---|
100 | $array["salt"] = $salt; |
---|
101 | } |
---|
102 | //-- パスワードの更新がある場合は暗号化 |
---|
103 | if ($array["password"] == DEFAULT_PASSWORD or $array["password"] == "") { |
---|
104 | //更新しない |
---|
105 | unset($array["password"]); |
---|
106 | } else { |
---|
107 | $array["password"] = SC_Utils_Ex::sfGetHashString($array["password"], $salt); |
---|
108 | } |
---|
109 | //-- 秘密の質問の更新がある場合は暗号化 |
---|
110 | if ($array["reminder_answer"] == DEFAULT_PASSWORD or $array["reminder_answer"] == "") { |
---|
111 | //更新しない |
---|
112 | unset($array["reminder_answer"]); |
---|
113 | } else { |
---|
114 | $array["reminder_answer"] = SC_Utils_Ex::sfGetHashString($array["reminder_answer"], $salt); |
---|
115 | } |
---|
116 | |
---|
117 | //-- 編集登録実行 |
---|
118 | if (is_numeric($customer_id)){ |
---|
119 | // 編集 |
---|
120 | $objQuery->update("dtb_customer", $array, "customer_id = ? ", array($customer_id)); |
---|
121 | } else { |
---|
122 | // 新規登録 |
---|
123 | |
---|
124 | // 会員ID |
---|
125 | $customer_id = $objQuery->nextVal('dtb_customer_customer_id'); |
---|
126 | if (is_null($array["customer_id"])){ |
---|
127 | $array['customer_id'] = $customer_id; |
---|
128 | } |
---|
129 | // 作成日 |
---|
130 | if (is_null($array["create_date"])){ |
---|
131 | $array["create_date"] = "now()"; |
---|
132 | } |
---|
133 | $objQuery->insert("dtb_customer", $array); |
---|
134 | } |
---|
135 | return $customer_id; |
---|
136 | } |
---|
137 | |
---|
138 | /** |
---|
139 | * 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
---|
140 | * |
---|
141 | * @param integer $order_id 注文番号 |
---|
142 | * @param integer $use_point 利用ポイント |
---|
143 | * @param integer $add_point 加算ポイント |
---|
144 | * @return array 最終ポイントの配列 |
---|
145 | */ |
---|
146 | function sfGetCustomerPoint($order_id, $use_point, $add_point) { |
---|
147 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
148 | $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); |
---|
149 | $customer_id = $arrRet[0]['customer_id']; |
---|
150 | if ($customer_id != "" && $customer_id >= 1) { |
---|
151 | if (USE_POINT !== false) { |
---|
152 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
---|
153 | $point = $arrRet[0]['point']; |
---|
154 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
---|
155 | } else { |
---|
156 | $total_point = 0; |
---|
157 | $point = 0; |
---|
158 | } |
---|
159 | } else { |
---|
160 | $total_point = ""; |
---|
161 | $point = ""; |
---|
162 | } |
---|
163 | return array($point, $total_point); |
---|
164 | } |
---|
165 | |
---|
166 | /** |
---|
167 | * emailアドレスから、登録済み会員や退会済み会員をチェックする |
---|
168 | * |
---|
169 | * @param string $email メールアドレス |
---|
170 | * @return integer 0:登録可能 1:登録済み 2:再登録制限期間内削除ユーザー 3:自分のアドレス |
---|
171 | */ |
---|
172 | function sfCheckRegisterUserFromEmail($email){ |
---|
173 | $return = 0; |
---|
174 | |
---|
175 | $objCustomer = new SC_Customer(); |
---|
176 | $objQuery =& SC_Query::getSingletonInstance(); |
---|
177 | |
---|
178 | $arrRet = $objQuery->select("email, update_date, del_flg", |
---|
179 | "dtb_customer", |
---|
180 | "email = ? OR email_mobile = ? ORDER BY del_flg", |
---|
181 | array($email, $email)); |
---|
182 | |
---|
183 | if(count($arrRet) > 0) { |
---|
184 | if($arrRet[0]['del_flg'] != '1') { |
---|
185 | // 会員である場合 |
---|
186 | $return = 1; |
---|
187 | } else { |
---|
188 | // 退会した会員である場合 |
---|
189 | $leave_time = SC_Utils_Ex::sfDBDatetoTime($arrRet[0]['update_date']); |
---|
190 | $now_time = time(); |
---|
191 | $pass_time = $now_time - $leave_time; |
---|
192 | // 退会から何時間-経過しているか判定する。 |
---|
193 | $limit_time = ENTRY_LIMIT_HOUR * 3600; |
---|
194 | if($pass_time < $limit_time) { |
---|
195 | $return = 2; |
---|
196 | } |
---|
197 | } |
---|
198 | } |
---|
199 | |
---|
200 | // ログインしている場合、すでに登録している自分のemailの場合はエラーを返さない |
---|
201 | if ($objCustomer->getValue('customer_id')){ |
---|
202 | $arrRet = $objQuery->select("email, email_mobile", |
---|
203 | "dtb_customer", |
---|
204 | "customer_id = ? ORDER BY del_flg", |
---|
205 | array($objCustomer->getValue('customer_id'))); |
---|
206 | |
---|
207 | if ($email == $arrRet[0]["email"] || $email == $arrRet[0]["email_mobile"]) { |
---|
208 | $return = 3; |
---|
209 | } |
---|
210 | } |
---|
211 | return $return; |
---|
212 | } |
---|
213 | |
---|
214 | |
---|
215 | /** |
---|
216 | * sfGetUniqSecretKey |
---|
217 | * |
---|
218 | * 重複しない会員登録キーを発行する。 |
---|
219 | * |
---|
220 | * @access public |
---|
221 | * @return void |
---|
222 | */ |
---|
223 | function sfGetUniqSecretKey() { |
---|
224 | $objQuery = new SC_Query(); |
---|
225 | $count = 1; |
---|
226 | while ($count != 0) { |
---|
227 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("r"); |
---|
228 | $count = $objQuery->count("dtb_customer", "secret_key = ?", array($uniqid)); |
---|
229 | } |
---|
230 | return $uniqid; |
---|
231 | } |
---|
232 | } |
---|