| 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 | require_once(DATA_PATH . 'module/Services/JSON.php'); |
---|
| 27 | |
---|
| 28 | /** |
---|
| 29 | * 支払い方法選択 のページクラス. |
---|
| 30 | * |
---|
| 31 | * @package Page |
---|
| 32 | * @author LOCKON CO.,LTD. |
---|
| 33 | * @version $Id:LC_Page_Shopping_Payment.php 15532 2009-10-30 20:04:46Z satou $ |
---|
| 34 | */ |
---|
| 35 | class LC_Page_Shopping_Payment extends LC_Page { |
---|
| 36 | |
---|
| 37 | // {{{ properties |
---|
| 38 | |
---|
| 39 | /** フォームパラメータの配列 */ |
---|
| 40 | var $objFormParam; |
---|
| 41 | |
---|
| 42 | /** 顧客情報のインスタンス */ |
---|
| 43 | var $objCustomer; |
---|
| 44 | |
---|
| 45 | // }}} |
---|
| 46 | // {{{ functions |
---|
| 47 | |
---|
| 48 | /** |
---|
| 49 | * Page を初期化する. |
---|
| 50 | * |
---|
| 51 | * @return void |
---|
| 52 | */ |
---|
| 53 | function init() { |
---|
| 54 | parent::init(); |
---|
| 55 | $this->tpl_mainpage = "shopping/payment.tpl"; |
---|
| 56 | $this->tpl_column_num = 1; |
---|
| 57 | $this->tpl_onload = "fnCheckInputPoint(); fnSetDelivTime('payment','payment_id','deliv_time_id');"; |
---|
| 58 | $this->tpl_title = "お支払方法・お届け時間等の指定"; |
---|
| 59 | } |
---|
| 60 | |
---|
| 61 | /** |
---|
| 62 | * Page のプロセス. |
---|
| 63 | * |
---|
| 64 | * @return void |
---|
| 65 | */ |
---|
| 66 | function process() { |
---|
| 67 | global $objCampaignSess; |
---|
| 68 | |
---|
| 69 | $objView = new SC_SiteView(); |
---|
| 70 | $objSiteSess = new SC_SiteSession(); |
---|
| 71 | $objCartSess = new SC_CartSession(); |
---|
| 72 | $objCampaignSess = new SC_CampaignSession(); |
---|
| 73 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 74 | $this->objCustomer = new SC_Customer(); |
---|
| 75 | |
---|
| 76 | // パラメータ管理クラス |
---|
| 77 | $this->objFormParam = new SC_FormParam(); |
---|
| 78 | // パラメータ情報の初期化 |
---|
| 79 | $this->lfInitParam(); |
---|
| 80 | // POST値の取得 |
---|
| 81 | $this->objFormParam->setParam($_POST); |
---|
| 82 | |
---|
| 83 | // ユーザユニークIDの取得と購入状態の正当性をチェック |
---|
| 84 | $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess); |
---|
| 85 | // ユニークIDを引き継ぐ |
---|
| 86 | $this->tpl_uniqid = $uniqid; |
---|
| 87 | |
---|
| 88 | //ダウンロード商品判定 |
---|
| 89 | $this->cartdown = $objDb->chkCartDown($objCartSess); |
---|
| 90 | |
---|
| 91 | // 会員ログインチェック |
---|
| 92 | if($this->objCustomer->isLoginSuccess()) { |
---|
| 93 | $this->tpl_login = '1'; |
---|
| 94 | $this->tpl_user_point = $this->objCustomer->getValue('point'); |
---|
| 95 | //戻り先URL |
---|
| 96 | if ($this->cartdown == 2) { |
---|
| 97 | // ダウンロード商品のみの場合はカート画面へ戻る |
---|
| 98 | $this->tpl_back_url = URL_CART_TOP; |
---|
| 99 | } else { |
---|
| 100 | $this->tpl_back_url = URL_DELIV_TOP; |
---|
| 101 | } |
---|
| 102 | } else { |
---|
| 103 | $this->tpl_back_url = URL_SHOP_TOP . "?from=nonmember"; |
---|
| 104 | } |
---|
| 105 | |
---|
| 106 | // 一時受注テーブルの読込 |
---|
| 107 | $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid); |
---|
| 108 | //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す) |
---|
| 109 | if (!$arrOrderTemp) { |
---|
| 110 | $this->sendRedirect($this->getLocation(URL_CART_TOP)); |
---|
| 111 | exit; |
---|
| 112 | } |
---|
| 113 | |
---|
| 114 | // カート内商品の集計処理を行う |
---|
| 115 | $this->cartKey = $_SESSION['cartKey']; |
---|
| 116 | $this->cartItems = $objCartSess->getCartList($this->cartKey); |
---|
| 117 | $this->tpl_message = $objCartSess->checkProducts($this->cartKey); |
---|
| 118 | |
---|
| 119 | if (strlen($this->tpl_message) >= 1) { |
---|
| 120 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true); |
---|
| 121 | } |
---|
| 122 | // FIXME 使用ポイント, 配送都道府県, 支払い方法, 手数料の扱い |
---|
| 123 | $this->arrData = $objCartSess->calculate($this->cartKey, $objCustomer); |
---|
| 124 | |
---|
| 125 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
| 126 | |
---|
| 127 | switch($_POST['mode']) { |
---|
| 128 | case 'confirm': |
---|
| 129 | // 入力値の変換 |
---|
| 130 | $this->objFormParam->convParam(); |
---|
| 131 | $this->arrErr = $this->lfCheckError($this->arrData); |
---|
| 132 | // 入力エラーなし |
---|
| 133 | if(count($this->arrErr) == 0) { |
---|
| 134 | // DBへのデータ登録 |
---|
| 135 | $this->lfRegistData($uniqid); |
---|
| 136 | // 正常に登録されたことを記録しておく |
---|
| 137 | $objSiteSess->setRegistFlag(); |
---|
| 138 | // 確認ページへ移動 |
---|
| 139 | $this->sendRedirect($this->getLocation(URL_SHOP_CONFIRM, array(), true)); |
---|
| 140 | exit; |
---|
| 141 | }else{ |
---|
| 142 | // ユーザユニークIDの取得 |
---|
| 143 | $uniqid = $objSiteSess->getUniqId(); |
---|
| 144 | // 受注一時テーブルからの情報を格納 |
---|
| 145 | $this->lfSetOrderTempData($uniqid); |
---|
| 146 | } |
---|
| 147 | break; |
---|
| 148 | // 前のページに戻る |
---|
| 149 | case 'return': |
---|
| 150 | // 非会員の場合 |
---|
| 151 | // 正常な推移であることを記録しておく |
---|
| 152 | $objSiteSess->setRegistFlag(); |
---|
| 153 | $this->sendRedirect(URL_SHOP_TOP); |
---|
| 154 | exit; |
---|
| 155 | break; |
---|
| 156 | // 支払い方法が変更された場合 |
---|
| 157 | case 'payment': |
---|
| 158 | // 配送時間の配列を生成 |
---|
| 159 | $this->lfSetDelivTime(); |
---|
| 160 | break; |
---|
| 161 | default: |
---|
| 162 | // 受注一時テーブルからの情報を格納 |
---|
| 163 | $this->lfSetOrderTempData($uniqid); |
---|
| 164 | break; |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | // 購入金額の取得 |
---|
| 168 | $total_pretax = $objCartSess->getAllProductsTotal($this->cartKey); |
---|
| 169 | // 支払い方法の取得 |
---|
| 170 | $this->arrPayment = $this->lfGetPayment($total_pretax); |
---|
| 171 | // 支払い方法の画像があるなしを取得($img_show true:ある false:なし) |
---|
| 172 | $this->img_show = $this->lfGetImgShow($this->arrPayment); |
---|
| 173 | // お届け日一覧の取得 |
---|
| 174 | $this->arrDelivDate = $this->lfGetDelivDate(); |
---|
| 175 | |
---|
| 176 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
| 177 | |
---|
| 178 | $objView->assignobj($this); |
---|
| 179 | // フレームを選択(キャンペーンページから遷移なら変更) |
---|
| 180 | $objCampaignSess->pageView($objView); |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | /** |
---|
| 184 | * モバイルページを初期化する. |
---|
| 185 | * |
---|
| 186 | * @return void |
---|
| 187 | */ |
---|
| 188 | function mobileInit() { |
---|
| 189 | $this->init(); |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | /** |
---|
| 193 | * Page のプロセス(モバイル). |
---|
| 194 | * |
---|
| 195 | * @return void |
---|
| 196 | */ |
---|
| 197 | function mobileProcess() { |
---|
| 198 | $objView = new SC_MobileView(); |
---|
| 199 | $objSiteSess = new SC_SiteSession(); |
---|
| 200 | $objCartSess = new SC_CartSession(); |
---|
| 201 | $this->objCustomer = new SC_Customer(); |
---|
| 202 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 203 | |
---|
| 204 | // パラメータ管理クラス |
---|
| 205 | $this->objFormParam = new SC_FormParam(); |
---|
| 206 | // パラメータ情報の初期化 |
---|
| 207 | $this->lfInitParam(); |
---|
| 208 | // POST値の取得 |
---|
| 209 | $this->objFormParam->setParam($_POST); |
---|
| 210 | |
---|
| 211 | // ユーザユニークIDの取得と購入状態の正当性をチェック |
---|
| 212 | $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess); |
---|
| 213 | // ユニークIDを引き継ぐ |
---|
| 214 | $this->tpl_uniqid = $uniqid; |
---|
| 215 | |
---|
| 216 | //ダウンロード商品判定 |
---|
| 217 | $this->cartdown = $objDb->chkCartDown($objCartSess); |
---|
| 218 | |
---|
| 219 | // 会員ログインチェック |
---|
| 220 | if($this->objCustomer->isLoginSuccess(true)) { |
---|
| 221 | $this->tpl_login = '1'; |
---|
| 222 | $this->tpl_user_point = $this->objCustomer->getValue('point'); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | // 一時受注テーブルの読込 |
---|
| 226 | $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid); |
---|
| 227 | //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す) |
---|
| 228 | if (!$arrOrderTemp) { |
---|
| 229 | $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP)); |
---|
| 230 | exit; |
---|
| 231 | } |
---|
| 232 | |
---|
| 233 | // 金額の取得 (購入途中で売り切れた場合にはこの関数内にてその商品の数量が0になる) |
---|
| 234 | $objDb->sfTotalCart($this, $objCartSess); |
---|
| 235 | if (strlen($this->tpl_message) >= 1) { |
---|
| 236 | SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true); |
---|
| 237 | } |
---|
| 238 | |
---|
| 239 | $this->arrData = $objDb->sfTotalConfirm(array(), $this, $objCartSess); |
---|
| 240 | |
---|
| 241 | if (!isset($_POST['mode'])) $_POST['mode'] = ""; |
---|
| 242 | |
---|
| 243 | // 戻るボタンの処理 |
---|
| 244 | if (!empty($_POST['return'])) { |
---|
| 245 | switch ($_POST['mode']) { |
---|
| 246 | case 'confirm': |
---|
| 247 | $_POST['mode'] = 'payment'; |
---|
| 248 | break; |
---|
| 249 | default: |
---|
| 250 | // 正常な推移であることを記録しておく |
---|
| 251 | $objSiteSess->setRegistFlag(); |
---|
| 252 | if ($this->cartdown == 2) { |
---|
| 253 | // ダウンロード商品のみの場合はカート画面へ戻る |
---|
| 254 | $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP), true); |
---|
| 255 | } else { |
---|
| 256 | $this->sendRedirect(MOBILE_URL_SHOP_TOP, true); |
---|
| 257 | } |
---|
| 258 | exit; |
---|
| 259 | } |
---|
| 260 | } |
---|
| 261 | |
---|
| 262 | // ダウンロード商品のみで、モードがお届け日時指定の場合はモードを変更 |
---|
| 263 | if ($this->cartdown == 2 && $_POST['mode'] == 'deliv_date') { |
---|
| 264 | $_POST['mode'] = 'confirm'; |
---|
| 265 | } |
---|
| 266 | |
---|
| 267 | switch($_POST['mode']) { |
---|
| 268 | // 支払い方法指定 → お届け日時指定 |
---|
| 269 | case 'deliv_date': |
---|
| 270 | // 入力値の変換 |
---|
| 271 | $this->objFormParam->convParam(); |
---|
| 272 | $this->arrErr = $this->lfCheckError($this->arrData); |
---|
| 273 | if (!isset($this->arrErr['payment_id'])) { |
---|
| 274 | // 支払い方法の入力エラーなし |
---|
| 275 | $this->tpl_mainpage = 'shopping/deliv_date.tpl'; |
---|
| 276 | $this->tpl_title = "お届け日時指定"; |
---|
| 277 | break; |
---|
| 278 | } else { |
---|
| 279 | // ユーザユニークIDの取得 |
---|
| 280 | $uniqid = $objSiteSess->getUniqId(); |
---|
| 281 | // 受注一時テーブルからの情報を格納 |
---|
| 282 | $this->lfSetOrderTempData($uniqid); |
---|
| 283 | } |
---|
| 284 | break; |
---|
| 285 | case 'confirm': |
---|
| 286 | // 入力値の変換 |
---|
| 287 | $this->objFormParam->convParam(); |
---|
| 288 | $this->arrErr = $this->lfCheckError($this->arrData); |
---|
| 289 | // 入力エラーなし |
---|
| 290 | if(count($this->arrErr) == 0) { |
---|
| 291 | // DBへのデータ登録 |
---|
| 292 | $this->lfRegistData($uniqid); |
---|
| 293 | // 正常に登録されたことを記録しておく |
---|
| 294 | $objSiteSess->setRegistFlag(); |
---|
| 295 | // 確認ページへ移動 |
---|
| 296 | $this->sendRedirect($this->getLocation(MOBILE_URL_SHOP_CONFIRM), true); |
---|
| 297 | exit; |
---|
| 298 | }else{ |
---|
| 299 | // ユーザユニークIDの取得 |
---|
| 300 | $uniqid = $objSiteSess->getUniqId(); |
---|
| 301 | // 受注一時テーブルからの情報を格納 |
---|
| 302 | $this->lfSetOrderTempData($uniqid); |
---|
| 303 | if (!isset($this->arrErr['payment_id'])) { |
---|
| 304 | // 支払い方法の入力エラーなし |
---|
| 305 | $this->tpl_mainpage = 'shopping/deliv_date.tpl'; |
---|
| 306 | $this->tpl_title = "お届け日時指定"; |
---|
| 307 | } |
---|
| 308 | } |
---|
| 309 | break; |
---|
| 310 | // 前のページに戻る |
---|
| 311 | case 'return': |
---|
| 312 | // 非会員の場合 |
---|
| 313 | // 正常な推移であることを記録しておく |
---|
| 314 | $objSiteSess->setRegistFlag(); |
---|
| 315 | $this->sendRedirect(MOBILE_URL_SHOP_TOP, true); |
---|
| 316 | exit; |
---|
| 317 | break; |
---|
| 318 | // 支払い方法が変更された場合 |
---|
| 319 | case 'payment': |
---|
| 320 | // ここのbreakは、意味があるので外さないで下さい。 |
---|
| 321 | break; |
---|
| 322 | default: |
---|
| 323 | // 受注一時テーブルからの情報を格納 |
---|
| 324 | $this->lfSetOrderTempData($uniqid); |
---|
| 325 | break; |
---|
| 326 | } |
---|
| 327 | |
---|
| 328 | // 購入金額の取得得 |
---|
| 329 | $total_pretax = $objCartSess->getAllProductsTotal(); |
---|
| 330 | // 支払い方法の取得 |
---|
| 331 | $this->arrPayment = $this->lfGetPayment($total_pretax); |
---|
| 332 | // お届け時間の取得 |
---|
| 333 | $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id')); |
---|
| 334 | $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time'); |
---|
| 335 | |
---|
| 336 | // お届け日一覧の取得 |
---|
| 337 | $this->arrDelivDate = $this->lfGetDelivDate(); |
---|
| 338 | |
---|
| 339 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
| 340 | |
---|
| 341 | $objView->assignobj($this); |
---|
| 342 | $objView->display(SITE_FRAME); |
---|
| 343 | } |
---|
| 344 | |
---|
| 345 | /** |
---|
| 346 | * デストラクタ. |
---|
| 347 | * |
---|
| 348 | * @return void |
---|
| 349 | */ |
---|
| 350 | function destroy() { |
---|
| 351 | parent::destroy(); |
---|
| 352 | } |
---|
| 353 | |
---|
| 354 | /* パラメータ情報の初期化 */ |
---|
| 355 | function lfInitParam() { |
---|
| 356 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 357 | $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START")); |
---|
| 358 | $this->objFormParam->addParam("お届け時間", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
| 359 | $this->objFormParam->addParam("ご質問", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
| 360 | $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2'); |
---|
| 361 | $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
| 362 | } |
---|
| 363 | |
---|
| 364 | function lfGetPayment($total_pretax) { |
---|
| 365 | $objQuery = new SC_Query(); |
---|
| 366 | $objQuery->setOrder("rank DESC"); |
---|
| 367 | |
---|
| 368 | //削除されていない支払方法を取得 |
---|
| 369 | $arrval = null; |
---|
| 370 | $where = "del_flg = 0 AND deliv_id IN (SELECT deliv_id FROM dtb_deliv WHERE del_flg = 0) "; |
---|
| 371 | |
---|
| 372 | //ダウンロード商品の有無判定 |
---|
| 373 | if($this->cartdown != 0){ |
---|
| 374 | //ダウンロード商品を含む場合は、オンライン決済以外は選択できない。 |
---|
| 375 | $arrval = explode(",", ONLINE_PAYMENT); |
---|
| 376 | $tmp_where = ""; |
---|
| 377 | foreach ($arrval as $val) { |
---|
| 378 | if($tmp_where == "") { |
---|
| 379 | $tmp_where.= "AND payment_id IN ( ?"; |
---|
| 380 | } else { |
---|
| 381 | $tmp_where.= ",? "; |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | $tmp_where.= " ) "; |
---|
| 385 | $where .= $tmp_where; |
---|
| 386 | } |
---|
| 387 | |
---|
| 388 | // 削除されていない支払方法を取得 |
---|
| 389 | $arrRet = $objQuery->select("payment_id, payment_method, rule, upper_rule, note, payment_image", "dtb_payment", $where, $arrval); |
---|
| 390 | |
---|
| 391 | // 配列初期化 |
---|
| 392 | $data = array(); |
---|
| 393 | // 選択可能な支払方法を判定 |
---|
| 394 | foreach($arrRet as $data) { |
---|
| 395 | //ダウンロード販売に対する注意追加 |
---|
| 396 | if($this->cartdown != 0){ |
---|
| 397 | $data['payment_method'] = $data['payment_method'] . " (ダウンロード商品を含む場合、オンライン決済のみ選択可能です)"; |
---|
| 398 | } |
---|
| 399 | // 下限と上限が設定されている |
---|
| 400 | if (strlen($data['rule']) != 0 && strlen($data['upper_rule']) != 0) { |
---|
| 401 | if ($data['rule'] <= $total_pretax && $data['upper_rule'] >= $total_pretax) { |
---|
| 402 | $arrPayment[] = $data; |
---|
| 403 | } |
---|
| 404 | } |
---|
| 405 | // 下限のみ設定されている |
---|
| 406 | elseif (strlen($data['rule']) != 0) { |
---|
| 407 | if($data['rule'] <= $total_pretax) { |
---|
| 408 | $arrPayment[] = $data; |
---|
| 409 | } |
---|
| 410 | } |
---|
| 411 | // 上限のみ設定されている |
---|
| 412 | elseif (strlen($data['upper_rule']) != 0) { |
---|
| 413 | if($data['upper_rule'] >= $total_pretax) { |
---|
| 414 | $arrPayment[] = $data; |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | // いずれも設定なし |
---|
| 418 | else { |
---|
| 419 | $arrPayment[] = $data; |
---|
| 420 | } |
---|
| 421 | } |
---|
| 422 | return $arrPayment; |
---|
| 423 | } |
---|
| 424 | |
---|
| 425 | /* 入力内容のチェック */ |
---|
| 426 | function lfCheckError($arrData) { |
---|
| 427 | // 入力データを渡す。 |
---|
| 428 | $arrRet = $this->objFormParam->getHashArray(); |
---|
| 429 | $objErr = new SC_CheckError($arrRet); |
---|
| 430 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
| 431 | |
---|
| 432 | if (USE_POINT === false) { |
---|
| 433 | $_POST['point_check'] = ""; |
---|
| 434 | $_POST['use_point'] = "0"; |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | if (!isset($_POST['point_check'])) $_POST['point_check'] = ""; |
---|
| 438 | |
---|
| 439 | if($_POST['point_check'] == '1') { |
---|
| 440 | $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK")); |
---|
| 441 | $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK")); |
---|
| 442 | $max_point = $this->objCustomer->getValue('point'); |
---|
| 443 | if($max_point == "") { |
---|
| 444 | $max_point = 0; |
---|
| 445 | } |
---|
| 446 | // FIXME mobile 互換のため br は閉じない... |
---|
| 447 | if($arrRet['use_point'] > $max_point) { |
---|
| 448 | $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>"; |
---|
| 449 | } |
---|
| 450 | if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) { |
---|
| 451 | $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>"; |
---|
| 452 | } |
---|
| 453 | } |
---|
| 454 | |
---|
| 455 | $objCartSess = new SC_CartSession(); |
---|
| 456 | // 購入金額の取得得 |
---|
| 457 | $total_pretax = $objCartSess->getAllProductsTotal(); |
---|
| 458 | // 支払い方法の取得 |
---|
| 459 | $arrPayment = $this->lfGetPayment($total_pretax); |
---|
| 460 | $pay_flag = true; |
---|
| 461 | foreach ($arrPayment as $key => $payment) { |
---|
| 462 | if ($payment['payment_id'] == $arrRet['payment_id']) { |
---|
| 463 | $pay_flag = false; |
---|
| 464 | break; |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | if ($pay_flag && $arrRet['payment_id'] != "") { |
---|
| 468 | SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | return $objErr->arrErr; |
---|
| 472 | } |
---|
| 473 | |
---|
| 474 | /* 支払い方法文字列の取得 */ |
---|
| 475 | function lfGetPaymentInfo($payment_id) { |
---|
| 476 | $objQuery = new SC_Query(); |
---|
| 477 | $where = "payment_id = ?"; |
---|
| 478 | $arrRet = $objQuery->select("charge, deliv_id", "dtb_payment", $where, array($payment_id)); |
---|
| 479 | return (array($arrRet[0]['charge'], $arrRet[0]['deliv_id'])); |
---|
| 480 | } |
---|
| 481 | |
---|
| 482 | /* DBへデータの登録 */ |
---|
| 483 | function lfRegistData($uniqid) { |
---|
| 484 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 485 | |
---|
| 486 | $sqlval = $this->objFormParam->getDbArray(); |
---|
| 487 | // 登録データの作成 |
---|
| 488 | $sqlval['order_temp_id'] = $uniqid; |
---|
| 489 | $sqlval['update_date'] = 'Now()'; |
---|
| 490 | |
---|
| 491 | if (strlen($sqlval['payment_id']) >= 1) { |
---|
| 492 | list($sqlval['charge'], $sqlval['deliv_id']) = $this->lfGetPaymentInfo($sqlval['payment_id']); |
---|
| 493 | } |
---|
| 494 | |
---|
| 495 | // 使用ポイントの設定 |
---|
| 496 | if($sqlval['point_check'] != '1') { |
---|
| 497 | $sqlval['use_point'] = 0; |
---|
| 498 | } |
---|
| 499 | |
---|
| 500 | // 受注_Tempテーブルに登録 |
---|
| 501 | $objDb->sfRegistTempOrder($uniqid, $sqlval); |
---|
| 502 | } |
---|
| 503 | |
---|
| 504 | /* お届け日一覧を取得する */ |
---|
| 505 | function lfGetDelivDate() { |
---|
| 506 | $objCartSess = new SC_CartSession(); |
---|
| 507 | $objQuery = new SC_Query(); |
---|
| 508 | // 商品IDの取得 |
---|
| 509 | $max = $objCartSess->getMax(); |
---|
| 510 | for($i = 1; $i <= $max; $i++) { |
---|
| 511 | if($_SESSION[$objCartSess->key][$i]['id'][0] != "") { |
---|
| 512 | $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0]; |
---|
| 513 | } |
---|
| 514 | } |
---|
| 515 | if(count($arrID['product_id']) > 0) { |
---|
| 516 | $id = implode(",", $arrID['product_id']); |
---|
| 517 | //商品から発送目安の取得 |
---|
| 518 | $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")"); |
---|
| 519 | //発送目安 |
---|
| 520 | switch($deliv_date) { |
---|
| 521 | //即日発送 |
---|
| 522 | case '1': |
---|
| 523 | $start_day = 1; |
---|
| 524 | break; |
---|
| 525 | //1-2日後 |
---|
| 526 | case '2': |
---|
| 527 | $start_day = 3; |
---|
| 528 | break; |
---|
| 529 | //3-4日後 |
---|
| 530 | case '3': |
---|
| 531 | $start_day = 5; |
---|
| 532 | break; |
---|
| 533 | //1週間以内 |
---|
| 534 | case '4': |
---|
| 535 | $start_day = 8; |
---|
| 536 | break; |
---|
| 537 | //2週間以内 |
---|
| 538 | case '5': |
---|
| 539 | $start_day = 15; |
---|
| 540 | break; |
---|
| 541 | //3週間以内 |
---|
| 542 | case '6': |
---|
| 543 | $start_day = 22; |
---|
| 544 | break; |
---|
| 545 | //1ヶ月以内 |
---|
| 546 | case '7': |
---|
| 547 | $start_day = 32; |
---|
| 548 | break; |
---|
| 549 | //2ヶ月以降 |
---|
| 550 | case '8': |
---|
| 551 | $start_day = 62; |
---|
| 552 | break; |
---|
| 553 | //お取り寄せ(商品入荷後) |
---|
| 554 | case '9': |
---|
| 555 | $start_day = ""; |
---|
| 556 | break; |
---|
| 557 | default: |
---|
| 558 | //お届け日が設定されていない場合 |
---|
| 559 | $start_day = ""; |
---|
| 560 | break; |
---|
| 561 | } |
---|
| 562 | //お届け可能日のスタート値から、お届け日の配列を取得する |
---|
| 563 | $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX); |
---|
| 564 | } |
---|
| 565 | return $arrDelivDate; |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | //お届け可能日のスタート値から、お届け日の配列を取得する |
---|
| 569 | function lfGetDateArray($start_day, $end_day) { |
---|
| 570 | $masterData = new SC_DB_MasterData(); |
---|
| 571 | $arrWDAY = $masterData->getMasterData("mtb_wday"); |
---|
| 572 | //お届け可能日のスタート値がセットされていれば |
---|
| 573 | if($start_day >= 1) { |
---|
| 574 | $now_time = time(); |
---|
| 575 | $max_day = $start_day + $end_day; |
---|
| 576 | // 集計 |
---|
| 577 | for ($i = $start_day; $i < $max_day; $i++) { |
---|
| 578 | // 基本時間から日数を追加していく |
---|
| 579 | $tmp_time = $now_time + ($i * 24 * 3600); |
---|
| 580 | list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time)); |
---|
| 581 | $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]); |
---|
| 582 | $arrDate[$val] = $val; |
---|
| 583 | } |
---|
| 584 | } else { |
---|
| 585 | $arrDate = false; |
---|
| 586 | } |
---|
| 587 | return $arrDate; |
---|
| 588 | } |
---|
| 589 | |
---|
| 590 | //一時受注テーブルからの情報を格納する |
---|
| 591 | function lfSetOrderTempData($uniqid) { |
---|
| 592 | $objQuery = new SC_Query(); |
---|
| 593 | $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date"; |
---|
| 594 | $from = "dtb_order_temp"; |
---|
| 595 | $where = "order_temp_id = ?"; |
---|
| 596 | $arrRet = $objQuery->select($col, $from, $where, array($uniqid)); |
---|
| 597 | // DB値の取得 |
---|
| 598 | $this->objFormParam->setParam($arrRet[0]); |
---|
| 599 | return $this->objFormParam; |
---|
| 600 | } |
---|
| 601 | |
---|
| 602 | /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */ |
---|
| 603 | function lfGetImgShow($arrPayment) { |
---|
| 604 | $img_show = false; |
---|
| 605 | foreach ($this->arrPayment as $payment) { |
---|
| 606 | if (strlen($payment["payment_image"]) > 0 ){ |
---|
| 607 | $img_show = true; |
---|
| 608 | break; |
---|
| 609 | } |
---|
| 610 | } |
---|
| 611 | return $img_show; |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | /* 配送時間の配列を生成 */ |
---|
| 615 | function lfSetDelivTime() { |
---|
| 616 | $objDb = new SC_Helper_DB_Ex(); |
---|
| 617 | $objJson = new Services_JSON; |
---|
| 618 | |
---|
| 619 | // 配送時間の取得 |
---|
| 620 | $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id')); |
---|
| 621 | // JSONエンコード |
---|
| 622 | echo $objJson->encode($arrRet); |
---|
| 623 | exit; |
---|
| 624 | } |
---|
| 625 | } |
---|
| 626 | ?> |
---|