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

Revision 20112, 14.2 KB checked in by nanasess, 13 years ago (diff)

#990(配送設定・支払方法設定の仕様変更)

  • 支払方法設定ページ
  • 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$
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();";
55        $this->tpl_title = "お支払方法・お届け時間等の指定";
56        $masterData = new SC_DB_MasterData();
57        $this->arrPref = $masterData->getMasterData('mtb_pref');
58    }
59
60    /**
61     * Page のプロセス.
62     *
63     * @return void
64     */
65    function process() {
66        parent::process();
67        $this->action();
68        $this->sendResponse();
69    }
70
71    /**
72     * Page のアクション.
73     *
74     * @return void
75     */
76    function action() {
77        $objSiteSess = new SC_SiteSession();
78        $objCartSess = new SC_CartSession();
79        $objPurchase = new SC_Helper_Purchase_Ex();
80        $this->objCustomer = new SC_Customer();
81        $this->objFormParam = new SC_FormParam();
82
83        $this->arrShipping =& $objPurchase->getShippingTemp();
84        $this->is_multiple = $objPurchase->isMultiple();
85        $this->tpl_uniqid = $objSiteSess->getUniqId();
86        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
87
88        $this->cartKey = $objCartSess->getKey();
89
90        // 配送業者を取得
91        $this->arrDeliv = $objPurchase->getDeliv($this->cartKey);
92        if (count($this->arrDeliv) == 1) {
93            $this->is_single_deliv = true;
94            $deliv_id = $this->arrDeliv[0]['deliv_id'];
95        } else {
96            $this->is_single_deliv = false;
97        }
98
99        // 会員ログインチェック
100        if($this->objCustomer->isLoginSuccess(true)) {
101            $this->tpl_login = '1';
102            $this->tpl_user_point = $this->objCustomer->getValue('point');
103            //戻り先URL
104            if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) {
105                // ダウンロード商品のみの場合はカート画面へ戻る
106                $this->tpl_back_url = CART_URLPATH;
107            } else {
108                $this->tpl_back_url = DELIV_URLPATH;
109            }
110        } else {
111            $this->tpl_back_url = SHOPPING_URL . "?from=nonmember";
112        }
113
114        // 一時受注テーブルの読込
115        $arrOrderTemp = $objPurchase->getOrderTemp($this->tpl_uniqid);
116        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
117        if (!$arrOrderTemp) {
118            SC_Response_Ex::sendRedirect(CART_URLPATH);
119            exit;
120        }
121
122        // カート内商品の集計処理を行う
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_Response_Ex::sendRedirect(CART_URLPATH);
128            exit;
129        }
130        // FIXME 使用ポイント, 手数料の扱い
131        $this->arrData = $objCartSess->calculate($this->cartKey, $objCustomer, 0, $objPurchase->getShippingPref());
132
133        // 購入金額の取得
134        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
135
136        // お届け日一覧の取得
137        $this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $this->cartKey);
138
139        switch($this->getMode()) {
140        case 'select_deliv':
141            $this->objFormParam->convParam();
142            $this->lfInitParam(true);
143            $this->objFormParam->setParam($_POST);
144            $arrErr = $this->objFormParam->checkError();
145            if (SC_Utils_Ex::isBlank($arrErr)) {
146                $deliv_id = $this->objFormParam->getValue('deliv_id');
147                $this->arrPayment = $objPurchase->getPaymentsByPrice($total_inctax, $deliv_id);
148                $this->img_show = $this->lfGetImgShow($this->arrPayment);
149                // 配送時間を取得
150                $this->arrDelivTime = $objPurchase->getDelivTime($deliv_id);
151                $arrSelectDeliv = array('error' => false,
152                                        'arrPayment' => $this->arrPayment,
153                                        'arrDelivTime' => $this->arrDelivTime,
154                                        'img_show' => $this->img_show);
155            } else {
156                $arrSelectDeliv = array('error' => true);
157            }
158
159            if (SC_Display::detectDevice() != DEVICE_TYPE_MOBILE) {
160                $objJson = new Services_JSON();
161                echo $objJson->encode($arrSelectDeliv);
162                exit;
163            }
164            break;
165
166        case 'confirm':
167            // パラメータ情報の初期化
168            $this->lfInitParam();
169            // POST値の取得
170            $this->objFormParam->setParam($_POST);
171            // 入力値の変換
172            $this->objFormParam->convParam();
173            $deliv_id = $this->objFormParam->getValue('deliv_id');
174            $this->arrPayment = $objPurchase->getPaymentsByPrice($total_inctax, $deliv_id);
175            $this->arrDelivTime = $objPurchase->getDelivTime($deliv_id);
176            $this->arrErr = $this->lfCheckError($this->arrData, $this->arrPayment);
177            // 入力エラーなし
178            if(count($this->arrErr) == 0) {
179
180                foreach (array_keys($_SESSION['shipping']) as $key) {
181                    $timeId = $this->objFormParam->getValue('deliv_time_id' . $key);
182
183                    /* TODO
184                     * SC_Purchase::getShippingTemp() で取得して,
185                     * リファレンスで代入すると, セッションに添字を追加できない?
186                     */
187                    $_SESSION['shipping'][$key]['deliv_id'] = $deliv_id;
188                    $_SESSION['shipping'][$key]['time_id'] = $timeId;
189                    $_SESSION['shipping'][$key]['shipping_time'] = $this->arrDelivTime[$timeId];
190                    $_SESSION['shipping'][$key]['shipping_date'] = $this->objFormParam->getValue('deliv_date' . $key);
191                }
192                $this->lfRegistData($this->tpl_uniqid, $objPurchase);
193
194                // 正常に登録されたことを記録しておく
195                $objSiteSess->setRegistFlag();
196                // 確認ページへ移動
197                SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URLPATH);
198                exit;
199            }else{
200                // 受注一時テーブルからの情報を格納
201                $this->img_show = $this->lfGetImgShow($this->arrPayment);
202                $this->objFormParam->setParam($objPurchase->getOrderTemp($this->tpl_uniqid));
203            }
204            break;
205        // 前のページに戻る
206        case 'return':
207
208            // 正常な推移であることを記録しておく
209            $objSiteSess->setRegistFlag();
210            SC_Response_Ex::sendRedirect(SHOPPING_URL);
211            exit;
212            break;
213
214        default:
215
216            // 前のページから戻ってきた場合の初期値を設定
217            $this->lfInitParam();
218            $this->objFormParam->setParam($arrOrderTemp);
219            $this->objFormParam->convParam();
220
221            if (!$this->is_single_deliv) {
222                $deliv_id = $this->objFormParam->getValue('deliv_id');
223            }
224
225            if (!SC_Utils_Ex::isBlank($deliv_id)) {
226                $this->objFormParam->setValue('deliv_id', $deliv_id);
227                $this->arrPayment = $objPurchase->getPaymentsByPrice($total_inctax, $deliv_id);
228                // XXX セッションからデフォルト値を取得する必要あり
229                $this->arrDelivTime = $objPurchase->getDelivTime($deliv_id);
230                $this->img_show = $this->lfGetImgShow($this->arrPayment);
231            }
232            break;
233        }
234
235        // モバイル用 ポストバック処理
236        if (SC_Display::detectDevice() == DEVICE_TYPE_MOBILE) {
237            switch($this->getMode()) {
238            case 'select_deliv':
239                $this->tpl_mainpage = 'shopping/payment.tpl';
240                break;
241
242            case 'confirm':
243            case 'return':
244            default:
245                if ($this->is_single_deliv) {
246                    $this->tpl_mainpage = 'shopping/payment.tpl';
247                } else {
248                    $this->tpl_mainpage = 'shopping/select_deliv.tpl';
249                }
250            }
251        }
252
253        $this->arrForm = $this->objFormParam->getFormParamList();
254    }
255
256    /**
257     * デストラクタ.
258     *
259     * @return void
260     */
261    function destroy() {
262        parent::destroy();
263    }
264
265    /* パラメータ情報の初期化 */
266    function lfInitParam($deliv_only = false) {
267        $this->objFormParam->addParam("配送業者", "deliv_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
268
269        if (!$deliv_only) {
270            $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
271            $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
272            $this->objFormParam->addParam("その他お問い合わせ", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
273            $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
274
275            for ($i = 0; $i < count($this->shipping); $i++) {
276                $this->objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
277                $this->objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
278            }
279        }
280    }
281
282
283    /* 入力内容のチェック */
284    function lfCheckError($arrData, $arrPayment) {
285        // 入力データを渡す。
286        $arrRet =  $this->objFormParam->getHashArray();
287        $objErr = new SC_CheckError($arrRet);
288        $objErr->arrErr = $this->objFormParam->checkError();
289
290        if (USE_POINT === false) {
291            $_POST['point_check'] = "";
292            $_POST['use_point'] = "0";
293        }
294
295        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
296
297        if($_POST['point_check'] == '1') {
298            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
299            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
300            $max_point = $this->objCustomer->getValue('point');
301            if($max_point == "") {
302                $max_point = 0;
303            }
304            // FIXME mobile 互換のため br は閉じない...
305            if($arrRet['use_point'] > $max_point) {
306                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
307            }
308            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
309                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
310            }
311        }
312
313        $objCartSess = new SC_CartSession();
314        // 購入金額の取得得
315        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
316        $pay_flag = true;
317        foreach ($arrPayment as $key => $payment) {
318            if ($payment['payment_id'] == $arrRet['payment_id']) {
319                $pay_flag = false;
320                break;
321            }
322        }
323        if ($pay_flag && $arrRet['payment_id'] != "") {
324            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
325        }
326
327        return $objErr->arrErr;
328    }
329
330    /* 支払い方法文字列の取得 */
331    function lfGetPaymentInfo($payment_id) {
332        $objQuery = new SC_Query();
333        $where = "payment_id = ?";
334        $arrRet = $objQuery->getRow("charge, payment_method", "dtb_payment", $where, array($payment_id));
335        return (array($arrRet['charge'], $arrRet['payment_method']));
336    }
337
338    /* DBへデータの登録 */
339    function lfRegistData($uniqid, &$objPurchase) {
340
341        $sqlval = $this->objFormParam->getDbArray();
342        // 登録データの作成
343        $sqlval['order_temp_id'] = $uniqid;
344        $sqlval['update_date'] = 'Now()';
345
346        if (strlen($sqlval['payment_id']) >= 1) {
347            list($sqlval['charge'], $sqlval['payment_method']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
348        }
349
350        // 使用ポイントの設定
351        if($sqlval['point_check'] != '1') {
352            $sqlval['use_point'] = 0;
353        }
354
355        $objPurchase->saveOrderTemp($uniqid, $sqlval);
356    }
357
358    //一時受注テーブルからの情報を格納する
359    function lfSetOrderTempData($uniqid, &$objPurchase) {
360        $arrOrderTemp = $objPurchase->getOrderTemp($uniqid);
361        $this->objFormParam->setParam($arrOrderTemp);
362        return $this->objFormParam;
363    }
364
365    /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */
366    function lfGetImgShow($arrPayment) {
367        $img_show = false;
368        foreach ($arrPayment as $payment) {
369            if (strlen($payment["payment_image"]) > 0 ){
370                $img_show = true;
371                break;
372            }
373        }
374        return $img_show;
375    }
376}
377?>
Note: See TracBrowser for help on using the repository browser.