| 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 | // {{{ requires |
|---|
| 25 | require_once(CLASS_PATH . "pages/LC_Page.php"); |
|---|
| 26 | |
|---|
| 27 | /** |
|---|
| 28 | * ご注文完了 のページクラス. |
|---|
| 29 | * |
|---|
| 30 | * @package Page |
|---|
| 31 | * @author LOCKON CO.,LTD. |
|---|
| 32 | * @version $Id:LC_Page_Shopping_Complete.php 15532 2007-08-31 14:39:46Z nanasess $ |
|---|
| 33 | */ |
|---|
| 34 | class LC_Page_Shopping_Complete extends LC_Page { |
|---|
| 35 | |
|---|
| 36 | // }}} |
|---|
| 37 | // {{{ functions |
|---|
| 38 | |
|---|
| 39 | /** |
|---|
| 40 | * Page を初期化する. |
|---|
| 41 | * |
|---|
| 42 | * @return void |
|---|
| 43 | */ |
|---|
| 44 | function init() { |
|---|
| 45 | parent::init(); |
|---|
| 46 | $this->tpl_mainpage = 'shopping/complete.tpl'; |
|---|
| 47 | $this->tpl_title = "ご注文完了"; |
|---|
| 48 | $this->tpl_column_num = 1; |
|---|
| 49 | |
|---|
| 50 | $masterData = new SC_DB_MasterData_Ex(); |
|---|
| 51 | $this->arrCONVENIENCE = $masterData->getMasterData("mtb_convenience"); |
|---|
| 52 | $this->arrCONVENIMESSAGE = $masterData->getMasterData("mtb_conveni_message"); |
|---|
| 53 | |
|---|
| 54 | $this->allowClientCache(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | /** |
|---|
| 58 | * Page のプロセス. |
|---|
| 59 | * |
|---|
| 60 | * @return void |
|---|
| 61 | */ |
|---|
| 62 | function process() { |
|---|
| 63 | global $objCampaignSess; |
|---|
| 64 | |
|---|
| 65 | $conn = new SC_DBConn(); |
|---|
| 66 | $objView = new SC_SiteView(); |
|---|
| 67 | $this->objSiteSess = new SC_SiteSession(); |
|---|
| 68 | $this->objCartSess = new SC_CartSession(); |
|---|
| 69 | $this->objCampaignSess = new SC_CampaignSession(); |
|---|
| 70 | $objSiteInfo = $objView->objSiteInfo; |
|---|
| 71 | $this->arrInfo = $objSiteInfo->data; |
|---|
| 72 | $this->objCustomer = new SC_Customer(); |
|---|
| 73 | $mailHelper = new SC_Helper_Mail_Ex(); |
|---|
| 74 | |
|---|
| 75 | // 前のページで正しく登録手続きが行われたか判定 |
|---|
| 76 | SC_Utils_Ex::sfIsPrePage($this->objSiteSess); |
|---|
| 77 | // ユーザユニークIDの取得と購入状態の正当性をチェック |
|---|
| 78 | $uniqid = SC_Utils_Ex::sfCheckNormalAccess($this->objSiteSess, $this->objCartSess); |
|---|
| 79 | if ($uniqid != "") { |
|---|
| 80 | |
|---|
| 81 | // 完了処理 |
|---|
| 82 | $objQuery = new SC_Query(); |
|---|
| 83 | $objQuery->begin(); |
|---|
| 84 | $order_id = $this->lfDoComplete($objQuery, $uniqid); |
|---|
| 85 | $objQuery->commit(); |
|---|
| 86 | |
|---|
| 87 | // セッションに保管されている情報を更新する |
|---|
| 88 | $this->objCustomer->updateSession(); |
|---|
| 89 | |
|---|
| 90 | // 完了メール送信 |
|---|
| 91 | if($order_id != "") { |
|---|
| 92 | $mailHelper->sfSendOrderMail($order_id, '1'); |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | // その他情報の取得 |
|---|
| 96 | $arrResults = $objQuery->getAll("SELECT memo02, memo05 FROM dtb_order WHERE order_id = ? ", array($order_id)); |
|---|
| 97 | |
|---|
| 98 | if (count($arrResults) > 0) { |
|---|
| 99 | if (isset($arrResults[0]["memo02"]) || isset($arrResults[0]["memo05"])) { |
|---|
| 100 | // 完了画面で表示する決済内容 |
|---|
| 101 | $arrOther = unserialize($arrResults[0]["memo02"]); |
|---|
| 102 | // 完了画面から送信する決済内容 |
|---|
| 103 | $arrModuleParam = unserialize($arrResults[0]["memo05"]); |
|---|
| 104 | |
|---|
| 105 | // データを編集 |
|---|
| 106 | foreach($arrOther as $key => $val){ |
|---|
| 107 | // URLの場合にはリンクつきで表示させる |
|---|
| 108 | if (preg_match('/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $val["value"])) { |
|---|
| 109 | $arrOther[$key]["value"] = "<a href='#' onClick=\"window.open('". $val["value"] . "'); \" >" . $val["value"] ."</a>"; |
|---|
| 110 | } |
|---|
| 111 | } |
|---|
| 112 | |
|---|
| 113 | $this->arrOther = $arrOther; |
|---|
| 114 | $this->arrModuleParam = $arrModuleParam; |
|---|
| 115 | } |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | // アフィリエイト用コンバージョンタグの設定 |
|---|
| 119 | $this->tpl_conv_page = AFF_SHOPPING_COMPLETE; |
|---|
| 120 | $this->tpl_aff_option = "order_id=$order_id"; |
|---|
| 121 | //合計価格の取得 |
|---|
| 122 | $total = $objQuery->get("dtb_order", "total", "order_id = ? ", array($order_id)); |
|---|
| 123 | if($total != "") { |
|---|
| 124 | $this->tpl_aff_option.= "|total=$total"; |
|---|
| 125 | } |
|---|
| 126 | |
|---|
| 127 | // TradeSafe連携用 |
|---|
| 128 | if (function_exists('sfTSRequest')) { |
|---|
| 129 | sfTSRequest($order_id); |
|---|
| 130 | } |
|---|
| 131 | } |
|---|
| 132 | |
|---|
| 133 | // キャンペーンからの遷移かチェック |
|---|
| 134 | $this->is_campaign = $this->objCampaignSess->getIsCampaign(); |
|---|
| 135 | $this->campaign_dir = $this->objCampaignSess->getCampaignDir(); |
|---|
| 136 | |
|---|
| 137 | $objView->assignobj($this); |
|---|
| 138 | // フレームを選択(キャンペーンページから遷移なら変更) |
|---|
| 139 | $this->objCampaignSess->pageView($objView); |
|---|
| 140 | |
|---|
| 141 | // セッション開放 |
|---|
| 142 | $this->objCampaignSess->delCampaign(); |
|---|
| 143 | } |
|---|
| 144 | |
|---|
| 145 | /** |
|---|
| 146 | * デストラクタ. |
|---|
| 147 | * |
|---|
| 148 | * @return void |
|---|
| 149 | */ |
|---|
| 150 | function destroy() { |
|---|
| 151 | parent::destroy(); |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | * モバイルページを初期化する. |
|---|
| 156 | * |
|---|
| 157 | * @return void |
|---|
| 158 | */ |
|---|
| 159 | function mobileInit() { |
|---|
| 160 | $this->init(); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | /** |
|---|
| 164 | * Page のプロセス(モバイル). |
|---|
| 165 | * |
|---|
| 166 | * @return void |
|---|
| 167 | */ |
|---|
| 168 | function mobileProcess() { |
|---|
| 169 | $conn = new SC_DBConn(); |
|---|
| 170 | $objView = new SC_MobileView(); |
|---|
| 171 | $this->objSiteSess = new SC_SiteSession(); |
|---|
| 172 | $this->objCartSess = new SC_CartSession(); |
|---|
| 173 | $objSiteInfo = $objView->objSiteInfo; |
|---|
| 174 | $this->arrInfo = $objSiteInfo->data; |
|---|
| 175 | $this->objCustomer = new SC_Customer(); |
|---|
| 176 | $mailHelper = new SC_Helper_Mail_Ex(); |
|---|
| 177 | |
|---|
| 178 | // 前のページで正しく登録手続きが行われたか判定 |
|---|
| 179 | SC_Utils_Ex::sfIsPrePage($this->objSiteSess, true); |
|---|
| 180 | // ユーザユニークIDの取得と購入状態の正当性をチェック |
|---|
| 181 | $uniqid = SC_Utils_Ex::sfCheckNormalAccess($this->objSiteSess, $this->objCartSess); |
|---|
| 182 | if ($uniqid != "") { |
|---|
| 183 | |
|---|
| 184 | // 完了処理 |
|---|
| 185 | $objQuery = new SC_Query(); |
|---|
| 186 | $objQuery->begin(); |
|---|
| 187 | $order_id = $this->lfDoComplete($objQuery, $uniqid); |
|---|
| 188 | $objQuery->commit(); |
|---|
| 189 | |
|---|
| 190 | // セッションに保管されている情報を更新する |
|---|
| 191 | $this->objCustomer->updateSession(); |
|---|
| 192 | |
|---|
| 193 | // 完了メール送信 |
|---|
| 194 | if($order_id != "") { |
|---|
| 195 | $mailHelper->sfSendOrderMail($order_id, '2'); |
|---|
| 196 | } |
|---|
| 197 | |
|---|
| 198 | //その他情報の取得 |
|---|
| 199 | $other_data = $objQuery->get("dtb_order", "memo02", "order_id = ? ", array($order_id)); |
|---|
| 200 | if($other_data != "") { |
|---|
| 201 | $arrOther = unserialize($other_data); |
|---|
| 202 | |
|---|
| 203 | // データを編集 |
|---|
| 204 | foreach($arrOther as $key => $val){ |
|---|
| 205 | // URLの場合にはリンクつきで表示させる |
|---|
| 206 | if (preg_match('/^(https?|ftp)(:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+)$/', $val["value"])) { |
|---|
| 207 | $arrOther[$key]["value"] = "<a href='". $val["value"]. "'>". $val["value"]. "</a>"; |
|---|
| 208 | } |
|---|
| 209 | } |
|---|
| 210 | |
|---|
| 211 | $this->arrOther = $arrOther; |
|---|
| 212 | |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | // アフィリエイト用コンバージョンタグの設定 |
|---|
| 216 | $this->tpl_conv_page = AFF_SHOPPING_COMPLETE; |
|---|
| 217 | $this->tpl_aff_option = "order_id=$order_id"; |
|---|
| 218 | //合計価格の取得 |
|---|
| 219 | $total = $objQuery->get("dtb_order", "total", "order_id = ? ", array($order_id)); |
|---|
| 220 | if($total != "") { |
|---|
| 221 | $this->tpl_aff_option.= "|total=$total"; |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | // TS連携モジュールの実行 |
|---|
| 225 | if (function_exists('sfTSRequest')) { |
|---|
| 226 | sfTSRequest($order_id); |
|---|
| 227 | } |
|---|
| 228 | } |
|---|
| 229 | |
|---|
| 230 | $objView->assignobj($this); |
|---|
| 231 | $objView->display(SITE_FRAME); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | |
|---|
| 235 | // エビスタグ引渡し用データを生成する |
|---|
| 236 | function lfGetEbisData($order_id) { |
|---|
| 237 | $objQuery = new SC_Query(); |
|---|
| 238 | $col = "customer_id, total, order_sex, order_job, to_number(to_char(age(current_timestamp, order_birth), 'YYY'), 999) AS order_age"; |
|---|
| 239 | $arrRet = $objQuery->select($col, "dtb_order", "order_id = ?", array($order_id)); |
|---|
| 240 | |
|---|
| 241 | if($arrRet[0]['customer_id'] > 0) { |
|---|
| 242 | // 会員番号 |
|---|
| 243 | $arrEbis['m1id'] = $arrRet[0]['customer_id']; |
|---|
| 244 | // 非会員or会員 |
|---|
| 245 | $arrEbis['o5id'] = '1'; |
|---|
| 246 | } else { |
|---|
| 247 | // 会員番号 |
|---|
| 248 | $arrEbis['m1id'] = ''; |
|---|
| 249 | // 非会員or会員 |
|---|
| 250 | $arrEbis['o5id'] = '2'; |
|---|
| 251 | } |
|---|
| 252 | |
|---|
| 253 | // 購入金額 |
|---|
| 254 | $arrEbis['a1id'] = $arrRet[0]['total']; |
|---|
| 255 | // 性別 |
|---|
| 256 | $arrEbis['o2id'] = $arrRet[0]['order_sex']; |
|---|
| 257 | // 年齢 |
|---|
| 258 | $arrEbis['o3id'] = $arrRet[0]['order_age']; |
|---|
| 259 | // 職業 |
|---|
| 260 | $arrEbis['o4id'] = $arrRet[0]['order_job']; |
|---|
| 261 | |
|---|
| 262 | $objQuery->setGroupBy("product_id"); |
|---|
| 263 | $arrRet = $objQuery->select("product_id", "dtb_order_detail", "order_id = ?", array($order_id)); |
|---|
| 264 | $arrProducts = sfSwapArray($arrRet); |
|---|
| 265 | |
|---|
| 266 | $line = ""; |
|---|
| 267 | // 商品IDをアンダーバーで接続する。 |
|---|
| 268 | foreach($arrProducts['product_id'] as $val) { |
|---|
| 269 | if($line != "") { |
|---|
| 270 | $line .= "_$val"; |
|---|
| 271 | } else { |
|---|
| 272 | $line .= "$val"; |
|---|
| 273 | } |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | // 商品ID |
|---|
| 277 | $arrEbis['o1id'] = $line; |
|---|
| 278 | |
|---|
| 279 | return $arrEbis; |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | /** |
|---|
| 283 | * 購入完了処理 |
|---|
| 284 | * |
|---|
| 285 | * @param object $objQuery |
|---|
| 286 | * @param string $uniqid |
|---|
| 287 | * @return string $order_id |
|---|
| 288 | */ |
|---|
| 289 | function lfDoComplete(&$objQuery, $uniqid) { |
|---|
| 290 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 291 | |
|---|
| 292 | // 一時受注テーブルの読込 |
|---|
| 293 | $arrData = $objDb->sfGetOrderTemp($uniqid); |
|---|
| 294 | |
|---|
| 295 | // 会員情報登録処理 |
|---|
| 296 | if ($this->objCustomer->isLoginSuccess(true)) { |
|---|
| 297 | // 新お届け先の登録 |
|---|
| 298 | $this->lfSetNewAddr($uniqid, $this->objCustomer->getValue('customer_id')); |
|---|
| 299 | // 購入集計を顧客テーブルに反映 |
|---|
| 300 | $this->lfSetCustomerPurchase($this->objCustomer->getValue('customer_id'), $arrData, $objQuery); |
|---|
| 301 | } else { |
|---|
| 302 | //購入時強制会員登録 |
|---|
| 303 | switch(PURCHASE_CUSTOMER_REGIST) { |
|---|
| 304 | //無効 |
|---|
| 305 | case '0': |
|---|
| 306 | // 購入時会員登録 |
|---|
| 307 | if(isset($arrData['member_check']) && $arrData['member_check'] == '1') { |
|---|
| 308 | // 会員登録 |
|---|
| 309 | $customer_id = $this->lfRegistCustomer($arrData, $this->arrInfo); |
|---|
| 310 | // 購入集計を顧客テーブルに反映 |
|---|
| 311 | $this->lfSetCustomerPurchase($customer_id, $arrData, $objQuery); |
|---|
| 312 | } |
|---|
| 313 | break; |
|---|
| 314 | //有効 |
|---|
| 315 | case '1': |
|---|
| 316 | // 会員登録 |
|---|
| 317 | $customer_id = $this->lfRegistCustomer($arrData, $this->arrInfo); |
|---|
| 318 | // 購入集計を顧客テーブルに反映 |
|---|
| 319 | $this->lfSetCustomerPurchase($customer_id, $arrData, $objQuery); |
|---|
| 320 | break; |
|---|
| 321 | } |
|---|
| 322 | |
|---|
| 323 | } |
|---|
| 324 | // 一時テーブルを受注テーブルに格納する |
|---|
| 325 | if (defined("MOBILE_SITE")) { |
|---|
| 326 | $order_id = $this->lfRegistOrder($objQuery, $arrData); |
|---|
| 327 | } else { |
|---|
| 328 | $order_id = $this->lfRegistOrder($objQuery, $arrData, $this->objCampaignSess); |
|---|
| 329 | } |
|---|
| 330 | // カート商品を受注詳細テーブルに格納する |
|---|
| 331 | $this->lfRegistOrderDetail($objQuery, $order_id, $this->objCartSess); |
|---|
| 332 | // 受注一時テーブルの情報を削除する。 |
|---|
| 333 | $this->lfDeleteTempOrder($objQuery, $uniqid); |
|---|
| 334 | // キャンペーンからの遷移の場合登録する。 |
|---|
| 335 | if (!defined("MOBILE_SITE")) { |
|---|
| 336 | if($this->objCampaignSess->getIsCampaign() and $this->objCartSess->chkCampaign($this->objCampaignSess->getCampaignId())) { |
|---|
| 337 | $this->lfRegistCampaignOrder($objQuery, $objCampaignSess, $order_id); |
|---|
| 338 | } |
|---|
| 339 | } |
|---|
| 340 | |
|---|
| 341 | // セッションカート内の商品を削除する。 |
|---|
| 342 | $this->objCartSess->delAllProducts(); |
|---|
| 343 | // 注文一時IDを解除する。 |
|---|
| 344 | $this->objSiteSess->unsetUniqId(); |
|---|
| 345 | |
|---|
| 346 | return $order_id; |
|---|
| 347 | } |
|---|
| 348 | |
|---|
| 349 | // 会員登録 |
|---|
| 350 | function lfRegistCustomer($arrData, $arrInfo) { |
|---|
| 351 | $objQuery = new SC_Query(); |
|---|
| 352 | |
|---|
| 353 | //会員登録時に仮会員確認用のメールを送付するか |
|---|
| 354 | $confirm_flg = CUSTOMER_CONFIRM_MAIL; |
|---|
| 355 | |
|---|
| 356 | // 購入時の会員登録 |
|---|
| 357 | $sqlval['name01'] = $arrData['order_name01']; |
|---|
| 358 | $sqlval['name02'] = $arrData['order_name02']; |
|---|
| 359 | $sqlval['kana01'] = $arrData['order_kana01']; |
|---|
| 360 | $sqlval['kana02'] = $arrData['order_kana02']; |
|---|
| 361 | $sqlval['zip01'] = $arrData['order_zip01']; |
|---|
| 362 | $sqlval['zip02'] = $arrData['order_zip02']; |
|---|
| 363 | $sqlval['pref'] = $arrData['order_pref']; |
|---|
| 364 | $sqlval['addr01'] = $arrData['order_addr01']; |
|---|
| 365 | $sqlval['addr02'] = $arrData['order_addr02']; |
|---|
| 366 | $sqlval['email'] = $arrData['order_email']; |
|---|
| 367 | $sqlval['tel01'] = $arrData['order_tel01']; |
|---|
| 368 | $sqlval['tel02'] = $arrData['order_tel02']; |
|---|
| 369 | $sqlval['tel03'] = $arrData['order_tel03']; |
|---|
| 370 | $sqlval['fax01'] = $arrData['order_fax01']; |
|---|
| 371 | $sqlval['fax02'] = $arrData['order_fax02']; |
|---|
| 372 | $sqlval['fax03'] = $arrData['order_fax03']; |
|---|
| 373 | $sqlval['sex'] = $arrData['order_sex']; |
|---|
| 374 | $sqlval['password'] = $arrData['password']; |
|---|
| 375 | $sqlval['reminder'] = $arrData['reminder']; |
|---|
| 376 | $sqlval['reminder_answer'] = $arrData['reminder_answer']; |
|---|
| 377 | |
|---|
| 378 | // 仮会員登録の場合 |
|---|
| 379 | if($confirm_flg == true) { |
|---|
| 380 | // 重複しない会員登録キーを発行する。 |
|---|
| 381 | $count = 1; |
|---|
| 382 | while ($count != 0) { |
|---|
| 383 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("t"); |
|---|
| 384 | $count = $objQuery->count("dtb_customer", "secret_key = ?", array($uniqid)); |
|---|
| 385 | } |
|---|
| 386 | $sqlval["status"] = "1"; // 仮会員 |
|---|
| 387 | //本会員登録 |
|---|
| 388 | } else { |
|---|
| 389 | // 重複しない会員登録キーを発行する。 |
|---|
| 390 | $count = 1; |
|---|
| 391 | while ($count != 0) { |
|---|
| 392 | $uniqid = SC_Utils_Ex::sfGetUniqRandomId("r"); |
|---|
| 393 | $count = $objQuery->count("dtb_customer", "secret_key = ?", array($uniqid)); |
|---|
| 394 | } |
|---|
| 395 | $sqlval["status"] = "2"; // 本会員 |
|---|
| 396 | } |
|---|
| 397 | |
|---|
| 398 | // メルマガフラグ |
|---|
| 399 | switch($arrData["mailmaga_flg"]) { |
|---|
| 400 | case 1: |
|---|
| 401 | $mail_flag = 4; |
|---|
| 402 | break; |
|---|
| 403 | case 2: |
|---|
| 404 | $mail_flag = 5; |
|---|
| 405 | break; |
|---|
| 406 | default: |
|---|
| 407 | $mail_flag = 6; |
|---|
| 408 | break; |
|---|
| 409 | } |
|---|
| 410 | $sqlval['mailmaga_flg'] = $mail_flag; |
|---|
| 411 | |
|---|
| 412 | // URL判定用キー |
|---|
| 413 | $sqlval['secret_key'] = SC_Utils_Ex::sfGetUniqRandomId("t"); |
|---|
| 414 | |
|---|
| 415 | $sqlval['create_date'] = "now()"; |
|---|
| 416 | $sqlval['update_date'] = "now()"; |
|---|
| 417 | $objQuery->insert("dtb_customer", $sqlval); |
|---|
| 418 | |
|---|
| 419 | // 顧客IDの取得 |
|---|
| 420 | $arrRet = $objQuery->select("customer_id", "dtb_customer", "secret_key = ?", array($sqlval['secret_key'])); |
|---|
| 421 | $customer_id = $arrRet[0]['customer_id']; |
|---|
| 422 | |
|---|
| 423 | // 登録完了メール送信 |
|---|
| 424 | $objMailPage = $this; |
|---|
| 425 | $objMailPage->name01 = $arrData['order_name01']; |
|---|
| 426 | $objMailPage->name02 = $arrData['order_name02']; |
|---|
| 427 | $objMailPage->CONF = $arrInfo; |
|---|
| 428 | $objMailPage->uniqid = $sqlval['secret_key']; |
|---|
| 429 | $objMailView = new SC_SiteView(); |
|---|
| 430 | $objMailView->assignobj($objMailPage); |
|---|
| 431 | $body = $objMailView->fetch("mail_templates/customer_mail.tpl"); |
|---|
| 432 | |
|---|
| 433 | $mailHelper = new SC_Helper_Mail_Ex(); |
|---|
| 434 | |
|---|
| 435 | //仮会員メール |
|---|
| 436 | if($confirm_flg == true) { |
|---|
| 437 | $subject = $mailHelper->sfMakeSubject($objQuery,$objMailView,$objMailPage,"会員登録のご確認"); |
|---|
| 438 | $body = $objMailView->fetch("mail_templates/customer_mail.tpl"); |
|---|
| 439 | //本会員メール |
|---|
| 440 | }else{ |
|---|
| 441 | $subject = $mailHelper->sfMakeSubject($objQuery,$objMailView,$objMailPage,'会員登録のご完了'); |
|---|
| 442 | $body = $objMailView->fetch("mail_templates/customer_regist_mail.tpl"); |
|---|
| 443 | // ログイン状態にする |
|---|
| 444 | $this->objCustomer->setLogin($arrData['order_email']); |
|---|
| 445 | } |
|---|
| 446 | |
|---|
| 447 | $objMail = new SC_SendMail(); |
|---|
| 448 | $objMail->setItem( |
|---|
| 449 | '' // 宛先 |
|---|
| 450 | , $subject // サブジェクト |
|---|
| 451 | , $body // 本文 |
|---|
| 452 | , $arrInfo['email03'] // 配送元アドレス |
|---|
| 453 | , $arrInfo['shop_name'] // 配送元 名前 |
|---|
| 454 | , $arrInfo["email03"] // reply_to |
|---|
| 455 | , $arrInfo["email04"] // return_path |
|---|
| 456 | , $arrInfo["email04"] // Errors_to |
|---|
| 457 | , $arrInfo["email01"] // Bcc |
|---|
| 458 | ); |
|---|
| 459 | // 宛先の設定 |
|---|
| 460 | $name = $arrData['order_name01'] . $arrData['order_name02'] ." 様"; |
|---|
| 461 | $objMail->setTo($arrData['order_email'], $name); |
|---|
| 462 | $objMail->sendMail(); |
|---|
| 463 | |
|---|
| 464 | return $customer_id; |
|---|
| 465 | } |
|---|
| 466 | |
|---|
| 467 | // 受注テーブルへ登録 |
|---|
| 468 | function lfRegistOrder($objQuery, $arrData, $objCampaignSess = null) { |
|---|
| 469 | $sqlval = $arrData; |
|---|
| 470 | |
|---|
| 471 | // 受注テーブルに書き込まない列を除去 |
|---|
| 472 | unset($sqlval['mailmaga_flg']); // メルマガチェック |
|---|
| 473 | unset($sqlval['deliv_check']); // 別のお届け先チェック |
|---|
| 474 | unset($sqlval['point_check']); // ポイント利用チェック |
|---|
| 475 | unset($sqlval['member_check']); // 購入時会員チェック |
|---|
| 476 | unset($sqlval['password']); // ログインパスワード |
|---|
| 477 | unset($sqlval['reminder']); // リマインダー質問 |
|---|
| 478 | unset($sqlval['reminder_answer']); // リマインダー答え |
|---|
| 479 | unset($sqlval['mail_flag']); // メールフラグ |
|---|
| 480 | unset($sqlval['session']); // セッション情報 |
|---|
| 481 | |
|---|
| 482 | // 注文ステータス:指定が無ければ新規受付に設定 |
|---|
| 483 | if($sqlval["status"] == ""){ |
|---|
| 484 | $sqlval['status'] = '1'; |
|---|
| 485 | } |
|---|
| 486 | |
|---|
| 487 | // 別のお届け先を指定していない場合、お届け先に登録住所をコピーする。 |
|---|
| 488 | if($arrData["deliv_check"] == "-1") { |
|---|
| 489 | $sqlval['deliv_name01'] = $arrData['order_name01']; |
|---|
| 490 | $sqlval['deliv_name02'] = $arrData['order_name02']; |
|---|
| 491 | $sqlval['deliv_kana01'] = $arrData['order_kana01']; |
|---|
| 492 | $sqlval['deliv_kana02'] = $arrData['order_kana02']; |
|---|
| 493 | $sqlval['deliv_pref'] = $arrData['order_pref']; |
|---|
| 494 | $sqlval['deliv_zip01'] = $arrData['order_zip01']; |
|---|
| 495 | $sqlval['deliv_zip02'] = $arrData['order_zip02']; |
|---|
| 496 | $sqlval['deliv_addr01'] = $arrData['order_addr01']; |
|---|
| 497 | $sqlval['deliv_addr02'] = $arrData['order_addr02']; |
|---|
| 498 | $sqlval['deliv_tel01'] = $arrData['order_tel01']; |
|---|
| 499 | $sqlval['deliv_tel02'] = $arrData['order_tel02']; |
|---|
| 500 | $sqlval['deliv_tel03'] = $arrData['order_tel03']; |
|---|
| 501 | } |
|---|
| 502 | |
|---|
| 503 | $order_id = $arrData['order_id']; // 注文番号 |
|---|
| 504 | $sqlval['create_date'] = 'now()'; // 受注日 |
|---|
| 505 | |
|---|
| 506 | // キャンペーンID |
|---|
| 507 | if (!defined("MOBILE_SITE")) { |
|---|
| 508 | if($objCampaignSess->getIsCampaign()) $sqlval['campaign_id'] = $objCampaignSess->getCampaignId(); |
|---|
| 509 | } |
|---|
| 510 | |
|---|
| 511 | // ゲットの値をインサート |
|---|
| 512 | //$sqlval = lfGetInsParam($sqlval); |
|---|
| 513 | |
|---|
| 514 | // INSERTの実行 |
|---|
| 515 | $objQuery->insert("dtb_order", $sqlval); |
|---|
| 516 | |
|---|
| 517 | return $order_id; |
|---|
| 518 | } |
|---|
| 519 | |
|---|
| 520 | // 受注詳細テーブルへ登録 |
|---|
| 521 | function lfRegistOrderDetail(&$objQuery, $order_id, &$objCartSess) { |
|---|
| 522 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 523 | // カート内情報の取得 |
|---|
| 524 | $arrCart = $objCartSess->getCartList(); |
|---|
| 525 | $max = count($arrCart); |
|---|
| 526 | |
|---|
| 527 | // 既に存在する詳細レコードを消しておく。 |
|---|
| 528 | $objQuery->delete("dtb_order_detail", "order_id = $order_id"); |
|---|
| 529 | |
|---|
| 530 | // 規格名一覧 |
|---|
| 531 | $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
|---|
| 532 | // 規格分類名一覧 |
|---|
| 533 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
|---|
| 534 | |
|---|
| 535 | for ($i = 0; $i < $max; $i++) { |
|---|
| 536 | // 商品規格情報の取得 |
|---|
| 537 | $arrData = $objDb->sfGetProductsClass($arrCart[$i]['id']); |
|---|
| 538 | |
|---|
| 539 | // 存在する商品のみ表示する。 |
|---|
| 540 | if($arrData != "") { |
|---|
| 541 | $sqlval['order_id'] = $order_id; |
|---|
| 542 | $sqlval['product_id'] = $arrCart[$i]['id'][0]; |
|---|
| 543 | $sqlval['classcategory_id1'] = $arrCart[$i]['id'][1]; |
|---|
| 544 | $sqlval['classcategory_id2'] = $arrCart[$i]['id'][2]; |
|---|
| 545 | $sqlval['product_name'] = $arrData['name']; |
|---|
| 546 | $sqlval['product_code'] = $arrData['product_code']; |
|---|
| 547 | $sqlval['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']]; |
|---|
| 548 | $sqlval['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']]; |
|---|
| 549 | $sqlval['point_rate'] = $arrCart[$i]['point_rate']; |
|---|
| 550 | $sqlval['price'] = $arrCart[$i]['price']; |
|---|
| 551 | $sqlval['quantity'] = $arrCart[$i]['quantity']; |
|---|
| 552 | $this->lfReduceStock($objQuery, $arrCart[$i]['id'], $arrCart[$i]['quantity']); |
|---|
| 553 | // INSERTの実行 |
|---|
| 554 | $objQuery->insert("dtb_order_detail", $sqlval); |
|---|
| 555 | } else { |
|---|
| 556 | if (defined("MOBILE_SITE")) { |
|---|
| 557 | SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND, "", false, "", true); |
|---|
| 558 | } else { |
|---|
| 559 | SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND); |
|---|
| 560 | } |
|---|
| 561 | } |
|---|
| 562 | } |
|---|
| 563 | } |
|---|
| 564 | |
|---|
| 565 | // キャンペーン受注テーブルへ登録 |
|---|
| 566 | function lfRegistCampaignOrder(&$objQuery, &$objCampaignSess, $order_id) { |
|---|
| 567 | |
|---|
| 568 | // 受注データを取得 |
|---|
| 569 | $cols = "order_id, campaign_id, customer_id, message, order_name01, order_name02,". |
|---|
| 570 | "order_kana01, order_kana02, order_email, order_tel01, order_tel02, order_tel03,". |
|---|
| 571 | "order_fax01, order_fax02, order_fax03, order_zip01, order_zip02, order_pref, order_addr01,". |
|---|
| 572 | "order_addr02, order_sex, order_birth, order_job, deliv_name01, deliv_name02, deliv_kana01,". |
|---|
| 573 | "deliv_kana02, deliv_tel01, deliv_tel02, deliv_tel03, deliv_fax01, deliv_fax02, deliv_fax03,". |
|---|
| 574 | "deliv_zip01, deliv_zip02, deliv_pref, deliv_addr01, deliv_addr02, payment_total"; |
|---|
| 575 | |
|---|
| 576 | $arrOrder = $objQuery->select($cols, "dtb_order", "order_id = ?", array($order_id)); |
|---|
| 577 | |
|---|
| 578 | $sqlval = $arrOrder[0]; |
|---|
| 579 | $sqlval['create_date'] = 'now()'; |
|---|
| 580 | |
|---|
| 581 | // INSERTの実行 |
|---|
| 582 | $objQuery->insert("dtb_campaign_order", $sqlval); |
|---|
| 583 | |
|---|
| 584 | // 申し込み数の更新 |
|---|
| 585 | $total_count = $objQuery->get("dtb_campaign", "total_count", "campaign_id = ?", array($sqlval['campaign_id'])); |
|---|
| 586 | $arrCampaign['total_count'] = $total_count += 1; |
|---|
| 587 | $objQuery->update("dtb_campaign", $arrCampaign, "campaign_id = ?", array($sqlval['campaign_id'])); |
|---|
| 588 | |
|---|
| 589 | } |
|---|
| 590 | |
|---|
| 591 | |
|---|
| 592 | |
|---|
| 593 | /* 受注一時テーブルの削除 */ |
|---|
| 594 | function lfDeleteTempOrder(&$objQuery, $uniqid) { |
|---|
| 595 | $where = "order_temp_id = ?"; |
|---|
| 596 | $sqlval['del_flg'] = 1; |
|---|
| 597 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); |
|---|
| 598 | // $objQuery->delete("dtb_order_temp", $where, array($uniqid)); |
|---|
| 599 | } |
|---|
| 600 | |
|---|
| 601 | // 受注一時テーブルの住所が登録済みテーブルと異なる場合は、別のお届け先に追加する |
|---|
| 602 | function lfSetNewAddr($uniqid, $customer_id) { |
|---|
| 603 | $objQuery = new SC_Query(); |
|---|
| 604 | $diff = false; |
|---|
| 605 | $find_same = false; |
|---|
| 606 | |
|---|
| 607 | $col = "deliv_name01,deliv_name02,deliv_kana01,deliv_kana02,deliv_tel01,deliv_tel02,deliv_tel03,deliv_zip01,deliv_zip02,deliv_pref,deliv_addr01,deliv_addr02"; |
|---|
| 608 | $where = "order_temp_id = ?"; |
|---|
| 609 | $arrRet = $objQuery->select($col, "dtb_order_temp", $where, array($uniqid)); |
|---|
| 610 | |
|---|
| 611 | // 要素名のdeliv_を削除する。 |
|---|
| 612 | foreach($arrRet[0] as $key => $val) { |
|---|
| 613 | $keyname = ereg_replace("^deliv_", "", $key); |
|---|
| 614 | $arrNew[$keyname] = $val; |
|---|
| 615 | } |
|---|
| 616 | |
|---|
| 617 | // 会員情報テーブルとの比較 |
|---|
| 618 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
|---|
| 619 | $where = "customer_id = ?"; |
|---|
| 620 | $arrCustomerAddr = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
|---|
| 621 | |
|---|
| 622 | // 会員情報の住所と異なる場合 |
|---|
| 623 | if($arrNew != $arrCustomerAddr[0]) { |
|---|
| 624 | // 別のお届け先テーブルの住所と比較する |
|---|
| 625 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
|---|
| 626 | $where = "customer_id = ?"; |
|---|
| 627 | $arrOtherAddr = $objQuery->select($col, "dtb_other_deliv", $where, array($customer_id)); |
|---|
| 628 | |
|---|
| 629 | foreach($arrOtherAddr as $arrval) { |
|---|
| 630 | if($arrNew == $arrval) { |
|---|
| 631 | // すでに同じ住所が登録されている |
|---|
| 632 | $find_same = true; |
|---|
| 633 | } |
|---|
| 634 | } |
|---|
| 635 | |
|---|
| 636 | if(!$find_same) { |
|---|
| 637 | $diff = true; |
|---|
| 638 | } |
|---|
| 639 | } |
|---|
| 640 | |
|---|
| 641 | // 新しいお届け先が登録済みのものと異なる場合は別のお届け先テーブルに登録する |
|---|
| 642 | if($diff) { |
|---|
| 643 | $sqlval = $arrNew; |
|---|
| 644 | $sqlval['customer_id'] = $customer_id; |
|---|
| 645 | $objQuery->insert("dtb_other_deliv", $sqlval); |
|---|
| 646 | } |
|---|
| 647 | } |
|---|
| 648 | |
|---|
| 649 | /* 購入情報を会員テーブルに登録する */ |
|---|
| 650 | function lfSetCustomerPurchase($customer_id, $arrData, &$objQuery) { |
|---|
| 651 | $col = "first_buy_date, last_buy_date, buy_times, buy_total, point"; |
|---|
| 652 | $where = "customer_id = ?"; |
|---|
| 653 | $arrRet = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
|---|
| 654 | $sqlval = $arrRet[0]; |
|---|
| 655 | |
|---|
| 656 | if($sqlval['first_buy_date'] == "") { |
|---|
| 657 | $sqlval['first_buy_date'] = "Now()"; |
|---|
| 658 | } |
|---|
| 659 | $sqlval['last_buy_date'] = "Now()"; |
|---|
| 660 | $sqlval['buy_times']++; |
|---|
| 661 | $sqlval['buy_total']+= $arrData['total']; |
|---|
| 662 | if (USE_POINT === false) { |
|---|
| 663 | $sqlval['point'] = $sqlval['point']; |
|---|
| 664 | } else { |
|---|
| 665 | //$sqlval['point'] = ($sqlval['point'] - $arrData['use_point']); |
|---|
| 666 | $sqlval['point'] = ($sqlval['point'] + $arrData['add_point'] - $arrData['use_point']); |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | // ポイントが不足している場合 |
|---|
| 670 | if($sqlval['point'] < 0) { |
|---|
| 671 | $objQuery->rollback(); |
|---|
| 672 | SC_Utils_Ex::sfDispSiteError(LACK_POINT); |
|---|
| 673 | } |
|---|
| 674 | |
|---|
| 675 | $objQuery->update("dtb_customer", $sqlval, $where, array($customer_id)); |
|---|
| 676 | } |
|---|
| 677 | |
|---|
| 678 | // 在庫を減らす処理 |
|---|
| 679 | function lfReduceStock(&$objQuery, $arrID, $quantity) { |
|---|
| 680 | $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; |
|---|
| 681 | $arrRet = $objQuery->select("stock, stock_unlimited", "dtb_products_class", $where, $arrID); |
|---|
| 682 | |
|---|
| 683 | // 売り切れエラー |
|---|
| 684 | if(($arrRet[0]['stock_unlimited'] != '1' && $arrRet[0]['stock'] < $quantity) || $quantity == 0) { |
|---|
| 685 | $objQuery->rollback(); |
|---|
| 686 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, "", true); |
|---|
| 687 | // 無制限の場合、在庫はNULL |
|---|
| 688 | } elseif($arrRet[0]['stock_unlimited'] == '1') { |
|---|
| 689 | $sqlval['stock'] = null; |
|---|
| 690 | $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); |
|---|
| 691 | // 在庫を減らす |
|---|
| 692 | } else { |
|---|
| 693 | $sqlval['stock'] = ($arrRet[0]['stock'] - $quantity); |
|---|
| 694 | if($sqlval['stock'] == "") { |
|---|
| 695 | $sqlval['stock'] = '0'; |
|---|
| 696 | } |
|---|
| 697 | $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); |
|---|
| 698 | } |
|---|
| 699 | } |
|---|
| 700 | |
|---|
| 701 | // GETの値をインサート用に整える |
|---|
| 702 | function lfGetInsParam($sqlVal){ |
|---|
| 703 | $objDb = new SC_Helper_DB_Ex(); |
|---|
| 704 | foreach($_GET as $key => $val){ |
|---|
| 705 | // カラムの存在チェック |
|---|
| 706 | if($objDb->sfColumnExists("dtb_order", $key)) $sqlVal[$key] = $val; |
|---|
| 707 | } |
|---|
| 708 | |
|---|
| 709 | return $sqlVal; |
|---|
| 710 | } |
|---|
| 711 | } |
|---|
| 712 | ?> |
|---|