source: branches/dev/html/mobile/nonmember/payment2.php @ 14830

Revision 14830, 11.0 KB checked in by nakanishi, 15 years ago (diff)
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// ¶â³Û¤Î¼èÆÀ (¹ØÆþÅÓÃæ¤ÇÇä¤êÀڤ줿¾ì¹ç¤Ë¤Ï¤³¤Î´Ø¿ôÆâ¤Ë¤Æ¤½¤Î¾¦ÉʤθĿô¤¬£°¤Ë¤Ê¤ë)
56$objPage = sfTotalCart($objPage, $objCartSess, $arrInfo);
57$objPage->arrData = sfTotalConfirm($arrData, $objPage, $objCartSess, $arrInfo);
58
59// ¥«¡¼¥ÈÆâ¤Î¾¦ÉʤÎÇä¤êÀÚ¤ì¥Á¥§¥Ã¥¯
60$objCartSess->chkSoldOut($objCartSess->getCartList(), true);
61
62// Ìá¤ë¥Ü¥¿¥ó¤Î½èÍý
63if (!empty($_POST['return'])) {
64    switch ($_POST['mode']) {
65    case 'confirm':
66        $_POST['mode'] = 'payment';
67        break;
68    default:
69        // Àµ¾ï¤Ê¿ä°Ü¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
70        $objSiteSess->setRegistFlag();
71        //header("Location: " . gfAddSessionId(MOBILE_URL_SHOP_TOP));
72        header("Location: " . gfAddSessionId('../nonmember/index.php'));
73        exit;
74//        $_POST['mode'] = "deliv_date";
75    }
76}
77
78switch($_POST['mode']) {
79// »Ùʧ¤¤ÊýË¡»ØÄê ¢ª ÇÛãÆü»þ»ØÄê
80case 'deliv_date':
81   
82    // ÆþÎÏÃͤÎÊÑ´¹
83    $objFormParam->convParam();
84    $objPage->arrErr = lfCheckError($objPage->arrData);
85    if (!isset($objPage->arrErr['payment_id'])) {
86        // »Ùʧ¤¤ÊýË¡¤ÎÆþÎÏ¥¨¥é¡¼¤Ê¤·
87        $objPage->tpl_mainpage = 'nonmember/deliv_date.tpl';
88        $objPage->tpl_title = "ÇÛãÆü»þ»ØÄê";
89        break;
90    } else {
91        // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
92        $uniqid = $objSiteSess->getUniqId();
93        // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
94        lfSetOrderTempData($uniqid);
95    }
96    break;
97case 'confirm':
98    // ÆþÎÏÃͤÎÊÑ´¹
99    $objFormParam->convParam();
100    $objPage->arrErr = lfCheckError($objPage->arrData );
101    // ÆþÎÏ¥¨¥é¡¼¤Ê¤·
102    if(count($objPage->arrErr) == 0) {
103        // DB¤Ø¤Î¥Ç¡¼¥¿ÅÐÏ¿
104        lfRegistData($uniqid);
105        // Àµ¾ï¤ËÅÐÏ¿¤µ¤ì¤¿¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
106        $objSiteSess->setRegistFlag();
107        // ³Îǧ¥Ú¡¼¥¸¤Ø°ÜÆ°
108        //header("Location: " . gfAddSessionId(MOBILE_URL_SHOP_CONFIRM));
109        header("Location: " . gfAddSessionId('./confirm.php'));
110        exit;
111    }else{
112        // ¥æ¡¼¥¶¥æ¥Ë¡¼¥¯ID¤Î¼èÆÀ
113        $uniqid = $objSiteSess->getUniqId();
114        // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
115        lfSetOrderTempData($uniqid);
116        if (!isset($objPage->arrErr['payment_id'])) {
117            // »Ùʧ¤¤ÊýË¡¤ÎÆþÎÏ¥¨¥é¡¼¤Ê¤·
118            $objPage->tpl_mainpage = 'nonmember/deliv_date.tpl';
119            $objPage->tpl_title = "ÇÛãÆü»þ»ØÄê";
120        }
121    }
122    break;
123// Á°¤Î¥Ú¡¼¥¸¤ËÌá¤ë
124case 'return':
125    // Èó²ñ°÷¤Î¾ì¹ç
126    // Àµ¾ï¤Ê¿ä°Ü¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤·¤Æ¤ª¤¯
127    $objSiteSess->setRegistFlag();
128    header("Location: " . gfAddSessionId('../shopping/index.php'));
129    exit;
130    break;
131// »Ùʧ¤¤ÊýË¡¤¬Êѹ¹¤µ¤ì¤¿¾ì¹ç
132case 'payment':
133    // ¤³¤³¤Îbreak¤Ï¡¢°ÕÌ£¤¬¤¢¤ë¤Î¤Ç³°¤µ¤Ê¤¤¤Ç²¼¤µ¤¤¡£
134    break;
135default:
136    // ¼õÃí°ì»þ¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ
137    lfSetOrderTempData($uniqid);
138    break;
139}
140
141// ŹÊÞ¾ðÊó¤Î¼èÆÀ
142$arrInfo = $objSiteInfo->data;
143// ¹ØÆþ¶â³Û¤Î¼èÆÀÆÀ
144$total_pretax = $objCartSess->getAllProductsTotal($arrInfo);
145// »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
146$objPage->arrPayment = lfGetPayment($total_pretax);
147// ÇÛÁ÷»þ´Ö¤Î¼èÆÀ
148$arrRet = sfGetDelivTime($objFormParam->getValue('payment_id'));
149$objPage->arrDelivTime = sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
150$objPage->objCustomer = $objCustomer;
151//¡¡ÇÛÁ÷Æü°ìÍ÷¤Î¼èÆÀ
152$objPage->arrDelivDate = lfGetDelivDate();
153
154$objPage->arrForm = $objFormParam->getFormParamList();
155
156$objView->assignobj($objPage);
157$objView->display(SITE_FRAME);
158//--------------------------------------------------------------------------------------------------------------------------
159/* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */
160function lfInitParam() {
161    global $objFormParam;
162    $objFormParam->addParam("¤ª»Ùʧ¤¤ÊýË¡", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
163    $objFormParam->addParam("¥Ý¥¤¥ó¥È", "use_point", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK", "ZERO_START"));
164    $objFormParam->addParam("ÇÛã»þ´Ö", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
165    $objFormParam->addParam("¤´¼ÁÌä", "message", LTEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
166    $objFormParam->addParam("¥Ý¥¤¥ó¥È¤ò»ÈÍѤ¹¤ë", "point_check", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), '2');
167    $objFormParam->addParam("ÇÛãÆü", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
168}
169
170function lfGetPayment($total_pretax) {
171    $objQuery = new SC_Query();
172    $objQuery->setorder("rank DESC");
173    //ºï½ü¤µ¤ì¤Æ¤¤¤Ê¤¤»ÙʧÊýË¡¤ò¼èÆÀ
174    $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) ");
175    //ÍøÍѾò·ï¤«¤é»Ùʧ²ÄǽÊýË¡¤òȽÄê
176    foreach($arrRet as $data) {
177        //²¼¸Â¤È¾å¸Â¤¬ÀßÄꤵ¤ì¤Æ¤¤¤ë
178        if($data['rule'] > 0 && $data['upper_rule'] > 0) {
179            if($data['rule'] <= $total_pretax && $data['upper_rule'] >= $total_pretax) {
180                $arrPayment[] = $data;
181            }
182        //²¼¸Â¤Î¤ßÀßÄꤵ¤ì¤Æ¤¤¤ë
183        } elseif($data['rule'] > 0) {   
184            if($data['rule'] <= $total_pretax) {
185                $arrPayment[] = $data;
186            }
187        //¾å¸Â¤Î¤ßÀßÄꤵ¤ì¤Æ¤¤¤ë
188        } elseif($data['upper_rule'] > 0) {
189            if($data['upper_rule'] >= $total_pretax) {
190                $arrPayment[] = $data;
191            }
192        //ÀßÄê¤Ê¤·
193        } else {
194            $arrPayment[] = $data;
195        }   
196    }
197    return $arrPayment;
198}
199
200/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
201function lfCheckError($arrData) {
202    global $objFormParam;
203    global $objCustomer;
204    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
205    $arrRet =  $objFormParam->getHashArray();
206    $objErr = new SC_CheckError($arrRet);
207    $objErr->arrErr = $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 = $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/* »Ùʧ¤¤Êýˡʸ»úÎó¤Î¼èÆÀ */
227function 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/* ÇÛÁ÷»þ´Öʸ»úÎó¤Î¼èÆÀ */
235function 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¤Ø¥Ç¡¼¥¿¤ÎÅÐÏ¿ */
243function lfRegistData($uniqid) {
244    global $objFormParam;
245    $arrRet = $objFormParam->getHashArray();
246    $sqlval = $objFormParam->getDbArray();
247    // ÅÐÏ¿¥Ç¡¼¥¿¤ÎºîÀ®
248    $sqlval['order_temp_id'] = $uniqid;
249    $sqlval['update_date'] = 'Now()';
250   
251    if($sqlval['payment_id'] != "") {
252        list($sqlval['payment_method'], $sqlval['charge']) = lfGetPaymentInfo($sqlval['payment_id']);
253    } else {
254        $sqlval['payment_id'] = '0';
255        $sqlval['payment_method'] = "";
256    }
257   
258    if($sqlval['deliv_time_id'] != "") {
259        list($sqlval['deliv_id'], $sqlval['deliv_time']) = lfGetDelivTimeInfo($sqlval['deliv_time_id']);
260    } else {
261        $sqlval['deliv_time_id'] = '0';
262        $sqlval['deliv_id'] = '0';
263        $sqlval['deliv_time'] = "";
264    }
265   
266    // »ÈÍѥݥ¤¥ó¥È¤ÎÀßÄê
267    if($sqlval['point_check'] != '1') {
268        $sqlval['use_point'] = 0;
269    }
270   
271    sfRegistTempOrder($uniqid, $sqlval);
272}
273
274/* ÇÛãÆü°ìÍ÷¤ò¼èÆÀ¤¹¤ë */
275function 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 = lfGetDateArray($start_day, DELIV_DATE_END_MAX);
334    }
335    return $arrDelivDate;
336}
337
338//ÇÛã²ÄǽÆü¤Î¥¹¥¿¡¼¥ÈÃͤ«¤é¡¢ÇÛãÆü¤ÎÇÛÎó¤ò¼èÆÀ¤¹¤ë
339function lfGetDateArray($start_day, $end_day) {
340    global $arrWDAY;
341    //ÇÛã²ÄǽÆü¤Î¥¹¥¿¡¼¥ÈÃͤ¬¥»¥Ã¥È¤µ¤ì¤Æ¤¤¤ì¤Ð
342    if($start_day >= 1) {
343        $now_time = time();
344        $max_day = $start_day + $end_day;
345        // ½¸·×
346        for ($i = $start_day; $i < $max_day; $i++) {
347            // ´ðËÜ»þ´Ö¤«¤éÆü¿ô¤òÄɲ䷤Ƥ¤¤¯
348            $tmp_time = $now_time + ($i * 24 * 3600);
349            list($y, $m, $d, $w) = split(" ", date("y m d w", $tmp_time)); 
350            $val = sprintf("%02d/%02d/%02d(%s)", $y, $m, $d, $arrWDAY[$w]);
351            $arrDate[$val] = $val;
352        }
353    } else {
354        $arrDate = false;
355    }
356    return $arrDate;
357}
358
359//°ì»þ¼õÃí¥Æ¡¼¥Ö¥ë¤«¤é¤Î¾ðÊó¤ò³ÊǼ¤¹¤ë
360function lfSetOrderTempData($uniqid) {
361    global $objQuery;
362    global $objFormParam;
363   
364    $objQuery = new SC_Query();
365    $col = "payment_id, use_point, deliv_time_id, message, point_check, deliv_date";
366    $from = "dtb_order_temp";
367    $where = "order_temp_id = ?";
368    $arrRet = $objQuery->select($col, $from, $where, array($uniqid));
369    // DBÃͤμèÆÀ
370    $objFormParam->setParam($arrRet[0]);
371    return $objFormParam;
372}
373
374
375?>
Note: See TracBrowser for help on using the repository browser.