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

Revision 23597, 18.7 KB checked in by shutta, 10 years ago (diff)

#2453 (支払方法・お届け先時間の指定画面のdeliv_idに数値チェックが行われていない)
コーディングスタイルの修正。
if句の括弧の前後に空白挿入漏れ。

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