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

Revision 18859, 23.4 KB checked in by nanasess, 14 years ago (diff)

ページ間の遷移方法の改善(#783)

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