source: branches/version-2_13_0/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 23182

Revision 23182, 18.1 KB checked in by h_yoshimoto, 11 years ago (diff)

#1506 「決済処理中」受注データの実行フラグを追加

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