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

Revision 19861, 20.6 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, $objPurchase);
146                $_SESSION['shipping'][0]['time_id'] = $this->objFormParam->getValue('deliv_time_id');
147                $_SESSION['shipping'][0]['deliv_date'] = $this->objFormParam->getValue('deliv_date');
148                // 正常に登録されたことを記録しておく
149                $objSiteSess->setRegistFlag();
150                // 確認ページへ移動
151                SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URL_PATH);
152                exit;
153            }else{
154                // ユーザユニークIDの取得
155                $uniqid = $objSiteSess->getUniqId();
156                // 受注一時テーブルからの情報を格納
157                $this->lfSetOrderTempData($uniqid);
158            }
159            break;
160        // 前のページに戻る
161        case 'return':
162            // 非会員の場合
163            // 正常な推移であることを記録しておく
164            $objSiteSess->setRegistFlag();
165            SC_Response_Ex::sendRedirect(SHOPPING_URL);
166            exit;
167            break;
168
169        default:
170            // 受注一時テーブルからの情報を格納
171            $this->objFormParam->setParam($arrOrderTemp);
172            break;
173        }
174
175        // 配送時間を取得
176        $this->arrDelivTime = $objPurchase->getDelivTime($this->cartKey);
177
178        // 支払い方法の画像があるなしを取得($img_show true:ある false:なし)
179        $this->img_show = $this->lfGetImgShow($this->arrPayment);
180        // FIXME お届け日一覧の取得
181        $this->arrDelivDate = $this->lfGetDelivDate();
182
183        $this->arrForm = $this->objFormParam->getFormParamList();
184    }
185
186    /**
187     * モバイルページを初期化する.
188     *
189     * @return void
190     */
191    function mobileInit() {
192        $this->init();
193    }
194
195    /**
196     * Page のプロセス(モバイル).
197     *
198     * @return void
199     */
200    function mobileProcess() {
201        parent::mobileProcess();
202        $this->mobileAction();
203        $this->sendResponse();
204    }
205
206    /**
207     * Page のプロセス(モバイル).
208     *
209     * @return void
210     */
211    function mobileAction() {
212        $objSiteSess = new SC_SiteSession();
213        $objCartSess = new SC_CartSession();
214        $this->objCustomer = new SC_Customer();
215        $objDb = new SC_Helper_DB_Ex();
216
217        // パラメータ管理クラス
218        $this->objFormParam = new SC_FormParam();
219        // パラメータ情報の初期化
220        $this->lfInitParam();
221        // POST値の取得
222        $this->objFormParam->setParam($_POST);
223
224        // ユーザユニークIDの取得と購入状態の正当性をチェック
225        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
226        // ユニークIDを引き継ぐ
227        $this->tpl_uniqid = $uniqid;
228
229        //ダウンロード商品判定
230        $this->cartdown = $objDb->chkCartDown($objCartSess);
231
232        // 会員ログインチェック
233        if($this->objCustomer->isLoginSuccess(true)) {
234            $this->tpl_login = '1';
235            $this->tpl_user_point = $this->objCustomer->getValue('point');
236        }
237
238        // 一時受注テーブルの読込
239        $arrOrderTemp = $objDb->sfGetOrderTemp($uniqid);
240        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
241        if (!$arrOrderTemp) {
242            $this->objDisplay->redirect($this->getLocation(MOBILE_CART_URL_PATH));
243            exit;
244        }
245
246        // 金額の取得 (購入途中で売り切れた場合にはこの関数内にてその商品の数量が0になる)
247        $objDb->sfTotalCart($this, $objCartSess);
248        if (strlen($this->tpl_message) >= 1) {
249            SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true);
250        }
251
252        $this->arrData = $objDb->sfTotalConfirm(array(), $this, $objCartSess);
253
254        if (!isset($_POST['mode'])) $_POST['mode'] = "";
255
256        // 戻るボタンの処理
257        if (!empty($_POST['return'])) {
258            switch ($_POST['mode']) {
259            case 'confirm':
260                $_POST['mode'] = 'payment';
261                break;
262            default:
263                // 正常な推移であることを記録しておく
264                $objSiteSess->setRegistFlag();
265                if ($this->cartdown == 2) {
266                    // ダウンロード商品のみの場合はカート画面へ戻る
267                    $this->objDisplay->redirect($this->getLocation(MOBILE_CART_URL_PATH));
268                } else {
269                    $this->objDisplay->redirect(MOBILE_SHOPPING_URL);
270                }
271                exit;
272            }
273        }
274
275        // ダウンロード商品のみで、モードがお届け日時指定の場合はモードを変更
276        if ($this->cartdown == 2 && $_POST['mode'] == 'deliv_date') {
277            $_POST['mode'] = 'confirm';
278        }
279
280        switch($_POST['mode']) {
281            // 支払い方法指定 → お届け日時指定
282        case 'deliv_date':
283            // 入力値の変換
284            $this->objFormParam->convParam();
285            $this->arrErr = $this->lfCheckError($this->arrData);
286            if (!isset($this->arrErr['payment_id'])) {
287                // 支払い方法の入力エラーなし
288                $this->tpl_mainpage = 'shopping/deliv_date.tpl';
289                $this->tpl_title = "お届け日時指定";
290                break;
291            } else {
292                // ユーザユニークIDの取得
293                $uniqid = $objSiteSess->getUniqId();
294                // 受注一時テーブルからの情報を格納
295                $this->lfSetOrderTempData($uniqid);
296            }
297            break;
298        case 'confirm':
299            // 入力値の変換
300            $this->objFormParam->convParam();
301            $this->arrErr = $this->lfCheckError($this->arrData);
302            // 入力エラーなし
303            if(count($this->arrErr) == 0) {
304                // DBへのデータ登録
305                $this->lfRegistData($uniqid);
306                // 正常に登録されたことを記録しておく
307                $objSiteSess->setRegistFlag();
308                // 確認ページへ移動
309                $this->objDisplay->redirect($this->getLocation(MOBILE_SHOPPING_CONFIRM_URL_PATH));
310                exit;
311            }else{
312                // ユーザユニークIDの取得
313                $uniqid = $objSiteSess->getUniqId();
314                // 受注一時テーブルからの情報を格納
315                $this->lfSetOrderTempData($uniqid);
316                if (!isset($this->arrErr['payment_id'])) {
317                    // 支払い方法の入力エラーなし
318                    $this->tpl_mainpage = 'shopping/deliv_date.tpl';
319                    $this->tpl_title = "お届け日時指定";
320                }
321            }
322            break;
323            // 前のページに戻る
324        case 'return':
325            // 非会員の場合
326            // 正常な推移であることを記録しておく
327            $objSiteSess->setRegistFlag();
328            $this->objDisplay->redirect(MOBILE_SHOPPING_URL);
329            exit;
330            break;
331            // 支払い方法が変更された場合
332        case 'payment':
333            // ここのbreakは、意味があるので外さないで下さい。
334            break;
335        default:
336            // 受注一時テーブルからの情報を格納
337            $this->lfSetOrderTempData($uniqid);
338            break;
339        }
340
341        // 購入金額の取得得
342        $total_inctax = $objCartSess->getAllProductsTotal();
343        // 支払い方法の取得
344        //$this->arrPayment = $this->lfGetPayment($total_inctax);
345        // お届け時間の取得
346        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
347        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
348
349        // お届け日一覧の取得
350        $this->arrDelivDate = $this->lfGetDelivDate();
351
352        $this->arrForm = $this->objFormParam->getFormParamList();
353    }
354
355    /**
356     * デストラクタ.
357     *
358     * @return void
359     */
360    function destroy() {
361        parent::destroy();
362    }
363
364    /* パラメータ情報の初期化 */
365    function lfInitParam() {
366        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
367        $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
368        $this->objFormParam->addParam("お届け時間", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
369        $this->objFormParam->addParam("ご質問", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
370        $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
371        $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
372    }
373
374 
375    /* 入力内容のチェック */
376    function lfCheckError($arrData, $arrPayment) {
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_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
408        $pay_flag = true;
409        foreach ($arrPayment as $key => $payment) {
410            if ($payment['payment_id'] == $arrRet['payment_id']) {
411                $pay_flag = false;
412                break;
413            }
414        }
415        if ($pay_flag && $arrRet['payment_id'] != "") {
416            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
417        }
418
419        return $objErr->arrErr;
420    }
421
422    /* 支払い方法文字列の取得 */
423    function lfGetPaymentInfo($payment_id) {
424        $objQuery = new SC_Query();
425        $where = "payment_id = ?";
426        $arrRet = $objQuery->select("charge", "dtb_payment", $where, array($payment_id));
427        return (array($arrRet[0]['charge'], $arrRet[0]['deliv_id']));
428    }
429
430    /* DBへデータの登録 */
431    function lfRegistData($uniqid, &$objPurchase) {
432
433        $sqlval = $this->objFormParam->getDbArray();
434        // 登録データの作成
435        $sqlval['order_temp_id'] = $uniqid;
436        $sqlval['update_date'] = 'Now()';
437
438        if (strlen($sqlval['payment_id']) >= 1) {
439            // FIXME list($sqlval['charge'], $sqlval['deliv_id']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
440        }
441
442        // 使用ポイントの設定
443        if($sqlval['point_check'] != '1') {
444            $sqlval['use_point'] = 0;
445        }
446
447        $objPurchase->saveOrderTemp($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.