source: tmp/version-2_5-test/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 18609

Revision 18609, 21.0 KB checked in by kajiwara, 14 years ago (diff)

正式版にナイトリービルド版をマージしてみるテスト

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