source: branches/beta/html/shopping/payment.php @ 316

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