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

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