source: branches/version-1/html/mobile/nonmember/payment.php @ 17690

Revision 17690, 11.6 KB checked in by takegami, 18 years ago (diff)

#397-392 モバイル解決

Line 
1<?php
2/**
3 *
4 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
5 *
6 * http://www.lockon.co.jp/
7 *
8 */
9
10require_once("../require.php");
11
12class LC_Page {
13    var $arrSession;
14    var $tpl_mode;
15    function LC_Page() {
16        $this->tpl_css = '/css/layout/shopping/pay.css';
17        $this->tpl_mainpage = 'nonmember/payment.tpl';
18        $this->tpl_onload = 'fnCheckInputPoint();';
19        $this->tpl_title = "¤ª»ÙʧÊýË¡¤Î»ØÄê";
20        /*
21         session_start»þ¤Îno-cache¥Ø¥Ã¥À¡¼¤òÍÞÀ©¤¹¤ë¤³¤È¤Ç
22         ¡ÖÌá¤ë¡×¥Ü¥¿¥ó»ÈÍÑ»þ¤ÎÍ­¸ú´ü¸ÂÀÚ¤ìɽ¼¨¤òÍÞÀ©¤¹¤ë¡£
23         private-no-expire:¥¯¥é¥¤¥¢¥ó¥È¤Î¥­¥ã¥Ã¥·¥å¤òµö²Ä¤¹¤ë¡£
24        */
25        session_cache_limiter('private-no-expire');     
26    }
27}
28
29$objPage = new LC_Page();
30$objView = new SC_MobileView();
31$objSiteSess = new SC_SiteSession();
32$objCartSess = new SC_CartSession();
33$objCustomer = new SC_Customer();
34$objSiteInfo = $objView->objSiteInfo;
35$arrInfo = $objSiteInfo->data;
36
37// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
38$objFormParam = new SC_FormParam();
39// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
40lfInitParam();
41// POSTÃͤμèÆÀ
42$objFormParam->setParam($_POST);
43// ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ¤È¹ØÆþ¾õÂÖ¤ÎÀµÅöÀ­¤ò¥Á¥§¥Ã¥¯
44$uniqid = sfCheckNormalAccess($objSiteSess, $objCartSess);
45// ¥æ¥Ë¡¼¥¯ID¤ò°ú¤­·Ñ¤°
46$objPage->tpl_uniqid = $uniqid;
47
48// ²ñ°÷¥í¥°¥¤¥ó¥Á¥§¥Ã¥¯
49if($objCustomer->isLoginSuccess()) {
50    $objPage->tpl_login = '1';
51    $objPage->tpl_user_point = $objCustomer->getValue('point');
52}
53
54// ¶â³Û¤Î¼èÆÀ (¹ØÆþÅÓÃæ¤ÇÇä¤êÀڤ줿¾ì¹ç¤Ë¤Ï¤³¤Î´Ø¿ôÆâ¤Ë¤Æ¤½¤Î¾¦ÉʤθĿô¤¬£°¤Ë¤Ê¤ë)
55$objPage = sfTotalCart($objPage, $objCartSess, $arrInfo);
56$objPage->arrData = sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo);
57
58// ¥«¡¼ÅÔÆâ¤Î¾¦ÉʤÎÇä¤êÀÚ¤ì¥Á¥§¥Ã¥¯
59$objCartSess->chkSoldOut($objCartSess->getCartList(), true);
60
61// Ìá¤ë¥Ü¥¿¥ó¤Î½èÍý
62if (!empty($_POST['return'])) {
63    switch ($_POST['mode']) {
64    case 'confirm':
65        $_POST['mode'] = 'payment';
66        break;
67    default:
68        // Àµ¾ï¤Ê¿ä°Ü¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
69        $objSiteSess->setRegistFlag();
70        //header("Location: " . gfAddSessionId(MOBILE_URL_SHOP_TOP));
71        header("Location: " . gfAddSessionId('../nonmember/deliv.php'));
72        exit;
73//        $_POST['mode'] = "deliv_date";
74    }
75}
76
77switch($_POST['mode']) {
78// »Ùʧ¤¤ÊýË¡»ØÄê ¢ª ÇÛãÆü»þ»ØÄê
79case 'deliv_date':
80   
81    // ÆþÎÏÃͤÎÊÑ´¹
82    $objFormParam->convParam();
83    $objPage->arrErr = lfCheckError($objPage->arrData);
84    if (!isset($objPage->arrErr['payment_id'])) {
85        // »Ùʧ¤¤ÊýË¡¤ÎÆþÎÏ¥¨¥é¡¼¤Ê¤·
86        $objPage->tpl_mainpage = 'nonmember/deliv_date.tpl';
87        $objPage->tpl_title = "ÇÛãÆü»þ»ØÄê";
88        break;
89    } else {
90        // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
91        $uniqid = $objSiteSess->getUniqId();
92        // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
93        lfSetOrderTempData($uniqid);
94    }
95    break;
96case 'confirm':
97    // ÆþÎÏÃͤÎÊÑ´¹
98    $objFormParam->convParam();
99    $objPage->arrErr = lfCheckError($objPage->arrData );
100    // ÆþÎÏ¥¨¥é¡¼¤Ê¤·
101    if(count($objPage->arrErr) == 0) {
102        // DB¤Ø¤Î¥Ç¡¼¥¿ÅÐÏ¿
103        lfRegistData($uniqid);
104        // Àµ¾ï¤ËÅÐÏ¿¤µ¤ì¤¿¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
105        $objSiteSess->setRegistFlag();
106        // ³Îǧ¥Ú¡¼¥¸¤Ø°Üư
107        //header("Location: " . gfAddSessionId(MOBILE_URL_SHOP_CONFIRM));
108        header("Location: " . gfAddSessionId('./confirm.php'));
109        exit;
110    }else{
111        // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
112        $uniqid = $objSiteSess->getUniqId();
113        // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
114        lfSetOrderTempData($uniqid);
115        if (!isset($objPage->arrErr['payment_id'])) {
116            // »Ùʧ¤¤ÊýË¡¤ÎÆþÎÏ¥¨¥é¡¼¤Ê¤·
117            $objPage->tpl_mainpage = 'nonmember/deliv_date.tpl';
118            $objPage->tpl_title = "ÇÛãÆü»þ»ØÄê";
119        }
120    }
121    break;
122// Á°¤Î¥Ú¡¼¥¸¤ËÌá¤ë
123case 'return':
124    // Èó²ñ°÷¤Î¾ì¹ç
125    // Àµ¾ï¤Ê¿ä°Ü¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
126    $objSiteSess->setRegistFlag();
127    header("Location: " . gfAddSessionId('../shopping/index.php'));
128    exit;
129    break;
130// »Ùʧ¤¤ÊýË¡¤¬Êѹ¹¤µ¤ì¤¿¾ì¹ç
131case 'payment':
132    // ¤³¤³¤Îbreak¤Ï¡¢°ÕÌ£¤¬¤¢¤ë¤Î¤Ç³°¤µ¤Ê¤¤¤Ç²¼¤µ¤¤¡£
133    break;
134default:
135    // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
136    lfSetOrderTempData($uniqid);
137    break;
138}
139
140// ŹÊÞ¾ðÊó¤Î¼èÆÀ
141$arrInfo = $objSiteInfo->data;
142// ¹ØÆþ¶â³Û¤Î¼èÆÀÆÀ
143$total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
144// »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
145$objPage->arrPayment = lfGetPayment($total_pretax);
146// ÇÛÁ÷»þ´Ö¤Î¼èÆÀ
147$arrRet = sfGetDelivTime($objFormParam->getValue('payment_id'));
148$objPage->arrDelivTime = sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
149$objPage->objCustomer = $objCustomer;
150//¡¡ÇÛÁ÷Æü°ìÍ÷¤Î¼èÆÀ
151$objPage->arrDelivDate = lfGetDelivDate();
152
153$objPage->arrForm = $objFormParam->getFormParamList();
154
155$objView->assignobj($objPage);
156$objView->display(SITE_FRAME);
157//--------------------------------------------------------------------------------------------------------------------------
158/* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */
159function lfInitParam() {
160    global $objFormParam;
161    $objFormParam->addParam("¤ª»Ùʧ¤¤ÊýË¡", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
162    $objFormParam->addParam("¥Ý¥¤¥ó¥È", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
163    $objFormParam->addParam("ÇÛã»þ´Ö", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
164    $objFormParam->addParam("¤´¼ÁÌä", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
165    $objFormParam->addParam("¥Ý¥¤¥ó¥È¤ò»ÈÍѤ¹¤ë", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
166    $objFormParam->addParam("ÇÛãÆü", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
167}
168
169function lfGetPayment($total_pretax) {
170    $objQuery = new SC_Query();
171    $objQuery->setorder("rank DESC");
172    //ºï½ü¤µ¤ì¤Æ¤¤¤Ê¤¤»ÙʧÊýË¡¤ò¼èÆÀ
173    $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) ");
174    //ÍøÍѾò·ï¤«¤é»Ùʧ²ÄǽÊýË¡¤òȽÄê
175    foreach($arrRet as $data) {
176        //²¼¸Â¤È¾å¸Â¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
177        if($data['rule'] > 0 && $data['upper_rule'] > 0) {
178            if($data['rule'] <= $total_pretax && $data['upper_rule'] >= $total_pretax) {
179                $arrPayment[] = $data;
180            }
181        //²¼¸Â¤Î¤ßÀßÄꤵ¤ì¤Æ¤¤¤ë
182        } elseif($data['rule'] > 0) {   
183            if($data['rule'] <= $total_pretax) {
184                $arrPayment[] = $data;
185            }
186        //¾å¸Â¤Î¤ßÀßÄꤵ¤ì¤Æ¤¤¤ë
187        } elseif($data['upper_rule'] > 0) {
188            if($data['upper_rule'] >= $total_pretax) {
189                $arrPayment[] = $data;
190            }
191        //ÀßÄê¤Ê¤·
192        } else {
193            $arrPayment[] = $data;
194        }   
195    }
196    return $arrPayment;
197}
198
199/* ÆþÎÏÆâÍÆ¤Î¥Á¥§¥Ã¥¯ */
200function lfCheckError($arrData) {
201    global $objFormParam;
202    global $objCustomer;
203    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
204    $arrRet =  $objFormParam->getHashArray();
205    $objErr = new SC_CheckError($arrRet);
206    $objErr->arrErr = $objFormParam->checkError();
207   
208    if($_POST['point_check'] == '1') {
209        $objErr->doFunc(array("¥Ý¥¤¥ó¥È¤ò»ÈÍѤ¹¤ë", "point_check"), array("EXIST_CHECK"));
210        $objErr->doFunc(array("¥Ý¥¤¥ó¥È", "use_point"), array("EXIST_CHECK"));
211        $max_point = $objCustomer->getValue('point');
212        if($max_point == "") {
213            $max_point = 0;
214        }
215        if($arrRet['use_point'] > $max_point) {
216            $objErr->arrErr['use_point'] = "¢¨ ¤´ÍøÍѥݥ¤¥ó¥È¤¬½ê»ý¥Ý¥¤¥ó¥È¤òͤ¨¤Æ¤¤¤Þ¤¹¡£<br>";
217        }
218        if(($arrRet['use_point'] * POINT_VALUE) > $arrData['subtotal']) {
219            $objErr->arrErr['use_point'] = "¢¨ ¤´ÍøÍѥݥ¤¥ó¥È¤¬¤´¹ØÆþ¶â³Û¤òͤ¨¤Æ¤¤¤Þ¤¹¡£<br>";
220        }
221    }
222   
223   //¤ª»ÙʧÊýË¡¤ÎÀ°¹çÀ­
224    $objView = new SC_SiteView();
225    $objSiteInfo = $objView->objSiteInfo;
226    $arrInfo = $objSiteInfo->data;
227    $objCartSess = new SC_CartSession();
228    $arrInfo = $objSiteInfo->data;
229    // ¹ØÆþ¶â³Û¤Î¼èÆÀÆÀ
230    $total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
231    // »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
232    $arrPayment = lfGetPayment($total_pretax);
233    $pay_flag = true;
234    foreach ($arrPayment as $key => $payment) {
235        if ($payment['payment_id'] == $arrRet['payment_id']) {
236                $pay_flag = false;
237                break;
238            }
239    }
240    if ($pay_flag) {
241        sfDispSiteError(CUSTOMER_ERROR);
242    }
243   
244    return $objErr->arrErr;
245}
246
247/* »Ùʧ¤¤Êýˡʸ»úÎó¤Î¼èÆÀ */
248function lfGetPaymentInfo($payment_id) {
249    $objQuery = new SC_Query();
250    $where = "payment_id = ?";
251    $arrRet = $objQuery->select("payment_method, charge", "dtb_payment", $where, array($payment_id));
252    return (array($arrRet[0]['payment_method'], $arrRet[0]['charge']));
253}
254
255/* ÇÛÁ÷»þ´Öʸ»úÎó¤Î¼èÆÀ */
256function lfGetDelivTimeInfo($time_id) {
257    $objQuery = new SC_Query();
258    $where = "time_id = ?";
259    $arrRet = $objQuery->select("deliv_id, deliv_time", "dtb_delivtime", $where, array($time_id));
260    return (array($arrRet[0]['deliv_id'], $arrRet[0]['deliv_time']));
261}
262
263/* DB¤Ø¥Ç¡¼¥¿¤ÎÅÐÏ¿ */
264function lfRegistData($uniqid) {
265    global $objFormParam;
266    $arrRet = $objFormParam->getHashArray();
267    $sqlval = $objFormParam->getDbArray();
268    // ÅÐÏ¿¥Ç¡¼¥¿¤ÎºîÀ®
269    $sqlval['order_temp_id'] = $uniqid;
270    $sqlval['update_date'] = 'Now()';
271   
272    if($sqlval['payment_id'] != "") {
273        list($sqlval['payment_method'], $sqlval['charge']) = lfGetPaymentInfo($sqlval['payment_id']);
274    } else {
275        $sqlval['payment_id'] = '0';
276        $sqlval['payment_method'] = "";
277    }
278   
279    if($sqlval['deliv_time_id'] != "") {
280        list($sqlval['deliv_id'], $sqlval['deliv_time']) = lfGetDelivTimeInfo($sqlval['deliv_time_id']);
281    } else {
282        $sqlval['deliv_time_id'] = '0';
283        $sqlval['deliv_id'] = '0';
284        $sqlval['deliv_time'] = "";
285    }
286   
287    // »ÈÍѥݥ¤¥ó¥È¤ÎÀßÄê
288    if($sqlval['point_check'] != '1') {
289        $sqlval['use_point'] = 0;
290    }
291   
292    sfRegistTempOrder($uniqid, $sqlval);
293}
294
295/* ÇÛãÆü°ìÍ÷¤ò¼èÆÀ¤¹¤ë */
296function lfGetDelivDate() {
297    $objCartSess = new SC_CartSession();
298    $objQuery = new SC_Query();
299    // ¾¦ÉÊID¤Î¼èÆÀ
300    $max = $objCartSess->getMax();
301    for($i = 1; $i <= $max; $i++) {
302        if($_SESSION[$objCartSess->key][$i]['id'][0] != "") {
303            $arrID['product_id'][$i] = $_SESSION[$objCartSess->key][$i]['id'][0];
304        }
305    }
306    if(count($arrID['product_id']) > 0) {
307        $id = implode(",", $arrID['product_id']);
308        //¾¦Éʤ«¤éȯÁ÷Ìܰ¤μèÆÀ
309        $deliv_date = $objQuery->get("dtb_products", "MAX(deliv_date_id)", "product_id IN (".$id.")");
310        //ȯÁ÷ÌܰÂ
311        switch($deliv_date) {
312        //¨ÆüȯÁ÷
313        case '1':
314            $start_day = 1;
315            break;
316        //1-2Æü¸å
317        case '2':
318            $start_day = 3;
319            break;
320        //3-4Æü¸å
321        case '3':
322            $start_day = 5;
323            break;
324        //1½µ´Ö°ÊÆâ
325        case '4':
326            $start_day = 8;
327            break;
328        //2½µ´Ö°ÊÆâ
329        case '5':
330            $start_day = 15;
331            break;
332        //3½µ´Ö°ÊÆâ
333        case '6':
334            $start_day = 22;
335            break;
336        //1¥ö·î°ÊÆâ
337        case '7':
338            $start_day = 32;
339            break;
340        //2¥ö·î°Ê¹ß
341        case '8':
342            $start_day = 62;           
343            break;
344        //¤ª¼è¤ê´ó¤»(¾¦ÉÊÆþ²Ù¸å)
345        case '9':
346            $start_day = "";
347            break;
348        default:
349            //¤ªÆÏ¤±Æü¤¬ÀßÄꤵ¤ì¤Æ¤¤¤Ê¤¤¾ì¹ç
350            $start_day = "";
351            break;
352        }
353        //ÇÛã²ÄǽÆü¤Î¥¹¥¿¡¼¥ÈÃͤ«¤é¡¢ÇÛãÆü¤ÎÇÛÎó¤ò¼èÆÀ¤¹¤ë
354        $arrDelivDate = lfGetDateArray($start_day, DELIV_DATE_END_MAX);
355    }
356    return $arrDelivDate;
357}
358
359//ÇÛã²ÄǽÆü¤Î¥¹¥¿¡¼¥ÈÃͤ«¤é¡¢ÇÛãÆü¤ÎÇÛÎó¤ò¼èÆÀ¤¹¤ë
360function lfGetDateArray($start_day, $end_day) {
361    global $arrWDAY;
362    //ÇÛã²ÄǽÆü¤Î¥¹¥¿¡¼¥ÈÃͤ¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ì¤Ð
363    if($start_day >= 1) {
364        $now_time = time();
365        $max_day = $start_day + $end_day;
366        // ½¸·×
367        for ($i = $start_day; $i < $max_day; $i++) {
368            // ´ðËÜ»þ´Ö¤«¤éÆü¿ô¤òÄɲ䷤Ƥ¤¤¯
369            $tmp_time = $now_time + ($i * 24 * 3600);
370            list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time)); 
371            $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
372            $arrDate[$val] = $val;
373        }
374    } else {
375        $arrDate = false;
376    }
377    return $arrDate;
378}
379
380//°ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë
381function lfSetOrderTempData($uniqid) {
382    global $objQuery;
383    global $objFormParam;
384   
385    $objQuery = new SC_Query();
386    $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
387    $from = "dtb_order_temp";
388    $where = "order_temp_id = ?";
389    $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
390    // DBÃͤμèÆÀ
391    $objFormParam->setParam($arrRet[0]);
392    return $objFormParam;
393}
394
395
396?>
Note: See TracBrowser for help on using the repository browser.