source: branches/rel/html/shopping/payment.php @ 13526

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