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

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