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

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