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

Revision 18177, 21.4 KB checked in by kajiwara, 15 years ago (diff)

2.4.1 正式版をコミット。コミット内容詳細はこちら(http://svn.ec-cube.net/open_trac/query?status=closed&milestone=EC-CUBE2.4.1

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