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

Revision 22857, 18.1 KB checked in by Seasoft, 11 years ago (diff)

#2043 (typo修正・ソース整形・ソースコメントの改善 for 2.13.0)

  • 主に空白・空白行の調整。
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id
  • 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-2013 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
24require_once CLASS_EX_REALDIR . 'page_extends/LC_Page_Ex.php';
25
26/**
27 * 支払い方法選択 のページクラス.
28 *
29 * @package Page
30 * @author LOCKON CO.,LTD.
31 * @version $Id$
32 */
33class LC_Page_Shopping_Payment extends LC_Page_Ex
34{
35    /** フォームパラメーターの配列 */
36    var $objFormParam;
37
38    /** 会員情報のインスタンス */
39    var $objCustomer;
40
41    /**
42     * Page を初期化する.
43     *
44     * @return void
45     */
46    function init()
47    {
48        parent::init();
49        $this->tpl_onload = 'fnCheckInputPoint();';
50        $this->tpl_title = 'お支払方法・お届け時間等の指定';
51        $masterData = new SC_DB_MasterData_Ex();
52        $this->arrPref = $masterData->getMasterData('mtb_pref');
53    }
54
55    /**
56     * Page のプロセス.
57     *
58     * @return void
59     */
60    function process()
61    {
62        parent::process();
63        $this->action();
64        $this->sendResponse();
65    }
66
67    /**
68     * Page のアクション.
69     *
70     * @return void
71     */
72    function action()
73    {
74        $objSiteSess = new SC_SiteSession_Ex();
75        $objCartSess = new SC_CartSession_Ex();
76        $objPurchase = new SC_Helper_Purchase_Ex();
77        $objCustomer = new SC_Customer_Ex();
78        $objFormParam = new SC_FormParam_Ex();
79        $objDelivery = new SC_Helper_Delivery_Ex();
80
81        $this->is_multiple = $objPurchase->isMultiple();
82
83        // カートの情報を取得
84        $this->arrShipping = $objPurchase->getShippingTemp($this->is_multiple);
85
86        $this->tpl_uniqid = $objSiteSess->getUniqId();
87        $cart_key = $objCartSess->getKey();
88        $this->cartKey = $cart_key;
89        $objPurchase->verifyChangeCart($this->tpl_uniqid, $objCartSess);
90
91        // 配送業者を取得
92        $this->arrDeliv = $objDelivery->getList($cart_key);
93        $this->is_single_deliv = $this->isSingleDeliv($this->arrDeliv);
94
95        // 会員情報の取得
96        if ($objCustomer->isLoginSuccess(true)) {
97            $this->tpl_login = '1';
98            $this->tpl_user_point = $objCustomer->getValue('point');
99            $this->name01 = $objCustomer->getValue('name01');
100            $this->name02 = $objCustomer->getValue('name02');
101        }
102
103        // 戻り URL の設定
104        // @deprecated 2.12.0 テンプレート直書きに戻した
105        $this->tpl_back_url = '?mode=return';
106
107        $arrOrderTemp = $objPurchase->getOrderTemp($this->tpl_uniqid);
108        // 正常に受注情報が格納されていない場合はカート画面へ戻す
109        if (SC_Utils_Ex::isBlank($arrOrderTemp)) {
110            SC_Response_Ex::sendRedirect(CART_URLPATH);
111            SC_Response_Ex::actionExit();
112        }
113
114        // カート内商品の妥当性チェック
115        $this->tpl_message = $objCartSess->checkProducts($cart_key);
116        if (strlen($this->tpl_message) >= 1) {
117            SC_Response_Ex::sendRedirect(CART_URLPATH);
118            SC_Response_Ex::actionExit();
119        }
120
121        /*
122         * 購入金額の取得
123         * ここでは送料を加算しない
124         */
125        $this->arrPrices = $objCartSess->calculate($cart_key, $objCustomer);
126
127        // お届け日一覧の取得
128        $this->arrDelivDate = $objPurchase->getDelivDate($objCartSess, $cart_key);
129
130        switch ($this->getMode()) {
131            /*
132             * 配送業者選択時のアクション
133             * モバイル端末以外の場合は, JSON 形式のデータを出力し, ajax で取得する.
134             */
135            case 'select_deliv':
136                $this->setFormParams($objFormParam, $arrOrderTemp, true, $this->arrShipping);
137                $objFormParam->setParam($_POST);
138                $this->arrErr = $objFormParam->checkError();
139                if (SC_Utils_Ex::isBlank($this->arrErr)) {
140                    $deliv_id = $objFormParam->getValue('deliv_id');
141                    $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
142                    $arrSelectedDeliv['error'] = false;
143                } else {
144                    $arrSelectedDeliv = array('error' => true);
145                    $this->tpl_mainpage = 'shopping/select_deliv.tpl'; // モバイル用
146                }
147
148                if (SC_Display_Ex::detectDevice() != DEVICE_TYPE_MOBILE) {
149                    echo SC_Utils_Ex::jsonEncode($arrSelectedDeliv);
150                    SC_Response_Ex::actionExit();
151                } else {
152                    $this->arrPayment = $arrSelectedDeliv['arrPayment'];
153                    $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
154                }
155                break;
156
157            // 登録処理
158            case 'confirm':
159                // パラメーター情報の初期化
160                $this->setFormParams($objFormParam, $_POST, false, $this->arrShipping);
161
162                $deliv_id = $objFormParam->getValue('deliv_id');
163                $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
164                $this->arrPayment = $arrSelectedDeliv['arrPayment'];
165                $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
166                $this->img_show = $arrSelectedDeliv['img_show'];
167
168                $this->arrErr = $this->lfCheckError($objFormParam, $this->arrPrices['subtotal'], $this->tpl_user_point);
169
170                if (empty($this->arrErr)) {
171                    $this->saveShippings($objFormParam, $this->arrDelivTime);
172                    $this->lfRegistData($this->tpl_uniqid, $objFormParam->getDbArray(), $objPurchase, $this->arrPayment);
173
174                    // 正常に登録されたことを記録しておく
175                    $objSiteSess->setRegistFlag();
176
177                    // 確認ページへ移動
178                    SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URLPATH);
179                    SC_Response_Ex::actionExit();
180                }
181
182                break;
183
184            // 前のページに戻る
185            case 'return':
186
187                // 正常な推移であることを記録しておく
188                $objSiteSess->setRegistFlag();
189
190                $url = null;
191                if ($this->is_multiple) {
192                    $url = MULTIPLE_URLPATH . '?from=multiple';
193                } elseif ($objCustomer->isLoginSuccess(true)) {
194                    if ($product_type_id == PRODUCT_TYPE_DOWNLOAD) {
195                        $url = CART_URLPATH;
196                    } else {
197                        $url = DELIV_URLPATH;
198                    }
199                } else {
200                    $url = SHOPPING_URL . '?from=nonmember';
201                }
202
203                SC_Response_Ex::sendRedirect($url);
204                SC_Response_Ex::actionExit();
205                break;
206
207            default:
208                // FIXME 前のページから戻ってきた場合は別パラメーター(mode)で処理分岐する必要があるのかもしれない
209                $this->setFormParams($objFormParam, $arrOrderTemp, false, $this->arrShipping);
210
211                if (!$this->is_single_deliv) {
212                    $deliv_id = $objFormParam->getValue('deliv_id');
213                } else {
214                    $deliv_id = $this->arrDeliv[0]['deliv_id'];
215                }
216
217                if (!SC_Utils_Ex::isBlank($deliv_id)) {
218                    $objFormParam->setValue('deliv_id', $deliv_id);
219                    $arrSelectedDeliv = $this->getSelectedDeliv($objPurchase, $objCartSess, $deliv_id);
220                    $this->arrPayment = $arrSelectedDeliv['arrPayment'];
221                    $this->arrDelivTime = $arrSelectedDeliv['arrDelivTime'];
222                    $this->img_show = $arrSelectedDeliv['img_show'];
223                }
224                break;
225        }
226
227        // モバイル用 ポストバック処理
228        if (SC_Display_Ex::detectDevice() == DEVICE_TYPE_MOBILE
229            && SC_Utils_Ex::isBlank($this->arrErr)) {
230            $this->tpl_mainpage = $this->getMobileMainpage($this->is_single_deliv, $this->getMode());
231        }
232
233        $this->arrForm = $objFormParam->getFormParamList();
234    }
235
236    /**
237     * デストラクタ.
238     *
239     * @return void
240     */
241    function destroy()
242    {
243        parent::destroy();
244    }
245
246    /**
247     * パラメーターの初期化を行い, 初期値を設定する.
248     *
249     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
250     * @param array $arrParam 設定する値の配列
251     * @param boolean $deliv_only deliv_id チェックのみの場合 true
252     * @param array $arrShipping 配送先情報の配列
253     */
254    function setFormParams(&$objFormParam, $arrParam, $deliv_only, &$arrShipping)
255    {
256        $this->lfInitParam($objFormParam, $deliv_only, $arrShipping);
257        $objFormParam->setParam($arrParam);
258        $objFormParam->convParam();
259    }
260
261    /**
262     * パラメーター情報の初期化を行う.
263     *
264     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
265     * @param boolean $deliv_only 必須チェックは deliv_id のみの場合 true
266     * @param array $arrShipping 配送先情報の配列
267     * @return void
268     */
269    function lfInitParam(&$objFormParam, $deliv_only, &$arrShipping)
270    {
271        $objFormParam->addParam('配送業者', 'deliv_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
272        $objFormParam->addParam('ポイント', 'use_point', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK', 'ZERO_START'));
273        $objFormParam->addParam('その他お問い合わせ', 'message', LTEXT_LEN, 'KVa', array('SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
274        $objFormParam->addParam('ポイントを使用する', 'point_check', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), '2');
275
276        if ($deliv_only) {
277            $objFormParam->addParam('お支払い方法', 'payment_id', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
278        } else {
279            $objFormParam->addParam('お支払い方法', 'payment_id', INT_LEN, 'n', array('EXIST_CHECK', 'MAX_LENGTH_CHECK', 'NUM_CHECK'));
280
281            foreach ($arrShipping as $val) {
282                $objFormParam->addParam('お届け時間', 'deliv_time_id' . $val['shipping_id'], INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'));
283                $objFormParam->addParam('お届け日', 'deliv_date' . $val['shipping_id'], STEXT_LEN, 'KVa', array('MAX_LENGTH_CHECK'));
284            }
285        }
286
287        $objFormParam->setParam($arrParam);
288        $objFormParam->convParam();
289    }
290
291    /**
292     * 入力内容のチェックを行なう.
293     *
294     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
295     * @param integer $subtotal 購入金額の小計
296     * @param integer $max_point 会員の保持ポイント
297     * @return array 入力チェック結果の配列
298     */
299    function lfCheckError(&$objFormParam, $subtotal, $max_point)
300    {
301        $objPurchase = new SC_Helper_Purchase_Ex();
302        // 入力データを渡す。
303        $arrForm =  $objFormParam->getHashArray();
304        $objErr = new SC_CheckError_Ex($arrForm);
305        $objErr->arrErr = $objFormParam->checkError();
306
307        if (USE_POINT === false) {
308            return $objErr->arrErr;
309        }
310
311        if ($arrForm['point_check'] == '1') {
312            $objErr->doFunc(array('ポイントを使用する', 'point_check'), array('EXIST_CHECK'));
313            $objErr->doFunc(array('ポイント', 'use_point'), array('EXIST_CHECK'));
314            if ($max_point == '') {
315                $max_point = 0;
316            }
317            // FIXME mobile 互換のため br は閉じない...
318            if ($arrForm['use_point'] > $max_point) {
319                $objErr->arrErr['use_point'] = '※ ご利用ポイントが所持ポイントを超えています。<br>';
320            }
321            if (($arrForm['use_point'] * POINT_VALUE) > $subtotal) {
322                $objErr->arrErr['use_point'] = '※ ご利用ポイントがご購入金額を超えています。<br>';
323            }
324            // ポイント差し引き後の決済方法チェック
325            $objPayment = new SC_Helper_Payment_Ex();
326            $arrPayments = $objPayment->get($arrForm['payment_id']);
327            if ($arrPayments['rule_max'] > $subtotal - $arrForm['use_point'] * POINT_VALUE) {
328                $objErr->arrErr['use_point'] = '※ 選択した支払方法では、ポイントは'.($subtotal - $arrPayments['rule_max']).'ポイントまでご利用いただけます。<br>';
329            }
330        }
331
332        return $objErr->arrErr;
333    }
334
335    /**
336     * 配送情報を保存する.
337     *
338     * @param SC_FormParam $objFormParam SC_FormParam インスタンス
339     * @param array $arrDelivTime 配送時間の配列
340     */
341    function saveShippings(&$objFormParam, $arrDelivTime)
342    {
343        $deliv_id = $objFormParam->getValue('deliv_id');
344
345        /* TODO
346         * SC_Purchase::getShippingTemp() で取得して,
347         * リファレンスで代入すると, セッションに添字を追加できない?
348         */
349        foreach ($_SESSION['shipping'] as $key => $value) {
350            $shipping_id = $_SESSION['shipping'][$key]['shipping_id'];
351            $time_id = $objFormParam->getValue('deliv_time_id' . $shipping_id);
352            $_SESSION['shipping'][$key]['deliv_id'] = $deliv_id;
353            $_SESSION['shipping'][$key]['time_id'] = $time_id;
354            $_SESSION['shipping'][$key]['shipping_time'] = $arrDelivTime[$time_id];
355            $_SESSION['shipping'][$key]['shipping_date'] = $objFormParam->getValue('deliv_date' . $shipping_id);
356        }
357    }
358
359    /**
360     * 受注一時テーブルへ登録を行う.
361     *
362     * @param integer $uniqid 受注一時テーブルのユニークID
363     * @param array $arrForm フォームの入力値
364     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
365     * @param array $arrPayment お支払い方法の配列
366     * @return void
367     */
368    function lfRegistData($uniqid, $arrForm, &$objPurchase, $arrPayment)
369    {
370        $arrForm['order_temp_id'] = $uniqid;
371        $arrForm['update_date'] = 'CURRENT_TIMESTAMP';
372
373        if ($arrForm['point_check'] != '1') {
374            $arrForm['use_point'] = 0;
375        }
376
377        foreach ($arrPayment as $payment) {
378            if ($arrForm['payment_id'] == $payment['payment_id']) {
379                $arrForm['charge'] = $payment['charge'];
380                $arrForm['payment_method'] = $payment['payment_method'];
381                break;
382            }
383        }
384        $objPurchase->saveOrderTemp($uniqid, $arrForm);
385    }
386
387    /**
388     * 配送業者IDから, 支払い方法, お届け時間の配列を取得する.
389     *
390     * 結果の連想配列の添字の値は以下の通り
391     * - 'arrDelivTime' - お届け時間の配列
392     * - 'arrPayment' - 支払い方法の配列
393     * - 'img_show' - 支払い方法の画像の有無
394     *
395     * @param SC_Helper_Purchase $objPurchase SC_Helper_Purchase インスタンス
396     * @param SC_CartSession $objCartSess SC_CartSession インスタンス
397     * @param integer $deliv_id 配送業者ID
398     * @return array 支払い方法, お届け時間を格納した配列
399     */
400    function getSelectedDeliv(&$objPurchase, &$objCartSess, $deliv_id)
401    {
402        $arrResults = array();
403        $arrResults['arrDelivTime'] = SC_Helper_Delivery_Ex::getDelivTime($deliv_id);
404        $total = $objCartSess->getAllProductsTotal($objCartSess->getKey());
405        $payments_deliv = SC_Helper_Delivery_Ex::getPayments($deliv_id);
406        $objPayment = new SC_Helper_Payment_Ex();
407        $payments_total = $objPayment->getByPrice($total);
408        $arrPayment = array();
409        foreach ($payments_total as $payment) {
410            if (in_array($payment['payment_id'], $payments_deliv)) {
411                $arrPayment[] = $payment;
412            }
413        }
414        $arrResults['arrPayment'] = $arrPayment;
415        $arrResults['img_show'] = $this->hasPaymentImage($arrResults['arrPayment']);
416
417        return $arrResults;
418    }
419
420    /**
421     * 支払い方法の画像があるかどうか.
422     *
423     * @param array $arrPayment 支払い方法の配列
424     * @return boolean 支払い方法の画像がある場合 true
425     */
426    function hasPaymentImage($arrPayment)
427    {
428        foreach ($arrPayment as $val) {
429            if (!SC_Utils_Ex::isBlank($val['payment_image'])) {
430                return true;
431            }
432        }
433
434        return false;
435    }
436
437    /**
438     * 配送業者が1社のみかどうか.
439     *
440     * @param array $arrDeliv 配送業者の配列
441     * @return boolean 配送業者が1社のみの場合 true
442     */
443    function isSingleDeliv($arrDeliv)
444    {
445        if (count($arrDeliv) == 1) {
446            return true;
447        } else {
448            return false;
449        }
450    }
451
452    /**
453     * モバイル用テンプレートのパスを取得する.
454     *
455     * @param boolean $is_single_deliv 配送業者が1社の場合 true
456     * @param string $mode フォームパラメーター 'mode' の文字列
457     * @return string モバイル用テンプレートのパス
458     */
459    function getMobileMainpage($is_single_deliv = true, $mode)
460    {
461        switch ($mode) {
462            case 'select_deliv':
463                return 'shopping/payment.tpl';
464
465            case 'confirm':
466            case 'return':
467            default:
468                if ($is_single_deliv) {
469                    return 'shopping/payment.tpl';
470                } else {
471                    return 'shopping/select_deliv.tpl';
472                }
473                break;
474        }
475    }
476}
Note: See TracBrowser for help on using the repository browser.