source: branches/version-1/html/mobile/products/payment.php @ 17705

Revision 17705, 11.5 KB checked in by takegami, 15 years ago (diff)

#395 追加対応

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