source: branches/version-2/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 17712

Revision 17712, 20.6 KB checked in by nakanishi, 15 years ago (diff)

#397 お支払方法選択ページで決済方法を指定しないで画面遷移した時に不正アクセスと表示されてしまう問題を修正。

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