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

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

#472「管理機能の配送業者の追加でエラー」を修正。

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