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

Revision 19782, 22.5 KB checked in by nanasess, 13 years ago (diff)

#748(モバイル/スマートフォンのデザイン管理)

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