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

Revision 19680, 23.1 KB checked in by Seasoft, 13 years ago (diff)

#627(ソース整形・ソースコメントの改善)

  • 「pretax」は収入に関する税込みを意味する英単語だと思いますので、より適切と考えられる「including tax」を基にした単語「inctax」に書き換えます。またメソッド名としては「calculate」を基にした「calc」を前置するように改めます。英文法・命名規則的に正しいか確信はないのですが少なくとも現状よりは理想に近づくと考えます。
  • 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_PATH . "pages/LC_Page.php");
26require_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 */
35class 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        parent::process();
68        $this->action();
69        $this->sendResponse();
70    }
71
72    /**
73     * Page のアクション.
74     *
75     * @return void
76     */
77    function action() {
78        $objSiteSess = new SC_SiteSession();
79        $objCartSess = new SC_CartSession();
80        $objDb = new SC_Helper_DB_Ex();
81        $this->objCustomer = new SC_Customer();
82
83        // パラメータ管理クラス
84        $this->objFormParam = new SC_FormParam();
85        // パラメータ情報の初期化
86        $this->lfInitParam();
87        // POST値の取得
88        $this->objFormParam->setParam($_POST);
89
90        // ユーザユニークIDの取得と購入状態の正当性をチェック
91        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
92        // ユニークIDを引き継ぐ
93        $this->tpl_uniqid = $uniqid;
94
95        //ダウンロード商品判定
96        $this->cartdown = $objDb->chkCartDown($objCartSess);
97
98        // 会員ログインチェック
99        if($this->objCustomer->isLoginSuccess()) {
100            $this->tpl_login = '1';
101            $this->tpl_user_point = $this->objCustomer->getValue('point');
102            //戻り先URL
103            if ($this->cartdown == 2) {
104                // ダウンロード商品のみの場合はカート画面へ戻る
105                $this->tpl_back_url = URL_CART_TOP;
106            } else {
107                $this->tpl_back_url = URL_DELIV_TOP;
108            }
109        } else {
110            $this->tpl_back_url = URL_SHOP_TOP . "?from=nonmember";
111        }
112
113        // 一時受注テーブルの読込
114        $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid);
115        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
116        if (!$arrOrderTemp) {
117            $this->objDisplay->redirect($this->getLocation(URL_CART_TOP));
118            exit;
119        }
120
121        // カート内商品の集計処理を行う
122        $this->cartKey = $_SESSION['cartKey'];
123        $this->cartItems = $objCartSess->getCartList($this->cartKey);
124        $this->tpl_message = $objCartSess->checkProducts($this->cartKey);
125
126        if (strlen($this->tpl_message) >= 1) {
127            SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true);
128        }
129        // FIXME 使用ポイント, 配送都道府県, 支払い方法, 手数料の扱い
130        $this->arrData = $objCartSess->calculate($this->cartKey, $objCustomer);
131
132        if (!isset($_POST['mode'])) $_POST['mode'] = "";
133
134        switch($_POST['mode']) {
135        case 'confirm':
136            // 入力値の変換
137            $this->objFormParam->convParam();
138            $this->arrErr = $this->lfCheckError($this->arrData);
139            // 入力エラーなし
140            if(count($this->arrErr) == 0) {
141                // DBへのデータ登録
142                $this->lfRegistData($uniqid);
143                // 正常に登録されたことを記録しておく
144                $objSiteSess->setRegistFlag();
145                // 確認ページへ移動
146                $this->objDisplay->redirect($this->getLocation(URL_SHOP_CONFIRM, array(), true));
147                exit;
148            }else{
149                // ユーザユニークIDの取得
150                $uniqid = $objSiteSess->getUniqId();
151                // 受注一時テーブルからの情報を格納
152                $this->lfSetOrderTempData($uniqid);
153            }
154            break;
155        // 前のページに戻る
156        case 'return':
157            // 非会員の場合
158            // 正常な推移であることを記録しておく
159            $objSiteSess->setRegistFlag();
160            $this->objDisplay->redirect(URL_SHOP_TOP);
161            exit;
162            break;
163        // 支払い方法が変更された場合
164        case 'payment':
165            // 配送時間の配列を生成
166            $this->lfSetDelivTime();
167            break;
168        default:
169            // 受注一時テーブルからの情報を格納
170            $this->lfSetOrderTempData($uniqid);
171            break;
172        }
173
174        // 購入金額の取得
175        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
176        // 支払い方法の取得
177        $this->arrPayment = $this->lfGetPayment($total_inctax);
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_URL_CART_TOP));
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_URL_CART_TOP));
268                } else {
269                    $this->objDisplay->redirect(MOBILE_URL_SHOP_TOP);
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_URL_SHOP_CONFIRM));
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_URL_SHOP_TOP);
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) {
375        $objQuery = new SC_Query();
376        $objQuery->setOrder("rank DESC");
377
378        //削除されていない支払方法を取得
379        $arrval = null;
380        $where = "del_flg = 0 AND deliv_id IN (SELECT deliv_id FROM dtb_deliv WHERE del_flg = 0) ";
381
382        //ダウンロード商品の有無判定
383        if($this->cartdown != 0){
384            //ダウンロード商品を含む場合は、オンライン決済以外は選択できない。
385            $arrval = explode(",", ONLINE_PAYMENT);
386            $tmp_where = "";
387            foreach ($arrval as $val) {
388                if($tmp_where == "") {
389                    $tmp_where.= "AND payment_id IN ( ?";
390                } else {
391                    $tmp_where.= ",? ";
392                }
393            }
394            $tmp_where.= " ) ";
395            $where .= $tmp_where;
396        }
397
398        // 削除されていない支払方法を取得
399        $arrRet = $objQuery->select("payment_id, payment_method, rule, upper_rule, note, payment_image", "dtb_payment", $where, $arrval);
400
401        // 配列初期化
402        $data = array();
403        // 選択可能な支払方法を判定
404        foreach($arrRet as $data) {
405            //ダウンロード販売に対する注意追加
406            if($this->cartdown != 0){
407                $data['payment_method'] = $data['payment_method'] . "  (ダウンロード商品を含む場合、オンライン決済のみ選択可能です)";
408            }
409            // 下限と上限が設定されている
410            if (strlen($data['rule']) != 0 && strlen($data['upper_rule']) != 0) {
411                if ($data['rule'] <= $total_inctax && $data['upper_rule'] >= $total_inctax) {
412                    $arrPayment[] = $data;
413                }
414            }
415            // 下限のみ設定されている
416            elseif (strlen($data['rule']) != 0) {
417                if($data['rule'] <= $total_inctax) {
418                    $arrPayment[] = $data;
419                }
420            }
421            // 上限のみ設定されている
422            elseif (strlen($data['upper_rule']) != 0) {
423                if($data['upper_rule'] >= $total_inctax) {
424                    $arrPayment[] = $data;
425                }
426            }
427            // いずれも設定なし
428            else {
429                $arrPayment[] = $data;
430            }
431        }
432        return $arrPayment;
433    }
434
435    /* 入力内容のチェック */
436    function lfCheckError($arrData) {
437        // 入力データを渡す。
438        $arrRet =  $this->objFormParam->getHashArray();
439        $objErr = new SC_CheckError($arrRet);
440        $objErr->arrErr = $this->objFormParam->checkError();
441
442        if (USE_POINT === false) {
443            $_POST['point_check'] = "";
444            $_POST['use_point'] = "0";
445        }
446
447        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
448
449        if($_POST['point_check'] == '1') {
450            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
451            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
452            $max_point = $this->objCustomer->getValue('point');
453            if($max_point == "") {
454                $max_point = 0;
455            }
456            // FIXME mobile 互換のため br は閉じない...
457            if($arrRet['use_point'] > $max_point) {
458                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
459            }
460            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
461                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
462            }
463        }
464
465        $objCartSess = new SC_CartSession();
466        // 購入金額の取得得
467        $total_inctax = $objCartSess->getAllProductsTotal();
468        // 支払い方法の取得
469        $arrPayment = $this->lfGetPayment($total_inctax);
470        $pay_flag = true;
471        foreach ($arrPayment as $key => $payment) {
472            if ($payment['payment_id'] == $arrRet['payment_id']) {
473                $pay_flag = false;
474                break;
475            }
476        }
477        if ($pay_flag && $arrRet['payment_id'] != "") {
478            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
479        }
480
481        return $objErr->arrErr;
482    }
483
484    /* 支払い方法文字列の取得 */
485    function lfGetPaymentInfo($payment_id) {
486        $objQuery = new SC_Query();
487        $where = "payment_id = ?";
488        $arrRet = $objQuery->select("charge, deliv_id", "dtb_payment", $where, array($payment_id));
489        return (array($arrRet[0]['charge'], $arrRet[0]['deliv_id']));
490    }
491
492    /* DBへデータの登録 */
493    function lfRegistData($uniqid) {
494        $objDb = new SC_Helper_DB_Ex();
495
496        $sqlval = $this->objFormParam->getDbArray();
497        // 登録データの作成
498        $sqlval['order_temp_id'] = $uniqid;
499        $sqlval['update_date'] = 'Now()';
500
501        if (strlen($sqlval['payment_id']) >= 1) {
502            list($sqlval['charge'], $sqlval['deliv_id']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
503        }
504
505        // 使用ポイントの設定
506        if($sqlval['point_check'] != '1') {
507            $sqlval['use_point'] = 0;
508        }
509
510        // 受注_Tempテーブルに登録
511        $objDb->sfRegistTempOrder($uniqid, $sqlval);
512    }
513
514    /* お届け日一覧を取得する */
515    function lfGetDelivDate() {
516        $objCartSess = new SC_CartSession();
517        $objQuery = new SC_Query();
518        // 商品IDの取得
519        $max = $objCartSess->getMax();
520        for($i = 1; $i <= $max; $i++) {
521            if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
522                $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
523            }
524        }
525        if(count($arrID['product_id']) > 0) {
526            $id = implode(",", $arrID['product_id']);
527            //商品から発送目安の取得
528            $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")");
529            //発送目安
530            switch($deliv_date) {
531            //即日発送
532            case '1':
533                $start_day = 1;
534                break;
535            //1-2日後
536            case '2':
537                $start_day = 3;
538                break;
539            //3-4日後
540            case '3':
541                $start_day = 5;
542                break;
543            //1週間以内
544            case '4':
545                $start_day = 8;
546                break;
547            //2週間以内
548            case '5':
549                $start_day = 15;
550                break;
551            //3週間以内
552            case '6':
553                $start_day = 22;
554                break;
555            //1ヶ月以内
556            case '7':
557                $start_day = 32;
558                break;
559            //2ヶ月以降
560            case '8':
561                $start_day = 62;
562                break;
563            //お取り寄せ(商品入荷後)
564            case '9':
565                $start_day = "";
566                break;
567            default:
568                //お届け日が設定されていない場合
569                $start_day = "";
570                break;
571            }
572            //お届け可能日のスタート値から、お届け日の配列を取得する
573            $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX);
574        }
575        return $arrDelivDate;
576    }
577
578    //お届け可能日のスタート値から、お届け日の配列を取得する
579    function lfGetDateArray($start_day, $end_day) {
580        $masterData = new SC_DB_MasterData();
581        $arrWDAY = $masterData->getMasterData("mtb_wday");
582        //お届け可能日のスタート値がセットされていれば
583        if($start_day >= 1) {
584            $now_time = time();
585            $max_day = $start_day + $end_day;
586            // 集計
587            for ($i = $start_day; $i < $max_day; $i++) {
588                // 基本時間から日数を追加していく
589                $tmp_time = $now_time + ($i * 24 * 3600);
590                list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time));
591                $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
592                $arrDate[$val] = $val;
593            }
594        } else {
595            $arrDate = false;
596        }
597        return $arrDate;
598    }
599
600    //一時受注テーブルからの情報を格納する
601    function lfSetOrderTempData($uniqid) {
602        $objQuery = new SC_Query();
603        $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
604        $from = "dtb_order_temp";
605        $where = "order_temp_id = ?";
606        $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
607        // DB値の取得
608        $this->objFormParam->setParam($arrRet[0]);
609        return $this->objFormParam;
610    }
611
612    /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */
613    function lfGetImgShow($arrPayment) {
614        $img_show = false;
615        foreach ($this->arrPayment as $payment) {
616            if (strlen($payment["payment_image"]) > 0 ){
617                $img_show = true;
618                break;
619            }
620        }
621        return $img_show;
622    }
623
624    /* 配送時間の配列を生成 */
625    function lfSetDelivTime() {
626        $objDb = new SC_Helper_DB_Ex();
627        $objJson = new Services_JSON;
628
629        // 配送時間の取得
630        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
631        // JSONエンコード
632        echo $objJson->encode($arrRet);
633        exit;
634    }
635}
636?>
Note: See TracBrowser for help on using the repository browser.