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