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

Revision 15613, 13.6 KB checked in by nanasess, 17 years ago (diff)

リファクタリング

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