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

Revision 19729, 22.5 KB checked in by Seasoft, 13 years ago (diff)

#855(SC_Query の #select, #getRow, #getCol, #get, #min, #max の引数順を統一する)

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