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

Revision 23357, 18.0 KB checked in by Seasoft, 10 years ago (diff)

#2518 (表記の統一 for 2.13.2)

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