source: trunk/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 18562

Revision 18562, 22.1 KB checked in by kajiwara, 14 years ago (diff)

EC-CUBE Ver2.4.3 分コミット。詳細はこちら( http://www.ec-cube.net/release/detail.php?release_id=210

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Id Revision Date
  • 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-2007 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
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/**
28 * 支払い方法選択 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id:LC_Page_Shopping_Payment.php 15532 2007-08-31 14:39:46Z nanasess $
33 */
34class LC_Page_Shopping_Payment extends LC_Page {
35
36    // {{{ properties
37
38    /** フォームパラメータの配列 */
39    var $objFormParam;
40
41    /** 顧客情報のインスタンス */
42    var $objCustomer;
43
44    // }}}
45    // {{{ functions
46
47    /**
48     * Page を初期化する.
49     *
50     * @return void
51     */
52    function init() {
53        parent::init();
54        $this->tpl_mainpage = 'shopping/payment.tpl';
55        $this->tpl_column_num = 1;
56        $this->tpl_onload = 'fnCheckInputPoint();';
57        $this->tpl_title = "お支払方法・お届け時間等の指定";
58
59        $this->allowClientCache();
60    }
61
62    /**
63     * Page のプロセス.
64     *
65     * @return void
66     */
67    function process() {
68        global $objCampaignSess;
69
70        $objView = new SC_SiteView();
71        $objSiteSess = new SC_SiteSession();
72        $objCartSess = new SC_CartSession();
73        $objCampaignSess = new SC_CampaignSession();
74        $objDb = new SC_Helper_DB_Ex();
75        $this->objCustomer = new SC_Customer();
76        $objSiteInfo = $objView->objSiteInfo;
77        $arrInfo = $objSiteInfo->data;
78
79        // パラメータ管理クラス
80        $this->objFormParam = new SC_FormParam();
81        // パラメータ情報の初期化
82        $this->lfInitParam();
83        // POST値の取得
84        $this->objFormParam->setParam($_POST);
85
86        // ユーザユニークIDの取得と購入状態の正当性をチェック
87        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
88        // ユニークIDを引き継ぐ
89        $this->tpl_uniqid = $uniqid;
90
91        // 会員ログインチェック
92        if($this->objCustomer->isLoginSuccess()) {
93            $this->tpl_login = '1';
94            $this->tpl_user_point = $this->objCustomer->getValue('point');
95            //戻り先URL
96            $this->tpl_back_url = URL_DELIV_TOP;
97        } else {
98            $this->tpl_back_url = URL_SHOP_TOP . "?from=nonmember";
99        }
100
101        // 一時受注テーブルの読込
102        $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid);
103        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
104        if (!$arrOrderTemp){
105            $this->sendRedirect($this->getLocation(URL_CART_TOP));
106            exit;
107        }
108        // 金額の取得 (購入途中で売り切れた場合にはこの関数内にてその商品の個数が0になる)
109        $objDb->sfTotalCart($this, $objCartSess, $arrInfo);
110
111        if (empty($arrData)) $arrData = array();
112        $this->arrData = $objDb->sfTotalConfirm($arrData, $this, $objCartSess, $arrInfo);
113
114        // カート内の商品の売り切れチェック
115        $objCartSess->chkSoldOut($objCartSess->getCartList());
116
117        if (!isset($_POST['mode'])) $_POST['mode'] = "";
118
119        switch($_POST['mode']) {
120        case 'confirm':
121            // 入力値の変換
122            $this->objFormParam->convParam();
123            $this->arrErr = $this->lfCheckError($this->arrData );
124            // 入力エラーなし
125            if(count($this->arrErr) == 0) {
126                // DBへのデータ登録
127                $this->lfRegistData($uniqid);
128                // 正常に登録されたことを記録しておく
129                $objSiteSess->setRegistFlag();
130                // 確認ページへ移動
131                $this->sendRedirect($this->getLocation(URL_SHOP_CONFIRM, array(), true));
132                exit;
133            }else{
134                // ユーザユニークIDの取得
135                $uniqid = $objSiteSess->getUniqId();
136                // 受注一時テーブルからの情報を格納
137                $this->lfSetOrderTempData($uniqid);
138            }
139            break;
140        // 前のページに戻る
141        case 'return':
142            // 非会員の場合
143            // 正常な推移であることを記録しておく
144            $objSiteSess->setRegistFlag();
145            $this->sendRedirect(URL_SHOP_TOP);
146            exit;
147            break;
148        // 支払い方法が変更された場合
149        case 'payment':
150            // ここのbreakは、意味があるので外さないで下さい。
151            break;
152        default:
153            // 受注一時テーブルからの情報を格納
154            $this->lfSetOrderTempData($uniqid);
155            break;
156        }
157
158        // 店舗情報の取得
159        $arrInfo = $objSiteInfo->data;
160        // 購入金額の取得得
161        $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
162        // 支払い方法の取得
163        $this->arrPayment = $this->lfGetPayment($total_pretax);
164        // 支払い方法の画像があるなしを取得($img_show true:ある false:なし)
165        $this->img_show = $this->lfGetImgShow($this->arrPayment);
166        // お届け時間の取得
167        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
168        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
169
170        // お届け日一覧の取得
171        $this->arrDelivDate = $this->lfGetDelivDate();
172
173        $this->arrForm = $this->objFormParam->getFormParamList();
174
175        $objView->assignobj($this);
176        // フレームを選択(キャンペーンページから遷移なら変更)
177        $objCampaignSess->pageView($objView);
178    }
179
180    /**
181     * モバイルページを初期化する.
182     *
183     * @return void
184     */
185    function mobileInit() {
186        $this->init();
187    }
188
189    /**
190     * Page のプロセス(モバイル).
191     *
192     * @return void
193     */
194    function mobileProcess() {
195        $objView = new SC_MobileView();
196        $objSiteSess = new SC_SiteSession();
197        $objCartSess = new SC_CartSession();
198        $this->objCustomer = new SC_Customer();
199        $objDb = new SC_Helper_DB_Ex();
200        $objSiteInfo = $objView->objSiteInfo;
201        $arrInfo = $objSiteInfo->data;
202
203        // パラメータ管理クラス
204        $this->objFormParam = new SC_FormParam();
205        // パラメータ情報の初期化
206        $this->lfInitParam();
207        // POST値の取得
208        $this->objFormParam->setParam($_POST);
209
210        // ユーザユニークIDの取得と購入状態の正当性をチェック
211        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
212        // ユニークIDを引き継ぐ
213        $this->tpl_uniqid = $uniqid;
214
215        // 会員ログインチェック
216        if($this->objCustomer->isLoginSuccess(true)) {
217            $this->tpl_login = '1';
218            $this->tpl_user_point = $this->objCustomer->getValue('point');
219        }
220
221        // 一時受注テーブルの読込
222        $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid);
223        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
224        if (!$arrOrderTemp){
225            $this->sendRedirect($this->getLocation(MOBILE_URL_CART_TOP));
226            exit;
227        }
228        // 金額の取得 (購入途中で売り切れた場合にはこの関数内にてその商品の個数が0になる)
229        $objDb->sfTotalCart($this, $objCartSess, $arrInfo);
230        if (empty($arrData)) $arrData = array();
231        $this->arrData = $objDb->sfTotalConfirm($arrData, $this, $objCartSess, $arrInfo);
232
233        // カート内の商品の売り切れチェック
234        $objCartSess->chkSoldOut($objCartSess->getCartList(), true);
235
236        if (!isset($_POST['mode'])) $_POST['mode'] = "";
237
238        // 戻るボタンの処理
239        if (!empty($_POST['return'])) {
240            switch ($_POST['mode']) {
241            case 'confirm':
242                $_POST['mode'] = 'payment';
243                break;
244            default:
245                // 正常な推移であることを記録しておく
246                $objSiteSess->setRegistFlag();
247                $this->sendRedirect(MOBILE_URL_SHOP_TOP, true);
248                exit;
249            }
250        }
251
252        switch($_POST['mode']) {
253            // 支払い方法指定 → お届け日時指定
254        case 'deliv_date':
255            // 入力値の変換
256            $this->objFormParam->convParam();
257            $this->arrErr = $this->lfCheckError($this->arrData);
258            if (!isset($this->arrErr['payment_id'])) {
259                // 支払い方法の入力エラーなし
260                $this->tpl_mainpage = 'shopping/deliv_date.tpl';
261                $this->tpl_title = "お届け日時指定";
262                break;
263            } else {
264                // ユーザユニークIDの取得
265                $uniqid = $objSiteSess->getUniqId();
266                // 受注一時テーブルからの情報を格納
267                $this->lfSetOrderTempData($uniqid);
268            }
269            break;
270        case 'confirm':
271            // 入力値の変換
272            $this->objFormParam->convParam();
273            $this->arrErr = $this->lfCheckError($this->arrData );
274            // 入力エラーなし
275            if(count($this->arrErr) == 0) {
276                // DBへのデータ登録
277                $this->lfRegistData($uniqid);
278                // 正常に登録されたことを記録しておく
279                $objSiteSess->setRegistFlag();
280                // 確認ページへ移動
281                $this->sendRedirect($this->getLocation(MOBILE_URL_SHOP_CONFIRM), true);
282                exit;
283            }else{
284                // ユーザユニークIDの取得
285                $uniqid = $objSiteSess->getUniqId();
286                // 受注一時テーブルからの情報を格納
287                $this->lfSetOrderTempData($uniqid);
288                if (!isset($this->arrErr['payment_id'])) {
289                    // 支払い方法の入力エラーなし
290                    $this->tpl_mainpage = 'shopping/deliv_date.tpl';
291                    $this->tpl_title = "お届け日時指定";
292                }
293            }
294            break;
295            // 前のページに戻る
296        case 'return':
297            // 非会員の場合
298            // 正常な推移であることを記録しておく
299            $objSiteSess->setRegistFlag();
300            $this->sendRedirect(MOBILE_URL_SHOP_TOP, true);
301            exit;
302            break;
303            // 支払い方法が変更された場合
304        case 'payment':
305            // ここのbreakは、意味があるので外さないで下さい。
306            break;
307        default:
308            // 受注一時テーブルからの情報を格納
309            $this->lfSetOrderTempData($uniqid);
310            break;
311        }
312
313        // 店舗情報の取得
314        $arrInfo = $objSiteInfo->data;
315        // 購入金額の取得得
316        $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
317        // 支払い方法の取得
318        $this->arrPayment = $this->lfGetPayment($total_pretax);
319        // お届け時間の取得
320        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
321        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
322
323        // お届け日一覧の取得
324        $this->arrDelivDate = $this->lfGetDelivDate();
325
326        $this->arrForm = $this->objFormParam->getFormParamList();
327
328        $objView->assignobj($this);
329        $objView->display(SITE_FRAME);
330    }
331
332    /**
333     * デストラクタ.
334     *
335     * @return void
336     */
337    function destroy() {
338        parent::destroy();
339    }
340
341    /* パラメータ情報の初期化 */
342    function lfInitParam() {
343        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
344        $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
345        $this->objFormParam->addParam("お届け時間", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
346        $this->objFormParam->addParam("ご質問", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
347        $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
348        $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
349    }
350
351    function lfGetPayment($total_pretax) {
352        $objQuery = new SC_Query();
353        $objQuery->setorder("rank DESC");
354        //削除されていない支払方法を取得
355        $arrRet = $objQuery->select("payment_id, payment_method, rule, upper_rule, note, payment_image", "dtb_payment", "del_flg = 0 AND deliv_id IN (SELECT deliv_id FROM dtb_deliv WHERE del_flg = 0) ");
356        //利用条件から支払可能方法を判定
357        foreach($arrRet as $data) {
358            //下限と上限が設定されている
359            if($data['rule'] > 0 && $data['upper_rule'] > 0) {
360                if($data['rule'] <= $total_pretax && $data['upper_rule'] >= $total_pretax) {
361                    $arrPayment[] = $data;
362                }
363            //下限のみ設定されている
364            } elseif($data['rule'] > 0) {
365                if($data['rule'] <= $total_pretax) {
366                    $arrPayment[] = $data;
367                }
368            //上限のみ設定されている
369            } elseif($data['upper_rule'] > 0) {
370                if($data['upper_rule'] >= $total_pretax) {
371                    $arrPayment[] = $data;
372                }
373            //設定なし
374            } else {
375                $arrPayment[] = $data;
376            }
377        }
378        return $arrPayment;
379    }
380
381    /* 入力内容のチェック */
382    function lfCheckError($arrData) {
383        // 入力データを渡す。
384        $arrRet =  $this->objFormParam->getHashArray();
385        $objErr = new SC_CheckError($arrRet);
386        $objErr->arrErr = $this->objFormParam->checkError();
387
388        if (USE_POINT === false) {
389            $_POST['point_check'] = "";
390            $_POST['use_point'] = "0";
391        }
392        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
393
394        if($_POST['point_check'] == '1') {
395            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
396            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
397            $max_point = $this->objCustomer->getValue('point');
398            if($max_point == "") {
399                $max_point = 0;
400            }
401            // FIXME mobile 互換のため br は閉じない...
402            if($arrRet['use_point'] > $max_point) {
403                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
404            }
405            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
406                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
407            }
408        }
409
410        $objView = new SC_MobileView();
411        $objSiteInfo = $objView->objSiteInfo;
412        $arrInfo = $objSiteInfo->data;
413        $objCartSess = new SC_CartSession();
414        $arrInfo = $objSiteInfo->data;
415        // 購入金額の取得得
416        $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
417        // 支払い方法の取得
418        $arrPayment = $this->lfGetPayment($total_pretax);
419        $pay_flag = true;
420        foreach ($arrPayment as $key => $payment) {
421            if ($payment['payment_id'] == $arrRet['payment_id']) {
422                $pay_flag = false;
423                break;
424            }
425        }
426        if ($pay_flag && $arrRet['payment_id'] != "" ) {
427            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
428        }
429
430        return $objErr->arrErr;
431    }
432
433    /* 支払い方法文字列の取得 */
434    function lfGetPaymentInfo($payment_id) {
435        $objQuery = new SC_Query();
436        $where = "payment_id = ?";
437        $arrRet = $objQuery->select("payment_method, charge", "dtb_payment", $where, array($payment_id));
438        return (array($arrRet[0]['payment_method'], $arrRet[0]['charge']));
439    }
440
441    /* お届け時間文字列の取得 */
442    function lfGetDelivTimeInfo($time_id) {
443        $objQuery = new SC_Query();
444        $where = "time_id = ?";
445        $arrRet = $objQuery->select("deliv_id, deliv_time", "dtb_delivtime", $where, array($time_id));
446        return (array($arrRet[0]['deliv_id'], $arrRet[0]['deliv_time']));
447    }
448
449    /* DBへデータの登録 */
450    function lfRegistData($uniqid) {
451        $arrRet = $this->objFormParam->getHashArray();
452        $sqlval = $this->objFormParam->getDbArray();
453        // 登録データの作成
454        $sqlval['order_temp_id'] = $uniqid;
455        $sqlval['update_date'] = 'Now()';
456
457        if($sqlval['payment_id'] != "") {
458            list($sqlval['payment_method'], $sqlval['charge']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
459        } else {
460            $sqlval['payment_id'] = '0';
461            $sqlval['payment_method'] = "";
462        }
463
464        if($sqlval['deliv_time_id'] != "") {
465            list($sqlval['deliv_id'], $sqlval['deliv_time']) = $this->lfGetDelivTimeInfo($sqlval['deliv_time_id']);
466        } else {
467            $sqlval['deliv_time_id'] = '0';
468            $sqlval['deliv_id'] = '0';
469            $sqlval['deliv_time'] = "";
470        }
471
472        // 使用ポイントの設定
473        if($sqlval['point_check'] != '1') {
474            $sqlval['use_point'] = 0;
475        }
476
477        $objDb = new SC_Helper_DB_Ex();
478        $objDb->sfRegistTempOrder($uniqid, $sqlval);
479    }
480
481    /* お届け日一覧を取得する */
482    function lfGetDelivDate() {
483        $objCartSess = new SC_CartSession();
484        $objQuery = new SC_Query();
485        // 商品IDの取得
486        $max = $objCartSess->getMax();
487        for($i = 1; $i <= $max; $i++) {
488            if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
489                $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
490            }
491        }
492        if(count($arrID['product_id']) > 0) {
493            $id = implode(",", $arrID['product_id']);
494            //商品から発送目安の取得
495            $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")");
496            //発送目安
497            switch($deliv_date) {
498            //即日発送
499            case '1':
500                $start_day = 1;
501                break;
502            //1-2日後
503            case '2':
504                $start_day = 3;
505                break;
506            //3-4日後
507            case '3':
508                $start_day = 5;
509                break;
510            //1週間以内
511            case '4':
512                $start_day = 8;
513                break;
514            //2週間以内
515            case '5':
516                $start_day = 15;
517                break;
518            //3週間以内
519            case '6':
520                $start_day = 22;
521                break;
522            //1ヶ月以内
523            case '7':
524                $start_day = 32;
525                break;
526            //2ヶ月以降
527            case '8':
528                $start_day = 62;
529                break;
530            //お取り寄せ(商品入荷後)
531            case '9':
532                $start_day = "";
533                break;
534            default:
535                //お届け日が設定されていない場合
536                $start_day = "";
537                break;
538            }
539            //お届け可能日のスタート値から、お届け日の配列を取得する
540            $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX);
541        }
542        return $arrDelivDate;
543    }
544
545    //お届け可能日のスタート値から、お届け日の配列を取得する
546    function lfGetDateArray($start_day, $end_day) {
547        $masterData = new SC_DB_MasterData();
548        $arrWDAY = $masterData->getMasterData("mtb_wday");
549        //お届け可能日のスタート値がセットされていれば
550        if($start_day >= 1) {
551            $now_time = time();
552            $max_day = $start_day + $end_day;
553            // 集計
554            for ($i = $start_day; $i < $max_day; $i++) {
555                // 基本時間から日数を追加していく
556                $tmp_time = $now_time + ($i * 24 * 3600);
557                list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time));
558                $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
559                $arrDate[$val] = $val;
560            }
561        } else {
562            $arrDate = false;
563        }
564        return $arrDate;
565    }
566
567    //一時受注テーブルからの情報を格納する
568    function lfSetOrderTempData($uniqid) {
569
570        $objQuery = new SC_Query();
571        $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
572        $from = "dtb_order_temp";
573        $where = "order_temp_id = ?";
574        $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
575        // DB値の取得
576        $this->objFormParam->setParam($arrRet[0]);
577        return $this->objFormParam;
578    }
579
580    /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */
581    function lfGetImgShow($arrPayment) {
582        $img_show = false;
583        foreach ($this->arrPayment as $payment) {
584            if (strlen($payment["payment_image"]) > 0 ){
585                $img_show = true;
586                break;
587            }
588        }
589        return $img_show;
590    }
591}
592?>
Note: See TracBrowser for help on using the repository browser.