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

Revision 19833, 22.5 KB checked in by Seasoft, 13 years ago (diff)

#834(パラメータの定数名に「URL」を含むにもかかわらず、パスのみのものがある)

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