source: branches/version-2_4/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 17790

Revision 17790, 20.8 KB checked in by zeniya, 15 years ago (diff)

EC-CUBE2.4改修 #376

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