source: branches/comu-ver2/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 18311

Revision 18311, 20.1 KB checked in by Seasoft, 15 years ago (diff)

merge r18155
・取得元: version-2_4

  • 真偽値の判定記述をスマートに改修
  • テンプレート上でのセルの重複を改修

【取得元のログメッセージ】

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