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

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