source: branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 19860

Revision 19860, 20.5 KB checked in by nanasess, 13 years ago (diff)

#843(複数配送先の指定)

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