| 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") { |
|---|
| 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 | if ($array["password"] != DEFAULT_PASSWORD) $arrRegist["password"] = sha1($array["password"] . ":" . AUTH_MAGIC); |
|---|
| 64 | $arrRegist["update_date"] = "NOW()"; |
|---|
| 65 | |
|---|
| 66 | //-- 編集登録実行 |
|---|
| 67 | $objQuery->update("dtb_customer", $arrRegist, "customer_id = ? ", array($array['customer_id'])); |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | /** |
|---|
| 71 | * 会員編集登録処理を行う. |
|---|
| 72 | * |
|---|
| 73 | * @param array $array 登録するデータの配列(SC_FormParamのgetDbArrayの戻り値) |
|---|
| 74 | * @param array $customer_id nullの場合はinsert, 存在する場合はupdate |
|---|
| 75 | * @access public |
|---|
| 76 | * @return integer 登録編集したユーザーのcustomer_id |
|---|
| 77 | */ |
|---|
| 78 | function sfEditCustomerData($array, $customer_id = null) { |
|---|
| 79 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 80 | |
|---|
| 81 | $array["update_date"] = "now()"; // 更新日 |
|---|
| 82 | |
|---|
| 83 | //-- パスワードの更新がある場合は暗号化 |
|---|
| 84 | if ($array["password"] != DEFAULT_PASSWORD){ |
|---|
| 85 | $array["password"] = sha1($array["password"] . ":" . AUTH_MAGIC); |
|---|
| 86 | } else { |
|---|
| 87 | unset($array["password"]); |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | //-- 編集登録実行 |
|---|
| 91 | if (is_numeric($customer_id)){ |
|---|
| 92 | // 編集 |
|---|
| 93 | $objQuery->update("dtb_customer", $array, "customer_id = ? ", array($customer_id)); |
|---|
| 94 | } else { |
|---|
| 95 | // 新規登録 |
|---|
| 96 | |
|---|
| 97 | // 会員ID |
|---|
| 98 | $customer_id = $objQuery->nextVal('dtb_customer_customer_id'); |
|---|
| 99 | if (is_null($array["customer_id"])){ |
|---|
| 100 | $array['customer_id'] = $customer_id; |
|---|
| 101 | } |
|---|
| 102 | // 作成日 |
|---|
| 103 | if (is_null($array["create_date"])){ |
|---|
| 104 | $array["create_date"] = "now()"; |
|---|
| 105 | } |
|---|
| 106 | $objQuery->insert("dtb_customer", $array); |
|---|
| 107 | } |
|---|
| 108 | return $customer_id; |
|---|
| 109 | } |
|---|
| 110 | |
|---|
| 111 | /** |
|---|
| 112 | * 注文番号、利用ポイント、加算ポイントから最終ポイントを取得する. |
|---|
| 113 | * |
|---|
| 114 | * @param integer $order_id 注文番号 |
|---|
| 115 | * @param integer $use_point 利用ポイント |
|---|
| 116 | * @param integer $add_point 加算ポイント |
|---|
| 117 | * @return array 最終ポイントの配列 |
|---|
| 118 | */ |
|---|
| 119 | function sfGetCustomerPoint($order_id, $use_point, $add_point) { |
|---|
| 120 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 121 | $arrRet = $objQuery->select("customer_id", "dtb_order", "order_id = ?", array($order_id)); |
|---|
| 122 | $customer_id = $arrRet[0]['customer_id']; |
|---|
| 123 | if ($customer_id != "" && $customer_id >= 1) { |
|---|
| 124 | if (USE_POINT !== false) { |
|---|
| 125 | $arrRet = $objQuery->select("point", "dtb_customer", "customer_id = ?", array($customer_id)); |
|---|
| 126 | $point = $arrRet[0]['point']; |
|---|
| 127 | $total_point = $arrRet[0]['point'] - $use_point + $add_point; |
|---|
| 128 | } else { |
|---|
| 129 | $total_point = 0; |
|---|
| 130 | $point = 0; |
|---|
| 131 | } |
|---|
| 132 | } else { |
|---|
| 133 | $total_point = ""; |
|---|
| 134 | $point = ""; |
|---|
| 135 | } |
|---|
| 136 | return array($point, $total_point); |
|---|
| 137 | } |
|---|
| 138 | |
|---|
| 139 | /** |
|---|
| 140 | * emailアドレスから、登録済み会員や退会済み会員をチェックする |
|---|
| 141 | * |
|---|
| 142 | * @param string $email メールアドレス |
|---|
| 143 | * @return integer 0:登録可能 1:登録済み 2:再登録制限期間内削除ユーザー 3:自分のアドレス |
|---|
| 144 | */ |
|---|
| 145 | function lfCheckRegisterUserFromEmail($email){ |
|---|
| 146 | $return = 0; |
|---|
| 147 | |
|---|
| 148 | $objCustomer = new SC_Customer(); |
|---|
| 149 | $objQuery =& SC_Query::getSingletonInstance(); |
|---|
| 150 | |
|---|
| 151 | $arrRet = $objQuery->select("email, update_date, del_flg" |
|---|
| 152 | ,"dtb_customer" |
|---|
| 153 | ,"email = ? OR email_mobile = ? ORDER BY del_flg" |
|---|
| 154 | ,array($email, $email) |
|---|
| 155 | ); |
|---|
| 156 | |
|---|
| 157 | if(count($arrRet) > 0) { |
|---|
| 158 | if($arrRet[0]['del_flg'] != '1') { |
|---|
| 159 | // 会員である場合 |
|---|
| 160 | if (!isset($objErr->arrErr['email'])) $objErr->arrErr['email'] = ""; |
|---|
| 161 | $return = 1; |
|---|
| 162 | } else { |
|---|
| 163 | // 退会した会員である場合 |
|---|
| 164 | $leave_time = SC_Utils_Ex::sfDBDatetoTime($arrRet[0]['update_date']); |
|---|
| 165 | $now_time = time(); |
|---|
| 166 | $pass_time = $now_time - $leave_time; |
|---|
| 167 | // 退会から何時間-経過しているか判定する。 |
|---|
| 168 | $limit_time = ENTRY_LIMIT_HOUR * 3600; |
|---|
| 169 | if($pass_time < $limit_time) { |
|---|
| 170 | if (!isset($objErr->arrErr['email'])) $objErr->arrErr['email'] = ""; |
|---|
| 171 | $return = 2; |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | // ログインしている場合、すでに登録している自分のemailの場合はエラーを返さない |
|---|
| 177 | if ($objCustomer->getValue('customer_id')){ |
|---|
| 178 | $arrRet = $objQuery->select("email, email_mobile" |
|---|
| 179 | ,"dtb_customer" |
|---|
| 180 | ,"customer_id = ? ORDER BY del_flg" |
|---|
| 181 | ,array($objCustomer->getValue('customer_id')) |
|---|
| 182 | ); |
|---|
| 183 | if ($email == $arrRet[0]["email"] |
|---|
| 184 | || $email == $arrRet[0]["email_mobile"]){ |
|---|
| 185 | $return = 3; |
|---|
| 186 | } |
|---|
| 187 | } |
|---|
| 188 | return $return; |
|---|
| 189 | } |
|---|
| 190 | } |
|---|