source: branches/comu-ver2/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 18052

Revision 18052, 19.7 KB checked in by Seasoft, 15 years ago (diff)

・店舗基本情報の取得処理にランタイムのキャッシュ機構を設け、店舗基本情報を深く渡し回す実装を改めた。
・SC_Utils 冒頭のコメントに従い、インスタンスを生成していた処理を、Helper クラスへ移す。計算処理のみ SC_Utils に残す。

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