source: branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 19868

Revision 19868, 20.9 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

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