source: branches/comu-ver2/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 17711

Revision 17711, 20.8 KB checked in by homan, 15 years ago (diff)

#395, #397のお支払方法の一連の不具合修正(comu-ver2)

  • 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, $arrInfo, $objCartSess);
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, $arrInfo, $objCartSess);
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, $arrInfo, $objCartSess);
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            //上限、下限が共に0の場合
358            } elseif($data['rule'] == "0" && $data['upper_rule'] == "0") {
359            //設定なし
360            } else {
361                $arrPayment[] = $data;
362            }
363        }
364        return $arrPayment;
365    }
366
367    /* 入力内容のチェック */
368    function lfCheckError($arrData, $arrInfo, $objCartSess) {
369        // 入力データを渡す。
370        $arrRet =  $this->objFormParam->getHashArray();
371        $objErr = new SC_CheckError($arrRet);
372        $objErr->arrErr = $this->objFormParam->checkError();
373
374        if (USE_POINT === false) {
375            $_POST['point_check'] = "";
376            $_POST['use_point'] = "0";
377        }
378       
379        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
380       
381        if($_POST['point_check'] == '1') {
382            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
383            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
384            $max_point = $this->objCustomer->getValue('point');
385            if($max_point == "") {
386                $max_point = 0;
387            }
388            // FIXME mobile 互換のため br は閉じない...
389            if($arrRet['use_point'] > $max_point) {
390                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
391            }
392            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
393                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
394            }
395        }
396       
397        // 購入金額の取得得
398        $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
399        // 支払い方法の取得
400        $arrPayment = $this->lfGetPayment($total_pretax);
401        $pay_flag = true;
402        foreach ($arrPayment as $key => $payment) {
403            if ($payment['payment_id'] == $arrRet['payment_id']) {
404                $pay_flag = false;
405                break;
406            }
407        }
408        if ($pay_flag && $arrRet['payment_id'] != "") {
409            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
410        }
411       
412        return $objErr->arrErr;
413    }
414
415    /* 支払い方法文字列の取得 */
416    function lfGetPaymentInfo($payment_id) {
417        $objQuery = new SC_Query();
418        $where = "payment_id = ?";
419        $arrRet = $objQuery->select("payment_method, charge", "dtb_payment", $where, array($payment_id));
420        return (array($arrRet[0]['payment_method'], $arrRet[0]['charge']));
421    }
422
423    /* 配送時間文字列の取得 */
424    function lfGetDelivTimeInfo($time_id) {
425        $objQuery = new SC_Query();
426        $where = "time_id = ?";
427        $arrRet = $objQuery->select("deliv_id, deliv_time", "dtb_delivtime", $where, array($time_id));
428        return (array($arrRet[0]['deliv_id'], $arrRet[0]['deliv_time']));
429    }
430
431    /* DBへデータの登録 */
432    function lfRegistData($uniqid) {
433        $arrRet = $this->objFormParam->getHashArray();
434        $sqlval = $this->objFormParam->getDbArray();
435        // 登録データの作成
436        $sqlval['order_temp_id'] = $uniqid;
437        $sqlval['update_date'] = 'Now()';
438
439        if($sqlval['payment_id'] != "") {
440            list($sqlval['payment_method'], $sqlval['charge']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
441        } else {
442            $sqlval['payment_id'] = '0';
443            $sqlval['payment_method'] = "";
444        }
445
446        if($sqlval['deliv_time_id'] != "") {
447            list($sqlval['deliv_id'], $sqlval['deliv_time']) = $this->lfGetDelivTimeInfo($sqlval['deliv_time_id']);
448        } else {
449            $sqlval['deliv_time_id'] = '0';
450            $sqlval['deliv_id'] = '0';
451            $sqlval['deliv_time'] = "";
452        }
453
454        // 使用ポイントの設定
455        if($sqlval['point_check'] != '1') {
456            $sqlval['use_point'] = 0;
457        }
458
459        $objDb = new SC_Helper_DB_Ex();
460        $objDb->sfRegistTempOrder($uniqid, $sqlval);
461    }
462
463    /* 配達日一覧を取得する */
464    function lfGetDelivDate() {
465        $objCartSess = new SC_CartSession();
466        $objQuery = new SC_Query();
467        // 商品IDの取得
468        $max = $objCartSess->getMax();
469        for($i = 1; $i <= $max; $i++) {
470            if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
471                $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
472            }
473        }
474        if(count($arrID['product_id']) > 0) {
475            $id = implode(",", $arrID['product_id']);
476            //商品から発送目安の取得
477            $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")");
478            //発送目安
479            switch($deliv_date) {
480            //即日発送
481            case '1':
482                $start_day = 1;
483                break;
484            //1-2日後
485            case '2':
486                $start_day = 3;
487                break;
488            //3-4日後
489            case '3':
490                $start_day = 5;
491                break;
492            //1週間以内
493            case '4':
494                $start_day = 8;
495                break;
496            //2週間以内
497            case '5':
498                $start_day = 15;
499                break;
500            //3週間以内
501            case '6':
502                $start_day = 22;
503                break;
504            //1ヶ月以内
505            case '7':
506                $start_day = 32;
507                break;
508            //2ヶ月以降
509            case '8':
510                $start_day = 62;
511                break;
512            //お取り寄せ(商品入荷後)
513            case '9':
514                $start_day = "";
515                break;
516            default:
517                //お届け日が設定されていない場合
518                $start_day = "";
519                break;
520            }
521            //配達可能日のスタート値から、配達日の配列を取得する
522            $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX);
523        }
524        return $arrDelivDate;
525    }
526
527    //配達可能日のスタート値から、配達日の配列を取得する
528    function lfGetDateArray($start_day, $end_day) {
529        $masterData = new SC_DB_MasterData();
530        $arrWDAY = $masterData->getMasterData("mtb_wday");
531        //配達可能日のスタート値がセットされていれば
532        if($start_day >= 1) {
533            $now_time = time();
534            $max_day = $start_day + $end_day;
535            // 集計
536            for ($i = $start_day; $i < $max_day; $i++) {
537                // 基本時間から日数を追加していく
538                $tmp_time = $now_time + ($i * 24 * 3600);
539                list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time));
540                $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
541                $arrDate[$val] = $val;
542            }
543        } else {
544            $arrDate = false;
545        }
546        return $arrDate;
547    }
548
549    //一時受注テーブルからの情報を格納する
550    function lfSetOrderTempData($uniqid) {
551
552        $objQuery = new SC_Query();
553        $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
554        $from = "dtb_order_temp";
555        $where = "order_temp_id = ?";
556        $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
557        // DB値の取得
558        $this->objFormParam->setParam($arrRet[0]);
559        return $this->objFormParam;
560    }
561}
562?>
Note: See TracBrowser for help on using the repository browser.