| 1 | <?php |
---|
| 2 | /* |
---|
| 3 | * This file is part of EC-CUBE |
---|
| 4 | * |
---|
| 5 | * Copyright(c) 2000-2007 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='". $val["value"] . "' target=\"_blank\">" . $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->lfRegistPreCustomer($arrData, $this->arrInfo); |
---|
| 310 | // 購入集計を顧客テーブルに反映 |
---|
| 311 | $this->lfSetCustomerPurchase($customer_id, $arrData, $objQuery); |
---|
| 312 | } |
---|
| 313 | break; |
---|
| 314 | //有効 |
---|
| 315 | case '1': |
---|
| 316 | // 仮会員登録 |
---|
| 317 | $customer_id = $this->lfRegistPreCustomer($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 lfRegistPreCustomer($arrData, $arrInfo) { |
---|
| 351 | // 購入時の会員登録 |
---|
| 352 | $sqlval['name01'] = $arrData['order_name01']; |
---|
| 353 | $sqlval['name02'] = $arrData['order_name02']; |
---|
| 354 | $sqlval['kana01'] = $arrData['order_kana01']; |
---|
| 355 | $sqlval['kana02'] = $arrData['order_kana02']; |
---|
| 356 | $sqlval['zip01'] = $arrData['order_zip01']; |
---|
| 357 | $sqlval['zip02'] = $arrData['order_zip02']; |
---|
| 358 | $sqlval['pref'] = $arrData['order_pref']; |
---|
| 359 | $sqlval['addr01'] = $arrData['order_addr01']; |
---|
| 360 | $sqlval['addr02'] = $arrData['order_addr02']; |
---|
| 361 | $sqlval['email'] = $arrData['order_email']; |
---|
| 362 | $sqlval['tel01'] = $arrData['order_tel01']; |
---|
| 363 | $sqlval['tel02'] = $arrData['order_tel02']; |
---|
| 364 | $sqlval['tel03'] = $arrData['order_tel03']; |
---|
| 365 | $sqlval['fax01'] = $arrData['order_fax01']; |
---|
| 366 | $sqlval['fax02'] = $arrData['order_fax02']; |
---|
| 367 | $sqlval['fax03'] = $arrData['order_fax03']; |
---|
| 368 | $sqlval['sex'] = $arrData['order_sex']; |
---|
| 369 | $sqlval['password'] = $arrData['password']; |
---|
| 370 | $sqlval['reminder'] = $arrData['reminder']; |
---|
| 371 | $sqlval['reminder_answer'] = $arrData['reminder_answer']; |
---|
| 372 | |
---|
| 373 | // メルマガ配信用フラグの判定 |
---|
| 374 | switch($arrData['mail_flag']) { |
---|
| 375 | case '1': // HTMLメール |
---|
| 376 | $mail_flag = 4; |
---|
| 377 | break; |
---|
| 378 | case '2': // TEXTメール |
---|
| 379 | $mail_flag = 5; |
---|
| 380 | break; |
---|
| 381 | case '3': // 希望なし |
---|
| 382 | $mail_flag = 6; |
---|
| 383 | break; |
---|
| 384 | default: |
---|
| 385 | $mail_flag = 6; |
---|
| 386 | break; |
---|
| 387 | } |
---|
| 388 | // メルマガフラグ |
---|
| 389 | $sqlval['mailmaga_flg'] = $mail_flag; |
---|
| 390 | |
---|
| 391 | // 会員仮登録 |
---|
| 392 | $sqlval['status'] = 1; |
---|
| 393 | // URL判定用キー |
---|
| 394 | $sqlval['secret_key'] = SC_Utils_Ex::sfGetUniqRandomId("t"); |
---|
| 395 | |
---|
| 396 | $objQuery = new SC_Query(); |
---|
| 397 | $sqlval['create_date'] = "now()"; |
---|
| 398 | $sqlval['update_date'] = "now()"; |
---|
| 399 | $objQuery->insert("dtb_customer", $sqlval); |
---|
| 400 | |
---|
| 401 | // 顧客IDの取得 |
---|
| 402 | $arrRet = $objQuery->select("customer_id", "dtb_customer", "secret_key = ?", array($sqlval['secret_key'])); |
---|
| 403 | $customer_id = $arrRet[0]['customer_id']; |
---|
| 404 | |
---|
| 405 | // 仮登録完了メール送信 |
---|
| 406 | $objMailPage = $this; |
---|
| 407 | $objMailPage->to_name01 = $arrData['order_name01']; |
---|
| 408 | $objMailPage->to_name02 = $arrData['order_name02']; |
---|
| 409 | $objMailPage->CONF = $arrInfo; |
---|
| 410 | $objMailPage->uniqid = $sqlval['secret_key']; |
---|
| 411 | $objMailView = new SC_SiteView(); |
---|
| 412 | $objMailView->assignobj($objMailPage); |
---|
| 413 | $body = $objMailView->fetch("mail_templates/customer_mail.tpl"); |
---|
| 414 | |
---|
| 415 | $mailHelper = new SC_Helper_Mail_Ex(); |
---|
| 416 | |
---|
| 417 | $objMail = new SC_SendMail(); |
---|
| 418 | $objMail->setItem( |
---|
| 419 | '' // 宛先 |
---|
| 420 | , $mailHelper->sfMakeSubject("会員登録のご確認") // サブジェクト |
---|
| 421 | , $body // 本文 |
---|
| 422 | , $arrInfo['email03'] // 配送元アドレス |
---|
| 423 | , $arrInfo['shop_name'] // 配送元 名前 |
---|
| 424 | , $arrInfo["email03"] // reply_to |
---|
| 425 | , $arrInfo["email04"] // return_path |
---|
| 426 | , $arrInfo["email04"] // Errors_to |
---|
| 427 | , $arrInfo["email01"] // Bcc |
---|
| 428 | ); |
---|
| 429 | // 宛先の設定 |
---|
| 430 | $name = $arrData['order_name01'] . $arrData['order_name02'] ." 様"; |
---|
| 431 | $objMail->setTo($arrData['order_email'], $name); |
---|
| 432 | $objMail->sendMail(); |
---|
| 433 | |
---|
| 434 | return $customer_id; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | /** |
---|
| 438 | * 受注テーブルへ登録 |
---|
| 439 | * |
---|
| 440 | * @return integer 注文番号 |
---|
| 441 | */ |
---|
| 442 | function lfRegistOrder($objQuery, $arrData, $objCampaignSess = null) { |
---|
| 443 | $sqlval = $arrData; |
---|
| 444 | |
---|
| 445 | // 受注テーブルに書き込まない列を除去 |
---|
| 446 | unset($sqlval['mailmaga_flg']); // メルマガチェック |
---|
| 447 | unset($sqlval['deliv_check']); // 別のお届け先チェック |
---|
| 448 | unset($sqlval['point_check']); // ポイント利用チェック |
---|
| 449 | unset($sqlval['member_check']); // 購入時会員チェック |
---|
| 450 | unset($sqlval['password']); // ログインパスワード |
---|
| 451 | unset($sqlval['reminder']); // リマインダー質問 |
---|
| 452 | unset($sqlval['reminder_answer']); // リマインダー答え |
---|
| 453 | unset($sqlval['mail_flag']); // メールフラグ |
---|
| 454 | unset($sqlval['session']); // セッション情報 |
---|
| 455 | |
---|
| 456 | // ポイントは別登録 |
---|
| 457 | $addPoint = $sqlval['add_point']; |
---|
| 458 | $usePoint = $sqlval['use_point']; |
---|
| 459 | $sqlval['add_point'] = 0; |
---|
| 460 | $sqlval['use_point'] = 0; |
---|
| 461 | |
---|
| 462 | // 注文ステータス:指定が無ければ新規受付に設定 |
---|
| 463 | if (strlen($sqlval['status']) == 0) { |
---|
| 464 | $sqlval['status'] = ORDER_NEW; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | // 別のお届け先を指定していない場合、配送先に登録住所をコピーする。 |
---|
| 468 | if ($arrData["deliv_check"] == "-1") { |
---|
| 469 | $sqlval['deliv_name01'] = $arrData['order_name01']; |
---|
| 470 | $sqlval['deliv_name02'] = $arrData['order_name02']; |
---|
| 471 | $sqlval['deliv_kana01'] = $arrData['order_kana01']; |
---|
| 472 | $sqlval['deliv_kana02'] = $arrData['order_kana02']; |
---|
| 473 | $sqlval['deliv_pref'] = $arrData['order_pref']; |
---|
| 474 | $sqlval['deliv_zip01'] = $arrData['order_zip01']; |
---|
| 475 | $sqlval['deliv_zip02'] = $arrData['order_zip02']; |
---|
| 476 | $sqlval['deliv_addr01'] = $arrData['order_addr01']; |
---|
| 477 | $sqlval['deliv_addr02'] = $arrData['order_addr02']; |
---|
| 478 | $sqlval['deliv_tel01'] = $arrData['order_tel01']; |
---|
| 479 | $sqlval['deliv_tel02'] = $arrData['order_tel02']; |
---|
| 480 | $sqlval['deliv_tel03'] = $arrData['order_tel03']; |
---|
| 481 | } |
---|
| 482 | |
---|
| 483 | $order_id = $arrData['order_id']; // 注文番号 |
---|
| 484 | $sqlval['create_date'] = 'Now()'; // 受注日 |
---|
| 485 | $sqlval['update_date'] = 'Now()'; // 更新日時 |
---|
| 486 | |
---|
| 487 | // キャンペーンID |
---|
| 488 | if (!defined("MOBILE_SITE")) { |
---|
| 489 | if ($objCampaignSess->getIsCampaign()) $sqlval['campaign_id'] = $objCampaignSess->getCampaignId(); |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | // ゲットの値をインサート |
---|
| 493 | //$sqlval = lfGetInsParam($sqlval); |
---|
| 494 | |
---|
| 495 | // 受注テーブルの登録 |
---|
| 496 | $objQuery->insert("dtb_order", $sqlval); |
---|
| 497 | |
---|
| 498 | // 受注.対応状況の更新 |
---|
| 499 | SC_Helper_DB_Ex::sfUpdateOrderStatus($order_id, null, $addPoint, $usePoint); |
---|
| 500 | |
---|
| 501 | return $order_id; |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | // 受注詳細テーブルへ登録 |
---|
| 505 | function lfRegistOrderDetail(&$objQuery, $order_id, &$objCartSess) { |
---|
| 506 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 507 | // カート内情報の取得 |
---|
| 508 | $arrCart = $objCartSess->getCartList(); |
---|
| 509 | $max = count($arrCart); |
---|
| 510 | |
---|
| 511 | // 既に存在する詳細レコードを消しておく。 |
---|
| 512 | $objQuery->delete("dtb_order_detail", "order_id = $order_id"); |
---|
| 513 | |
---|
| 514 | // 規格名一覧 |
---|
| 515 | $arrClassName = $objDb->sfGetIDValueList("dtb_class", "class_id", "name"); |
---|
| 516 | // 規格分類名一覧 |
---|
| 517 | $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name"); |
---|
| 518 | |
---|
| 519 | for ($i = 0; $i < $max; $i++) { |
---|
| 520 | // 商品規格情報の取得 |
---|
| 521 | $arrData = $objDb->sfGetProductsClass($arrCart[$i]['id']); |
---|
| 522 | |
---|
| 523 | // 存在する商品のみ表示する。 |
---|
| 524 | if($arrData != "") { |
---|
| 525 | $sqlval['order_id'] = $order_id; |
---|
| 526 | $sqlval['product_id'] = $arrCart[$i]['id'][0]; |
---|
| 527 | $sqlval['classcategory_id1'] = $arrCart[$i]['id'][1]; |
---|
| 528 | $sqlval['classcategory_id2'] = $arrCart[$i]['id'][2]; |
---|
| 529 | $sqlval['product_name'] = $arrData['name']; |
---|
| 530 | $sqlval['product_code'] = $arrData['product_code']; |
---|
| 531 | $sqlval['classcategory_name1'] = $arrClassCatName[$arrData['classcategory_id1']]; |
---|
| 532 | $sqlval['classcategory_name2'] = $arrClassCatName[$arrData['classcategory_id2']]; |
---|
| 533 | $sqlval['point_rate'] = $arrCart[$i]['point_rate']; |
---|
| 534 | $sqlval['price'] = $arrCart[$i]['price']; |
---|
| 535 | $sqlval['quantity'] = $arrCart[$i]['quantity']; |
---|
| 536 | $this->lfReduceStock($objQuery, $arrCart[$i]['id'], $arrCart[$i]['quantity']); |
---|
| 537 | // INSERTの実行 |
---|
| 538 | $objQuery->insert("dtb_order_detail", $sqlval); |
---|
| 539 | } else { |
---|
| 540 | if (defined("MOBILE_SITE")) { |
---|
| 541 | SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND, "", false, "", true); |
---|
| 542 | } else { |
---|
| 543 | SC_Utils_Ex::sfDispSiteError(CART_NOT_FOUND); |
---|
| 544 | } |
---|
| 545 | } |
---|
| 546 | } |
---|
| 547 | } |
---|
| 548 | |
---|
| 549 | // キャンペーン受注テーブルへ登録 |
---|
| 550 | function lfRegistCampaignOrder(&$objQuery, &$objCampaignSess, $order_id) { |
---|
| 551 | |
---|
| 552 | // 受注データを取得 |
---|
| 553 | $cols = "order_id, campaign_id, customer_id, message, order_name01, order_name02,". |
---|
| 554 | "order_kana01, order_kana02, order_email, order_tel01, order_tel02, order_tel03,". |
---|
| 555 | "order_fax01, order_fax02, order_fax03, order_zip01, order_zip02, order_pref, order_addr01,". |
---|
| 556 | "order_addr02, order_sex, order_birth, order_job, deliv_name01, deliv_name02, deliv_kana01,". |
---|
| 557 | "deliv_kana02, deliv_tel01, deliv_tel02, deliv_tel03, deliv_fax01, deliv_fax02, deliv_fax03,". |
---|
| 558 | "deliv_zip01, deliv_zip02, deliv_pref, deliv_addr01, deliv_addr02, payment_total"; |
---|
| 559 | |
---|
| 560 | $arrOrder = $objQuery->select($cols, "dtb_order", "order_id = ?", array($order_id)); |
---|
| 561 | |
---|
| 562 | $sqlval = $arrOrder[0]; |
---|
| 563 | $sqlval['create_date'] = 'Now()'; |
---|
| 564 | |
---|
| 565 | // INSERTの実行 |
---|
| 566 | $objQuery->insert("dtb_campaign_order", $sqlval); |
---|
| 567 | |
---|
| 568 | // 申し込み数の更新 |
---|
| 569 | $total_count = $objQuery->get("dtb_campaign", "total_count", "campaign_id = ?", array($sqlval['campaign_id'])); |
---|
| 570 | $arrCampaign['total_count'] = $total_count += 1; |
---|
| 571 | $objQuery->update("dtb_campaign", $arrCampaign, "campaign_id = ?", array($sqlval['campaign_id'])); |
---|
| 572 | |
---|
| 573 | } |
---|
| 574 | |
---|
| 575 | |
---|
| 576 | |
---|
| 577 | /* 受注一時テーブルの削除 */ |
---|
| 578 | function lfDeleteTempOrder(&$objQuery, $uniqid) { |
---|
| 579 | $where = "order_temp_id = ?"; |
---|
| 580 | $sqlval['del_flg'] = 1; |
---|
| 581 | $objQuery->update("dtb_order_temp", $sqlval, $where, array($uniqid)); |
---|
| 582 | // $objQuery->delete("dtb_order_temp", $where, array($uniqid)); |
---|
| 583 | } |
---|
| 584 | |
---|
| 585 | // 受注一時テーブルの住所が登録済みテーブルと異なる場合は、別のお届け先に追加する |
---|
| 586 | function lfSetNewAddr($uniqid, $customer_id) { |
---|
| 587 | $objQuery = new SC_Query(); |
---|
| 588 | $diff = false; |
---|
| 589 | $find_same = false; |
---|
| 590 | |
---|
| 591 | $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"; |
---|
| 592 | $where = "order_temp_id = ?"; |
---|
| 593 | $arrRet = $objQuery->select($col, "dtb_order_temp", $where, array($uniqid)); |
---|
| 594 | |
---|
| 595 | // 要素名のdeliv_を削除する。 |
---|
| 596 | foreach($arrRet[0] as $key => $val) { |
---|
| 597 | $keyname = ereg_replace("^deliv_", "", $key); |
---|
| 598 | $arrNew[$keyname] = $val; |
---|
| 599 | } |
---|
| 600 | |
---|
| 601 | // 会員情報テーブルとの比較 |
---|
| 602 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
---|
| 603 | $where = "customer_id = ?"; |
---|
| 604 | $arrCustomerAddr = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
---|
| 605 | |
---|
| 606 | // 会員情報の住所と異なる場合 |
---|
| 607 | if($arrNew != $arrCustomerAddr[0]) { |
---|
| 608 | // 別のお届け先テーブルの住所と比較する |
---|
| 609 | $col = "name01,name02,kana01,kana02,tel01,tel02,tel03,zip01,zip02,pref,addr01,addr02"; |
---|
| 610 | $where = "customer_id = ?"; |
---|
| 611 | $arrOtherAddr = $objQuery->select($col, "dtb_other_deliv", $where, array($customer_id)); |
---|
| 612 | |
---|
| 613 | foreach($arrOtherAddr as $arrval) { |
---|
| 614 | if($arrNew == $arrval) { |
---|
| 615 | // すでに同じ住所が登録されている |
---|
| 616 | $find_same = true; |
---|
| 617 | } |
---|
| 618 | } |
---|
| 619 | |
---|
| 620 | if(!$find_same) { |
---|
| 621 | $diff = true; |
---|
| 622 | } |
---|
| 623 | } |
---|
| 624 | |
---|
| 625 | // 新しいお届け先が登録済みのものと異なる場合は別のお届け先テーブルに登録する |
---|
| 626 | if($diff) { |
---|
| 627 | $sqlval = $arrNew; |
---|
| 628 | $sqlval['customer_id'] = $customer_id; |
---|
| 629 | $objQuery->insert("dtb_other_deliv", $sqlval); |
---|
| 630 | } |
---|
| 631 | } |
---|
| 632 | |
---|
| 633 | /* 購入情報を会員テーブルに登録する */ |
---|
| 634 | function lfSetCustomerPurchase($customer_id, $arrData, &$objQuery) { |
---|
| 635 | $col = "first_buy_date, last_buy_date, buy_times, buy_total"; |
---|
| 636 | $where = "customer_id = ?"; |
---|
| 637 | $arrRet = $objQuery->select($col, "dtb_customer", $where, array($customer_id)); |
---|
| 638 | $sqlval = $arrRet[0]; |
---|
| 639 | |
---|
| 640 | if($sqlval['first_buy_date'] == "") { |
---|
| 641 | $sqlval['first_buy_date'] = "Now()"; |
---|
| 642 | } |
---|
| 643 | $sqlval['last_buy_date'] = "Now()"; |
---|
| 644 | $sqlval['buy_times']++; |
---|
| 645 | $sqlval['buy_total']+= $arrData['total']; |
---|
| 646 | |
---|
| 647 | $objQuery->update("dtb_customer", $sqlval, $where, array($customer_id)); |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | // 在庫を減らす処理 |
---|
| 651 | function lfReduceStock(&$objQuery, $arrID, $quantity) { |
---|
| 652 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 653 | |
---|
| 654 | $where = "product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?"; |
---|
| 655 | $arrRet = $objQuery->select("stock, stock_unlimited", "dtb_products_class", $where, $arrID); |
---|
| 656 | |
---|
| 657 | // 売り切れエラー |
---|
| 658 | if(($arrRet[0]['stock_unlimited'] != '1' && $arrRet[0]['stock'] < $quantity) || $quantity == 0) { |
---|
| 659 | $objQuery->rollback(); |
---|
| 660 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, "", true); |
---|
| 661 | // 無制限の場合、在庫はNULL |
---|
| 662 | } elseif($arrRet[0]['stock_unlimited'] == '1') { |
---|
| 663 | $sqlval['stock'] = null; |
---|
| 664 | $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); |
---|
| 665 | // 在庫を減らす |
---|
| 666 | } else { |
---|
| 667 | $sqlval['stock'] = ($arrRet[0]['stock'] - $quantity); |
---|
| 668 | if($sqlval['stock'] == "") { |
---|
| 669 | $sqlval['stock'] = '0'; |
---|
| 670 | } |
---|
| 671 | $objQuery->update("dtb_products_class", $sqlval, $where, $arrID); |
---|
| 672 | } |
---|
| 673 | |
---|
| 674 | // 在庫無し商品の非表示対応 |
---|
| 675 | if (NOSTOCK_HIDDEN === true) { |
---|
| 676 | // 件数カウントバッチ実行 |
---|
| 677 | $objDb->sfCategory_Count($objQuery); |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | } |
---|
| 681 | |
---|
| 682 | // GETの値をインサート用に整える |
---|
| 683 | function lfGetInsParam($sqlVal){ |
---|
| 684 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 685 | foreach($_GET as $key => $val){ |
---|
| 686 | // カラムの存在チェック |
---|
| 687 | if($objDb->sfColumnExists("dtb_order", $key)) $sqlVal[$key] = $val; |
---|
| 688 | } |
---|
| 689 | |
---|
| 690 | return $sqlVal; |
---|
| 691 | } |
---|
| 692 | } |
---|
| 693 | ?> |
---|