source: branches/dev/html/mobile/nonmember/payment.php @ 14741

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