Warning: Can't use blame annotator:
svn blame failed on branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php: バイナリファイル 'file:///home/svn/open/branches/version-2_5-dev/data/class/pages/shopping/LC_Page_Shopping_Payment.php' に対しては blame で各行の最終変更者を計算できません 195004

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

Revision 18777, 22.5 KB checked in by eccuore, 14 years ago (diff)

#792(ダウンロード販売機能) 機能追加

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