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

Revision 19915, 14.5 KB checked in by kotani, 13 years ago (diff)

#754 モバイルサイト ポイント機能対応

  • 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_REALDIR . "pages/LC_Page.php");
26
27/**
28 * 支払い方法選択 のページクラス.
29 *
30 * @package Page
31 * @author LOCKON CO.,LTD.
32 * @version $Id$
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_onload = "fnCheckInputPoint(); fnSetDelivTime('payment','payment_id','deliv_time_id');";
55        $this->tpl_title = "お支払方法・お届け時間等の指定";
56        $masterData = new SC_DB_MasterData();
57        $this->arrPref = $masterData->getMasterData('mtb_pref');
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        $objPurchase = new SC_Helper_Purchase_Ex();
80        $this->objCustomer = new SC_Customer();
81
82        $this->shipping =& $objPurchase->getShippingTemp();
83        $this->isMultiple = $objPurchase->isMultiple();
84
85        // パラメータ管理クラス
86        $this->objFormParam = new SC_FormParam();
87        // パラメータ情報の初期化
88        $this->lfInitParam();
89        // POST値の取得
90        $this->objFormParam->setParam($_POST);
91
92        $uniqid = $objSiteSess->getUniqId();
93        $objPurchase->verifyChangeCart($uniqid, $objCartSess);
94
95        // ユニークIDを引き継ぐ
96        $this->tpl_uniqid = $uniqid;
97
98        $this->cartKey = $objCartSess->getKey();
99
100        // 会員ログインチェック
101        if($this->objCustomer->isLoginSuccess()) {
102            $this->tpl_login = '1';
103            $this->tpl_user_point = $this->objCustomer->getValue('point');
104            //戻り先URL
105            if ($this->cartKey == PRODUCT_TYPE_DOWNLOAD) {
106                // ダウンロード商品のみの場合はカート画面へ戻る
107                $this->tpl_back_url = CART_URL_PATH;
108            } else {
109                $this->tpl_back_url = DELIV_URL_PATH;
110            }
111        } else {
112            $this->tpl_back_url = SHOPPING_URL . "?from=nonmember";
113        }
114
115        // 一時受注テーブルの読込
116        $arrOrderTemp = $objPurchase->getOrderTemp($uniqid);
117        //不正遷移チェック(正常に受注情報が格納されていない場合は一旦カート画面まで戻す)
118        if (!$arrOrderTemp) {
119            SC_Response_Ex::sendRedirect(CART_URL_PATH);
120            exit;
121        }
122
123        // カート内商品の集計処理を行う
124        $this->cartItems = $objCartSess->getCartList($this->cartKey);
125        $this->tpl_message = $objCartSess->checkProducts($this->cartKey);
126
127        if (strlen($this->tpl_message) >= 1) {
128            SC_Utils_Ex::sfDispSiteError(SOLD_OUT, '', true);
129        }
130        // FIXME 使用ポイント, 配送都道府県, 支払い方法, 手数料の扱い
131        $this->arrData = $objCartSess->calculate($this->cartKey, $objCustomer);
132
133        // 購入金額の取得
134        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
135
136        // 支払い方法の取得
137        $this->arrPayment = $objPurchase->getPayment($total_inctax, $objCartSess->getAllProductClassID($this->cartKey));
138
139        if (!isset($_POST['mode'])) $_POST['mode'] = "";
140
141        switch($_POST['mode']) {
142        case 'confirm':
143            // 入力値の変換
144            $this->objFormParam->convParam();
145            $this->arrErr = $this->lfCheckError($this->arrData, $this->arrPayment);
146            // 入力エラーなし
147            if(count($this->arrErr) == 0) {
148                // DBへのデータ登録
149                $this->lfRegistData($uniqid, $objPurchase);
150                $_SESSION['shipping'][0]['time_id'] = $this->objFormParam->getValue('deliv_time_id');
151                $_SESSION['shipping'][0]['deliv_date'] = $this->objFormParam->getValue('deliv_date');
152                // 正常に登録されたことを記録しておく
153                $objSiteSess->setRegistFlag();
154                // 確認ページへ移動
155                SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URL_PATH);
156                exit;
157            }else{
158                // ユーザユニークIDの取得
159                $uniqid = $objSiteSess->getUniqId();
160                // 受注一時テーブルからの情報を格納
161                $this->lfSetOrderTempData($uniqid);
162            }
163            break;
164        // 前のページに戻る
165        case 'return':
166            // 非会員の場合
167            // 正常な推移であることを記録しておく
168            $objSiteSess->setRegistFlag();
169            SC_Response_Ex::sendRedirect(SHOPPING_URL);
170            exit;
171            break;
172
173        default:
174            // 受注一時テーブルからの情報を格納
175            $this->objFormParam->setParam($arrOrderTemp);
176            break;
177        }
178
179        // 配送時間を取得
180        $this->arrDelivTime = $objPurchase->getDelivTime($this->cartKey);
181
182        // 支払い方法の画像があるなしを取得($img_show true:ある false:なし)
183        $this->img_show = $this->lfGetImgShow($this->arrPayment);
184        // FIXME お届け日一覧の取得
185        $this->arrDelivDate = $this->lfGetDelivDate();
186
187        $this->arrForm = $this->objFormParam->getFormParamList();
188    }
189
190    /**
191     * デストラクタ.
192     *
193     * @return void
194     */
195    function destroy() {
196        parent::destroy();
197    }
198
199    /* パラメータ情報の初期化 */
200    function lfInitParam() {
201        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
202        $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
203        $this->objFormParam->addParam("その他お問い合わせ", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
204        $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
205
206        for ($i = 0; $i < count($this->shipping); $i++) {
207            $this->objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
208            $this->objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
209        }
210    }
211
212 
213    /* 入力内容のチェック */
214    function lfCheckError($arrData, $arrPayment) {
215        // 入力データを渡す。
216        $arrRet =  $this->objFormParam->getHashArray();
217        $objErr = new SC_CheckError($arrRet);
218        $objErr->arrErr = $this->objFormParam->checkError();
219
220        if (USE_POINT === false) {
221            $_POST['point_check'] = "";
222            $_POST['use_point'] = "0";
223        }
224
225        if (!isset($_POST['point_check'])) $_POST['point_check'] = "";
226
227        if($_POST['point_check'] == '1') {
228            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
229            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
230            $max_point = $this->objCustomer->getValue('point');
231            if($max_point == "") {
232                $max_point = 0;
233            }
234            // FIXME mobile 互換のため br は閉じない...
235            if($arrRet['use_point'] > $max_point) {
236                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>";
237            }
238            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
239                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>";
240            }
241        }
242
243        $objCartSess = new SC_CartSession();
244        // 購入金額の取得得
245        $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey);
246        $pay_flag = true;
247        foreach ($arrPayment as $key => $payment) {
248            if ($payment['payment_id'] == $arrRet['payment_id']) {
249                $pay_flag = false;
250                break;
251            }
252        }
253        if ($pay_flag && $arrRet['payment_id'] != "") {
254            SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR);
255        }
256
257        return $objErr->arrErr;
258    }
259
260    /* 支払い方法文字列の取得 */
261    function lfGetPaymentInfo($payment_id) {
262        $objQuery = new SC_Query();
263        $where = "payment_id = ?";
264        $arrRet = $objQuery->select("charge", "dtb_payment", $where, array($payment_id));
265        return (array($arrRet[0]['charge'], $arrRet[0]['deliv_id']));
266    }
267
268    /* DBへデータの登録 */
269    function lfRegistData($uniqid, &$objPurchase) {
270
271        $sqlval = $this->objFormParam->getDbArray();
272        // 登録データの作成
273        $sqlval['order_temp_id'] = $uniqid;
274        $sqlval['update_date'] = 'Now()';
275
276        if (strlen($sqlval['payment_id']) >= 1) {
277            // FIXME list($sqlval['charge'], $sqlval['deliv_id']) = $this->lfGetPaymentInfo($sqlval['payment_id']);
278        }
279
280        // 使用ポイントの設定
281        if($sqlval['point_check'] != '1') {
282            $sqlval['use_point'] = 0;
283        }
284
285        $objPurchase->saveOrderTemp($uniqid, $sqlval);
286    }
287
288    /* お届け日一覧を取得する */
289    function lfGetDelivDate() {
290        $objCartSess = new SC_CartSession();
291        $objQuery = new SC_Query();
292        // 商品IDの取得
293        $max = $objCartSess->getMax();
294        for($i = 1; $i <= $max; $i++) {
295            if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
296                $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
297            }
298        }
299        if(count($arrID['product_id']) > 0) {
300            $id = implode(",", $arrID['product_id']);
301            //商品から発送目安の取得
302            $deliv_date = $objQuery->get("MAX(deliv_date_id)", "dtb_products", "product_id IN (".$id.")");
303            //発送目安
304            switch($deliv_date) {
305            //即日発送
306            case '1':
307                $start_day = 1;
308                break;
309            //1-2日後
310            case '2':
311                $start_day = 3;
312                break;
313            //3-4日後
314            case '3':
315                $start_day = 5;
316                break;
317            //1週間以内
318            case '4':
319                $start_day = 8;
320                break;
321            //2週間以内
322            case '5':
323                $start_day = 15;
324                break;
325            //3週間以内
326            case '6':
327                $start_day = 22;
328                break;
329            //1ヶ月以内
330            case '7':
331                $start_day = 32;
332                break;
333            //2ヶ月以降
334            case '8':
335                $start_day = 62;
336                break;
337            //お取り寄せ(商品入荷後)
338            case '9':
339                $start_day = "";
340                break;
341            default:
342                //お届け日が設定されていない場合
343                $start_day = "";
344                break;
345            }
346            //お届け可能日のスタート値から、お届け日の配列を取得する
347            $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX);
348        }
349        return $arrDelivDate;
350    }
351
352    //お届け可能日のスタート値から、お届け日の配列を取得する
353    function lfGetDateArray($start_day, $end_day) {
354        $masterData = new SC_DB_MasterData();
355        $arrWDAY = $masterData->getMasterData("mtb_wday");
356        //お届け可能日のスタート値がセットされていれば
357        if($start_day >= 1) {
358            $now_time = time();
359            $max_day = $start_day + $end_day;
360            // 集計
361            for ($i = $start_day; $i < $max_day; $i++) {
362                // 基本時間から日数を追加していく
363                $tmp_time = $now_time + ($i * 24 * 3600);
364                list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time));
365                $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
366                $arrDate[$val] = $val;
367            }
368        } else {
369            $arrDate = false;
370        }
371        return $arrDate;
372    }
373
374    //一時受注テーブルからの情報を格納する
375    function lfSetOrderTempData($uniqid) {
376        $objQuery = new SC_Query();
377        $col = "payment_id, use_point, message, point_check ";
378        $from = "dtb_order_temp";
379        $where = "order_temp_id = ?";
380        $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
381        // DB値の取得
382        $this->objFormParam->setParam($arrRet[0]);
383        return $this->objFormParam;
384    }
385
386    /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */
387    function lfGetImgShow($arrPayment) {
388        $img_show = false;
389        foreach ($arrPayment as $payment) {
390            if (strlen($payment["payment_image"]) > 0 ){
391                $img_show = true;
392                break;
393            }
394        }
395        return $img_show;
396    }
397
398    /* 配送時間の配列を生成 */
399    function lfSetDelivTime() {
400        $objDb = new SC_Helper_DB_Ex();
401        $objJson = new Services_JSON;
402
403        // 配送時間の取得
404        $arrRet = $objDb->sfGetDelivTime($this->cartKey);
405        // JSONエンコード
406        echo $objJson->encode($arrRet);
407        exit;
408    }
409}
410?>
Note: See TracBrowser for help on using the repository browser.