source: branches/feature-module-update/data/class/pages/shopping/LC_Page_Shopping_Payment.php @ 15532

Revision 15532, 13.4 KB checked in by nanasess, 17 years ago (diff)

svn:mime-type 修正

  • 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 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7
8// {{{ requires
9require_once(CLASS_PATH . "pages/LC_Page.php");
10
11/**
12 * 支払い方法選択 のページクラス.
13 *
14 * @package Page
15 * @author LOCKON CO.,LTD.
16 * @version $Id$
17 */
18class LC_Page_Shopping_Payment extends LC_Page {
19
20    // {{{ properties
21
22    /** フォームパラメータの配列 */
23    var $objFormParam;
24
25    /** 顧客情報のインスタンス */
26    var $objCustomer;
27
28    // }}}
29    // {{{ functions
30
31    /**
32     * Page を初期化する.
33     *
34     * @return void
35     */
36    function init() {
37        parent::init();
38        $this->tpl_css = URL_DIR.'css/layout/shopping/pay.css';
39        $this->tpl_mainpage = 'shopping/payment.tpl';
40        $this->tpl_onload = 'fnCheckInputPoint();';
41        $this->tpl_title = "お支払方法・お届け時間等の指定";
42
43        $this->allowClientCache();
44    }
45
46    /**
47     * Page のプロセス.
48     *
49     * @return void
50     */
51    function process() {
52        $objView = new SC_SiteView();
53        $objSiteSess = new SC_SiteSession();
54        $objCartSess = new SC_CartSession();
55        $objCampaignSess = new SC_CampaignSession();
56        $this->objCustomer = new SC_Customer();
57        $objSiteInfo = $objView->objSiteInfo;
58        $arrInfo = $objSiteInfo->data;
59
60        // パラメータ管理クラス
61        $this->objFormParam = new SC_FormParam();
62        // パラメータ情報の初期化
63        $this->lfInitParam();
64        // POST値の取得
65        $this->objFormParam->setParam($_POST);
66
67        // ユーザユニークIDの取得と購入状態の正当性をチェック
68        $uniqid = SC_Utils_Ex::sfCheckNormalAccess($objSiteSess, $objCartSess);
69        // ユニークIDを引き継ぐ
70        $this->tpl_uniqid = $uniqid;
71
72        // 会員ログインチェック
73        if($objCustomer->isLoginSuccess()) {
74            $this->tpl_login = '1';
75            $this->tpl_user_point = $objCustomer->getValue('point');
76            //戻り先URL
77            $this->tpl_back_url = URL_DELIV_TOP;
78        } else {
79            $this->tpl_back_url = URL_SHOP_TOP . "?from=nonmember";
80        }
81
82        // 金額の取得 (購入途中で売り切れた場合にはこの関数内にてその商品の個数が0になる)
83        $this = SC_Utils_Ex::sfTotalCart($this, $objCartSess, $arrInfo);
84        $this->arrData = SC_Utils_Ex::sfTotalConfirm($arrData, $this, $objCartSess, $arrInfo);
85
86        // カー都内の商品の売り切れチェック
87        $objCartSess->chkSoldOut($objCartSess->getCartList());
88
89        switch($_POST['mode']) {
90        case 'confirm':
91            // 入力値の変換
92            $this->objFormParam->convParam();
93            $this->arrErr = $this->lfCheckError($this->arrData );
94            // 入力エラーなし
95            if(count($this->arrErr) == 0) {
96                // DBへのデータ登録
97                $this->lfRegistData($uniqid);
98                // 正常に登録されたことを記録しておく
99                $objSiteSess->setRegistFlag();
100                // 確認ページへ移動
101                $this->sendRedirect($this->getLocation(URL_SHOP_CONFIRM, array(), true));
102                exit;
103            }else{
104                // ユーザユニークIDの取得
105                $uniqid = $objSiteSess->getUniqId();
106                // 受注一時テーブルからの情報を格納
107                $this->lfSetOrderTempData($uniqid);
108            }
109            break;
110        // 前のページに戻る
111        case 'return':
112            // 非会員の場合
113            // 正常な推移であることを記録しておく
114            $objSiteSess->setRegistFlag();
115            $this->sendRedirect(URL_SHOP_TOP);
116            exit;
117            break;
118        // 支払い方法が変更された場合
119        case 'payment':
120            // ここのbreakは、意味があるので外さないで下さい。
121            break;
122        default:
123            // 受注一時テーブルからの情報を格納
124            $this->lfSetOrderTempData($uniqid);
125            break;
126        }
127
128        // 店舗情報の取得
129        $arrInfo = $objSiteInfo->data;
130        // 購入金額の取得得
131        $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
132        // 支払い方法の取得
133        $this->arrPayment = $this->lfGetPayment($total_pretax);
134        // 配送時間の取得
135        $arrRet = $this->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
136        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
137        $this->objCustomer = $objCustomer;
138        // 配送日一覧の取得
139        $this->arrDelivDate = $this->lfGetDelivDate();
140
141        $this->arrForm = $this->objFormParam->getFormParamList();
142
143        $objView->assignobj($this);
144        // フレームを選択(キャンペーンページから遷移なら変更)
145        $objCampaignSess->pageView($objView);
146    }
147
148    /**
149     * デストラクタ.
150     *
151     * @return void
152     */
153    function destroy() {
154        parent::destroy();
155    }
156
157    /* パラメータ情報の初期化 */
158    function lfInitParam() {
159        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
160        $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
161        $this->objFormParam->addParam("配達時間", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
162        $this->objFormParam->addParam("ご質問", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
163        $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
164        $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
165    }
166
167    function lfGetPayment($total_pretax) {
168        $objQuery = new SC_Query();
169        $objQuery->setorder("rank DESC");
170        //削除されていない支払方法を取得
171        $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) ");
172        //利用条件から支払可能方法を判定
173        foreach($arrRet as $data) {
174            //下限と上限が設定されている
175            if($data['rule'] > 0 && $data['upper_rule'] > 0) {
176                if($data['rule'] <= $total_pretax && $data['upper_rule'] >= $total_pretax) {
177                    $arrPayment[] = $data;
178                }
179            //下限のみ設定されている
180            } elseif($data['rule'] > 0) {
181                if($data['rule'] <= $total_pretax) {
182                    $arrPayment[] = $data;
183                }
184            //上限のみ設定されている
185            } elseif($data['upper_rule'] > 0) {
186                if($data['upper_rule'] >= $total_pretax) {
187                    $arrPayment[] = $data;
188                }
189            //設定なし
190            } else {
191                $arrPayment[] = $data;
192            }
193        }
194        return $arrPayment;
195    }
196
197    /* 入力内容のチェック */
198    function lfCheckError($arrData) {
199        // 入力データを渡す。
200        $arrRet =  $this->objFormParam->getHashArray();
201        $objErr = new SC_CheckError($arrRet);
202        $objErr->arrErr = $this->objFormParam->checkError();
203
204        if($_POST['point_check'] == '1') {
205            $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK"));
206            $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK"));
207            $max_point = $this->objCustomer->getValue('point');
208            if($max_point == "") {
209                $max_point = 0;
210            }
211            if($arrRet['use_point'] > $max_point) {
212                $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br />";
213            }
214            if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
215                $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br />";
216            }
217        }
218        return $objErr->arrErr;
219    }
220
221    /* 支払い方法文字列の取得 */
222    function lfGetPaymentInfo($payment_id) {
223        $objQuery = new SC_Query();
224        $where = "payment_id = ?";
225        $arrRet = $objQuery->select("payment_method, charge", "dtb_payment", $where, array($payment_id));
226        return (array($arrRet[0]['payment_method'], $arrRet[0]['charge']));
227    }
228
229    /* 配送時間文字列の取得 */
230    function lfGetDelivTimeInfo($time_id) {
231        $objQuery = new SC_Query();
232        $where = "time_id = ?";
233        $arrRet = $objQuery->select("deliv_id, deliv_time", "dtb_delivtime", $where, array($time_id));
234        return (array($arrRet[0]['deliv_id'], $arrRet[0]['deliv_time']));
235    }
236
237    /* DBへデータの登録 */
238    function lfRegistData($uniqid) {
239        $arrRet = $this->objFormParam->getHashArray();
240        $sqlval = $this->objFormParam->getDbArray();
241        // 登録データの作成
242        $sqlval['order_temp_id'] = $uniqid;
243        $sqlval['update_date'] = 'Now()';
244
245        if($sqlval['payment_id'] != "") {
246            list($sqlval['payment_method'], $sqlval['charge']) = lfGetPaymentInfo($sqlval['payment_id']);
247        } else {
248            $sqlval['payment_id'] = '0';
249            $sqlval['payment_method'] = "";
250        }
251
252        if($sqlval['deliv_time_id'] != "") {
253            list($sqlval['deliv_id'], $sqlval['deliv_time']) = lfGetDelivTimeInfo($sqlval['deliv_time_id']);
254        } else {
255            $sqlval['deliv_time_id'] = '0';
256            $sqlval['deliv_id'] = '0';
257            $sqlval['deliv_time'] = "";
258        }
259
260        // 使用ポイントの設定
261        if($sqlval['point_check'] != '1') {
262            $sqlval['use_point'] = 0;
263        }
264
265        $objDb = new SC_Helper_DB_Ex();
266        $objDb->sfRegistTempOrder($uniqid, $sqlval);
267    }
268
269    /* 配達日一覧を取得する */
270    function lfGetDelivDate() {
271        $objCartSess = new SC_CartSession();
272        $objQuery = new SC_Query();
273        // 商品IDの取得
274        $max = $objCartSess->getMax();
275        for($i = 1; $i <= $max; $i++) {
276            if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
277                $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
278            }
279        }
280        if(count($arrID['product_id']) > 0) {
281            $id = implode(",", $arrID['product_id']);
282            //商品から発送目安の取得
283            $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")");
284            //発送目安
285            switch($deliv_date) {
286            //即日発送
287            case '1':
288                $start_day = 1;
289                break;
290            //1-2日後
291            case '2':
292                $start_day = 3;
293                break;
294            //3-4日後
295            case '3':
296                $start_day = 5;
297                break;
298            //1週間以内
299            case '4':
300                $start_day = 8;
301                break;
302            //2週間以内
303            case '5':
304                $start_day = 15;
305                break;
306            //3週間以内
307            case '6':
308                $start_day = 22;
309                break;
310            //1ヶ月以内
311            case '7':
312                $start_day = 32;
313                break;
314            //2ヶ月以降
315            case '8':
316                $start_day = 62;
317                break;
318            //お取り寄せ(商品入荷後)
319            case '9':
320                $start_day = "";
321                break;
322            default:
323                //お届け日が設定されていない場合
324                $start_day = "";
325                break;
326            }
327            //配達可能日のスタート値から、配達日の配列を取得する
328            $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX);
329        }
330        return $arrDelivDate;
331    }
332
333    //配達可能日のスタート値から、配達日の配列を取得する
334    function lfGetDateArray($start_day, $end_day) {
335        $masterData = new SC_DB_MasterData();
336        $arrWDAY = $masterData->getMasterData("mtb_wday");
337        //配達可能日のスタート値がセットされていれば
338        if($start_day >= 1) {
339            $now_time = time();
340            $max_day = $start_day + $end_day;
341            // 集計
342            for ($i = $start_day; $i < $max_day; $i++) {
343                // 基本時間から日数を追加していく
344                $tmp_time = $now_time + ($i * 24 * 3600);
345                list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time));
346                $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
347                $arrDate[$val] = $val;
348            }
349        } else {
350            $arrDate = false;
351        }
352        return $arrDate;
353    }
354
355    //一時受注テーブルからの情報を格納する
356    function lfSetOrderTempData($uniqid) {
357
358        $objQuery = new SC_Query();
359        $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
360        $from = "dtb_order_temp";
361        $where = "order_temp_id = ?";
362        $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
363        // DB値の取得
364        $this->objFormParam->setParam($arrRet[0]);
365        return $this->objFormParam;
366    }
367}
368?>
Note: See TracBrowser for help on using the repository browser.