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 |
---|
25 | require_once(CLASS_REALDIR . "pages/LC_Page.php"); |
---|
26 | |
---|
27 | /** |
---|
28 | * 支払い方法選択 のページクラス. |
---|
29 | * |
---|
30 | * @package Page |
---|
31 | * @author LOCKON CO.,LTD. |
---|
32 | * @version $Id$ |
---|
33 | */ |
---|
34 | class 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 | // 戻るボタンの処理(モバイル) |
---|
142 | if (Net_UserAgent_Mobile::isMobile() === true) { |
---|
143 | if (!empty($_POST['return'])) { |
---|
144 | switch ($_POST['mode']) { |
---|
145 | case 'confirm': |
---|
146 | $_POST['mode'] = 'payment'; |
---|
147 | break; |
---|
148 | default: |
---|
149 | // 正常な推移であることを記録しておく |
---|
150 | $objSiteSess->setRegistFlag(); |
---|
151 | if ($this->cartdown == 2) { |
---|
152 | // ダウンロード商品のみの場合はカート画面へ戻る |
---|
153 | SC_Response_Ex::sendRedirect(CART_URL_PATH); |
---|
154 | } else { |
---|
155 | SC_Response_Ex::sendRedirect(SHOPPING_URL); |
---|
156 | } |
---|
157 | exit; |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | |
---|
162 | switch($_POST['mode']) { |
---|
163 | // お届け日時指定(モバイル) |
---|
164 | case 'deliv_date': |
---|
165 | // 入力値の変換 |
---|
166 | $this->objFormParam->convParam(); |
---|
167 | $this->arrErr = $this->lfCheckError($this->arrData, $this->arrPayment); |
---|
168 | if (!isset($this->arrErr['payment_id'])) { |
---|
169 | // 支払い方法の入力エラーなし |
---|
170 | $this->tpl_mainpage = 'shopping/deliv_date.tpl'; |
---|
171 | $this->tpl_title = "お届け日時指定"; |
---|
172 | break; |
---|
173 | } else { |
---|
174 | // ユーザユニークIDの取得 |
---|
175 | $uniqid = $objSiteSess->getUniqId(); |
---|
176 | // 受注一時テーブルからの情報を格納 |
---|
177 | $this->lfSetOrderTempData($uniqid); |
---|
178 | } |
---|
179 | break; |
---|
180 | case 'confirm': |
---|
181 | // 入力値の変換 |
---|
182 | $this->objFormParam->convParam(); |
---|
183 | $this->arrErr = $this->lfCheckError($this->arrData, $this->arrPayment); |
---|
184 | // 入力エラーなし |
---|
185 | if(count($this->arrErr) == 0) { |
---|
186 | // DBへのデータ登録 |
---|
187 | $this->lfRegistData($uniqid, $objPurchase); |
---|
188 | $_SESSION['shipping'][0]['time_id'] = $this->objFormParam->getValue('deliv_time_id'); |
---|
189 | $_SESSION['shipping'][0]['deliv_date'] = $this->objFormParam->getValue('deliv_date'); |
---|
190 | // 正常に登録されたことを記録しておく |
---|
191 | $objSiteSess->setRegistFlag(); |
---|
192 | // 確認ページへ移動 |
---|
193 | SC_Response_Ex::sendRedirect(SHOPPING_CONFIRM_URL_PATH); |
---|
194 | exit; |
---|
195 | }else{ |
---|
196 | // ユーザユニークIDの取得 |
---|
197 | $uniqid = $objSiteSess->getUniqId(); |
---|
198 | // 受注一時テーブルからの情報を格納 |
---|
199 | $this->lfSetOrderTempData($uniqid); |
---|
200 | if (Net_UserAgent_Mobile::isMobile() === true && !isset($this->arrErr['payment_id'])) { |
---|
201 | // 支払い方法の入力エラーなし |
---|
202 | $this->tpl_mainpage = 'shopping/deliv_date.tpl'; |
---|
203 | $this->tpl_title = "お届け日時指定"; |
---|
204 | } |
---|
205 | } |
---|
206 | break; |
---|
207 | // 前のページに戻る |
---|
208 | case 'return': |
---|
209 | // 非会員の場合 |
---|
210 | // 正常な推移であることを記録しておく |
---|
211 | $objSiteSess->setRegistFlag(); |
---|
212 | SC_Response_Ex::sendRedirect(SHOPPING_URL); |
---|
213 | exit; |
---|
214 | break; |
---|
215 | |
---|
216 | default: |
---|
217 | // 受注一時テーブルからの情報を格納 |
---|
218 | $this->objFormParam->setParam($arrOrderTemp); |
---|
219 | break; |
---|
220 | } |
---|
221 | |
---|
222 | // 配送時間を取得 |
---|
223 | $this->arrDelivTime = $objPurchase->getDelivTime($this->cartKey); |
---|
224 | |
---|
225 | // 支払い方法の画像があるなしを取得($img_show true:ある false:なし) |
---|
226 | $this->img_show = $this->lfGetImgShow($this->arrPayment); |
---|
227 | // FIXME お届け日一覧の取得 |
---|
228 | $this->arrDelivDate = $this->lfGetDelivDate(); |
---|
229 | |
---|
230 | $this->arrForm = $this->objFormParam->getFormParamList(); |
---|
231 | } |
---|
232 | |
---|
233 | /** |
---|
234 | * デストラクタ. |
---|
235 | * |
---|
236 | * @return void |
---|
237 | */ |
---|
238 | function destroy() { |
---|
239 | parent::destroy(); |
---|
240 | } |
---|
241 | |
---|
242 | /* パラメータ情報の初期化 */ |
---|
243 | function lfInitParam() { |
---|
244 | $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
245 | $this->objFormParam->addParam("ポイント", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START")); |
---|
246 | $this->objFormParam->addParam("ご質問", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); |
---|
247 | $this->objFormParam->addParam("ポイントを使用する", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2'); |
---|
248 | |
---|
249 | for ($i = 0; $i < count($this->shipping); $i++) { |
---|
250 | $this->objFormParam->addParam("お届け時間", "deliv_time_id" . $i, INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); |
---|
251 | $this->objFormParam->addParam("お届け日", "deliv_date" . $i, STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK")); |
---|
252 | } |
---|
253 | } |
---|
254 | |
---|
255 | |
---|
256 | /* 入力内容のチェック */ |
---|
257 | function lfCheckError($arrData, $arrPayment) { |
---|
258 | // 入力データを渡す。 |
---|
259 | $arrRet = $this->objFormParam->getHashArray(); |
---|
260 | $objErr = new SC_CheckError($arrRet); |
---|
261 | $objErr->arrErr = $this->objFormParam->checkError(); |
---|
262 | |
---|
263 | if (USE_POINT === false) { |
---|
264 | $_POST['point_check'] = ""; |
---|
265 | $_POST['use_point'] = "0"; |
---|
266 | } |
---|
267 | |
---|
268 | if (!isset($_POST['point_check'])) $_POST['point_check'] = ""; |
---|
269 | |
---|
270 | if($_POST['point_check'] == '1') { |
---|
271 | $objErr->doFunc(array("ポイントを使用する", "point_check"), array("EXIST_CHECK")); |
---|
272 | $objErr->doFunc(array("ポイント", "use_point"), array("EXIST_CHECK")); |
---|
273 | $max_point = $this->objCustomer->getValue('point'); |
---|
274 | if($max_point == "") { |
---|
275 | $max_point = 0; |
---|
276 | } |
---|
277 | // FIXME mobile 互換のため br は閉じない... |
---|
278 | if($arrRet['use_point'] > $max_point) { |
---|
279 | $objErr->arrErr['use_point'] = "※ ご利用ポイントが所持ポイントを超えています。<br>"; |
---|
280 | } |
---|
281 | if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) { |
---|
282 | $objErr->arrErr['use_point'] = "※ ご利用ポイントがご購入金額を超えています。<br>"; |
---|
283 | } |
---|
284 | } |
---|
285 | |
---|
286 | $objCartSess = new SC_CartSession(); |
---|
287 | // 購入金額の取得得 |
---|
288 | $total_inctax = $objCartSess->getAllProductsTotal($this->cartKey); |
---|
289 | $pay_flag = true; |
---|
290 | foreach ($arrPayment as $key => $payment) { |
---|
291 | if ($payment['payment_id'] == $arrRet['payment_id']) { |
---|
292 | $pay_flag = false; |
---|
293 | break; |
---|
294 | } |
---|
295 | } |
---|
296 | if ($pay_flag && $arrRet['payment_id'] != "") { |
---|
297 | SC_Utils_Ex::sfDispSiteError(CUSTOMER_ERROR); |
---|
298 | } |
---|
299 | |
---|
300 | return $objErr->arrErr; |
---|
301 | } |
---|
302 | |
---|
303 | /* 支払い方法文字列の取得 */ |
---|
304 | function lfGetPaymentInfo($payment_id) { |
---|
305 | $objQuery = new SC_Query(); |
---|
306 | $where = "payment_id = ?"; |
---|
307 | $arrRet = $objQuery->select("charge", "dtb_payment", $where, array($payment_id)); |
---|
308 | return (array($arrRet[0]['charge'], $arrRet[0]['deliv_id'])); |
---|
309 | } |
---|
310 | |
---|
311 | /* DBへデータの登録 */ |
---|
312 | function lfRegistData($uniqid, &$objPurchase) { |
---|
313 | |
---|
314 | $sqlval = $this->objFormParam->getDbArray(); |
---|
315 | // 登録データの作成 |
---|
316 | $sqlval['order_temp_id'] = $uniqid; |
---|
317 | $sqlval['update_date'] = 'Now()'; |
---|
318 | |
---|
319 | if (strlen($sqlval['payment_id']) >= 1) { |
---|
320 | // FIXME list($sqlval['charge'], $sqlval['deliv_id']) = $this->lfGetPaymentInfo($sqlval['payment_id']); |
---|
321 | } |
---|
322 | |
---|
323 | // 使用ポイントの設定 |
---|
324 | if($sqlval['point_check'] != '1') { |
---|
325 | $sqlval['use_point'] = 0; |
---|
326 | } |
---|
327 | |
---|
328 | $objPurchase->saveOrderTemp($uniqid, $sqlval); |
---|
329 | } |
---|
330 | |
---|
331 | /* お届け日一覧を取得する */ |
---|
332 | function lfGetDelivDate() { |
---|
333 | $objCartSess = new SC_CartSession(); |
---|
334 | $objQuery = new SC_Query(); |
---|
335 | // 商品IDの取得 |
---|
336 | $max = $objCartSess->getMax(); |
---|
337 | for($i = 1; $i <= $max; $i++) { |
---|
338 | if($_SESSION[$objCartSess->key][$i]['id'][0] != "") { |
---|
339 | $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0]; |
---|
340 | } |
---|
341 | } |
---|
342 | if(count($arrID['product_id']) > 0) { |
---|
343 | $id = implode(",", $arrID['product_id']); |
---|
344 | //商品から発送目安の取得 |
---|
345 | $deliv_date = $objQuery->get("MAX(deliv_date_id)", "dtb_products", "product_id IN (".$id.")"); |
---|
346 | //発送目安 |
---|
347 | switch($deliv_date) { |
---|
348 | //即日発送 |
---|
349 | case '1': |
---|
350 | $start_day = 1; |
---|
351 | break; |
---|
352 | //1-2日後 |
---|
353 | case '2': |
---|
354 | $start_day = 3; |
---|
355 | break; |
---|
356 | //3-4日後 |
---|
357 | case '3': |
---|
358 | $start_day = 5; |
---|
359 | break; |
---|
360 | //1週間以内 |
---|
361 | case '4': |
---|
362 | $start_day = 8; |
---|
363 | break; |
---|
364 | //2週間以内 |
---|
365 | case '5': |
---|
366 | $start_day = 15; |
---|
367 | break; |
---|
368 | //3週間以内 |
---|
369 | case '6': |
---|
370 | $start_day = 22; |
---|
371 | break; |
---|
372 | //1ヶ月以内 |
---|
373 | case '7': |
---|
374 | $start_day = 32; |
---|
375 | break; |
---|
376 | //2ヶ月以降 |
---|
377 | case '8': |
---|
378 | $start_day = 62; |
---|
379 | break; |
---|
380 | //お取り寄せ(商品入荷後) |
---|
381 | case '9': |
---|
382 | $start_day = ""; |
---|
383 | break; |
---|
384 | default: |
---|
385 | //お届け日が設定されていない場合 |
---|
386 | $start_day = ""; |
---|
387 | break; |
---|
388 | } |
---|
389 | //お届け可能日のスタート値から、お届け日の配列を取得する |
---|
390 | $arrDelivDate = $this->lfGetDateArray($start_day, DELIV_DATE_END_MAX); |
---|
391 | } |
---|
392 | return $arrDelivDate; |
---|
393 | } |
---|
394 | |
---|
395 | //お届け可能日のスタート値から、お届け日の配列を取得する |
---|
396 | function lfGetDateArray($start_day, $end_day) { |
---|
397 | $masterData = new SC_DB_MasterData(); |
---|
398 | $arrWDAY = $masterData->getMasterData("mtb_wday"); |
---|
399 | //お届け可能日のスタート値がセットされていれば |
---|
400 | if($start_day >= 1) { |
---|
401 | $now_time = time(); |
---|
402 | $max_day = $start_day + $end_day; |
---|
403 | // 集計 |
---|
404 | for ($i = $start_day; $i < $max_day; $i++) { |
---|
405 | // 基本時間から日数を追加していく |
---|
406 | $tmp_time = $now_time + ($i * 24 * 3600); |
---|
407 | list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time)); |
---|
408 | $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]); |
---|
409 | $arrDate[$val] = $val; |
---|
410 | } |
---|
411 | } else { |
---|
412 | $arrDate = false; |
---|
413 | } |
---|
414 | return $arrDate; |
---|
415 | } |
---|
416 | |
---|
417 | //一時受注テーブルからの情報を格納する |
---|
418 | function lfSetOrderTempData($uniqid) { |
---|
419 | $objQuery = new SC_Query(); |
---|
420 | $col = "payment_id, use_point, message, point_check "; |
---|
421 | $from = "dtb_order_temp"; |
---|
422 | $where = "order_temp_id = ?"; |
---|
423 | $arrRet = $objQuery->select($col, $from, $where, array($uniqid)); |
---|
424 | // DB値の取得 |
---|
425 | $this->objFormParam->setParam($arrRet[0]); |
---|
426 | return $this->objFormParam; |
---|
427 | } |
---|
428 | |
---|
429 | /* 支払い方法の画像があるなしを取得($img_show true:ある false:なし) */ |
---|
430 | function lfGetImgShow($arrPayment) { |
---|
431 | $img_show = false; |
---|
432 | foreach ($arrPayment as $payment) { |
---|
433 | if (strlen($payment["payment_image"]) > 0 ){ |
---|
434 | $img_show = true; |
---|
435 | break; |
---|
436 | } |
---|
437 | } |
---|
438 | return $img_show; |
---|
439 | } |
---|
440 | |
---|
441 | /* 配送時間の配列を生成 */ |
---|
442 | function lfSetDelivTime() { |
---|
443 | $objDb = new SC_Helper_DB_Ex(); |
---|
444 | $objJson = new Services_JSON; |
---|
445 | |
---|
446 | // 配送時間の取得 |
---|
447 | $arrRet = $objDb->sfGetDelivTime($this->cartKey); |
---|
448 | // JSONエンコード |
---|
449 | echo $objJson->encode($arrRet); |
---|
450 | exit; |
---|
451 | } |
---|
452 | } |
---|
453 | ?> |
---|