source: branches/feature-module-paygent/html/admin/order/edit.php @ 16542

Revision 16542, 12.6 KB checked in by naka, 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 */
7require_once("../require.php");
8
9if(file_exists(MODULE_PATH . 'mdl_paygent/mdl_paygent.inc')) {
10    require_once(MODULE_PATH . 'mdl_paygent/mdl_paygent.inc');
11}
12
13class LC_Page {
14    function LC_Page() {
15        $this->tpl_mainpage = 'order/edit.tpl';
16        $this->tpl_subnavi = 'order/subnavi.tpl';
17        $this->tpl_mainno = 'order';       
18        $this->tpl_subno = 'index';
19        $this->tpl_subtitle = '¼õÃí´ÉÍý';
20        global $arrPref;
21        $this->arrPref = $arrPref;
22        global $arrORDERSTATUS;
23        $this->arrORDERSTATUS = $arrORDERSTATUS;
24    }
25}
26
27$conn = new SC_DBConn();
28$objPage = new LC_Page();
29$objView = new SC_AdminView();
30$objSess = new SC_Session();
31$objSiteInfo = new SC_SiteInfo();
32$arrInfo = $objSiteInfo->data;
33
34// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
35$objFormParam = new SC_FormParam();
36// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
37lfInitParam();
38
39// ǧ¾Ú²ÄÈݤÎȽÄê
40sfIsSuccess($objSess);
41
42// ¸¡º÷¥Ñ¥é¥á¡¼¥¿¤Î°ú¤­·Ñ¤®
43foreach ($_POST as $key => $val) {
44    if (ereg("^search_", $key)) {
45        $objPage->arrSearchHidden[$key] = $val;
46    }
47}
48
49// ɽ¼¨¥â¡¼¥ÉȽÄê
50if(sfIsInt($_GET['order_id'])) {
51    $objPage->disp_mode = true;
52    $order_id = $_GET['order_id'];
53} else {
54    $order_id = $_POST['order_id'];
55}
56$objPage->tpl_order_id = $order_id;
57
58// DB¤«¤é¼õÃí¾ðÊó¤òÆɤ߹þ¤à
59lfGetOrderData($order_id);
60
61switch($_POST['mode']) {
62case 'pre_edit':
63case 'order_id':
64    break;
65case 'edit':
66    // POST¾ðÊó¤Ç¾å½ñ¤­
67    $objFormParam->setParam($_POST);
68   
69    // ÆþÎÏÃͤÎÊÑ´¹
70    $objFormParam->convParam();
71    $objPage->arrErr = lfCheckError($arrRet);
72    if(count($objPage->arrErr) == 0) {
73        $objPage->arrErr = lfCheek($arrInfo);
74        if(count($objPage->arrErr) == 0) {
75            lfRegistData($_POST['order_id']);
76            // DB¤«¤é¼õÃí¾ðÊó¤òºÆÆɹþ
77            lfGetOrderData($order_id);
78            $objPage->tpl_onload = "window.alert('¼õÃíÍúÎò¤òÊÔ½¸¤·¤Þ¤·¤¿¡£');";
79        }
80    }
81    break;
82// ºÆ·×»»
83case 'cheek':
84    // POST¾ðÊó¤Ç¾å½ñ¤­
85    $objFormParam->setParam($_POST);
86    // ÆþÎÏÃͤÎÊÑ´¹
87    $objFormParam->convParam();
88    $objPage->arrErr = lfCheckError($arrRet);
89    if(count($objPage->arrErr) == 0) {
90        $objPage->arrErr = lfCheek($arrInfo);
91    }
92    break;
93// ¥Ú¥¤¥¸¥§¥ó¥ÈÂбþ
94case 'paygent_order':
95    $objPage->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id);
96    break;
97default:
98    break;
99}
100
101// »Ùʧ¤¤ÊýË¡¤Î¼èÆÀ
102$objPage->arrPayment = sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
103// ÇÛÁ÷»þ´Ö¤Î¼èÆÀ
104$arrRet = sfGetDelivTime($objFormParam->getValue('payment_id'));
105$objPage->arrDelivTime = sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
106
107$objPage->arrForm = $objFormParam->getFormParamList();
108
109$objPage->arrInfo = $arrInfo;
110
111$objView->assignobj($objPage);
112// ɽ¼¨¥â¡¼¥ÉȽÄê
113if(!$objPage->disp_mode) {
114    $objView->display(MAIN_FRAME);
115} else {
116    $objView->display('order/disp.tpl');
117}
118//-----------------------------------------------------------------------------------------------------------------------------------
119/* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */
120function lfInitParam() {
121    global $objFormParam;
122    // ÇÛÁ÷Àè¾ðÊó
123    $objFormParam->addParam("¤ªÌ¾Á°1", "deliv_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
124    $objFormParam->addParam("¤ªÌ¾Á°2", "deliv_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
125    $objFormParam->addParam("¥Õ¥ê¥¬¥Ê1", "deliv_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
126    $objFormParam->addParam("¥Õ¥ê¥¬¥Ê2", "deliv_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
127    $objFormParam->addParam("͹ÊØÈÖ¹æ1", "deliv_zip01", ZIP01_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
128    $objFormParam->addParam("͹ÊØÈÖ¹æ2", "deliv_zip02", ZIP02_LEN, "n", array("EXIST_CHECK", "NUM_CHECK", "NUM_COUNT_CHECK"));
129    $objFormParam->addParam("ÅÔÆ»Éܸ©", "deliv_pref", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
130    $objFormParam->addParam("½»½ê1", "deliv_addr01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
131    $objFormParam->addParam("½»½ê2", "deliv_addr02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
132    $objFormParam->addParam("ÅÅÏÃÈÖ¹æ1", "deliv_tel01", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
133    $objFormParam->addParam("ÅÅÏÃÈÖ¹æ2", "deliv_tel02", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
134    $objFormParam->addParam("ÅÅÏÃÈÖ¹æ3", "deliv_tel03", TEL_ITEM_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK" ,"NUM_CHECK"));
135    // ¼õÃí¾¦ÉʾðÊó
136    $objFormParam->addParam("ÃÍ°ú¤­", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
137    $objFormParam->addParam("Á÷ÎÁ", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
138    $objFormParam->addParam("¼ê¿ôÎÁ", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
139    $objFormParam->addParam("ÍøÍѥݥ¤¥ó¥È", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
140    $objFormParam->addParam("¤ª»Ùʧ¤¤ÊýË¡", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
141    $objFormParam->addParam("ÇÛÁ÷»þ´ÖID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
142    $objFormParam->addParam("Âбþ¾õ¶·", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
143    $objFormParam->addParam("ÇÛãÆü", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
144    $objFormParam->addParam("¤ª»ÙʧÊýˡ̾¾Î", "payment_method");
145    $objFormParam->addParam("ÇÛÁ÷»þ´Ö", "deliv_time");
146   
147    // ¼õÃí¾ÜºÙ¾ðÊó
148    $objFormParam->addParam("ñ²Á", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
149    $objFormParam->addParam("¸Ä¿ô", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
150    $objFormParam->addParam("¾¦ÉÊID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
151    $objFormParam->addParam("¥Ý¥¤¥ó¥ÈÉÕͿΨ", "point_rate");
152    $objFormParam->addParam("¾¦ÉÊ¥³¡¼¥É", "product_code");
153    $objFormParam->addParam("¾¦ÉÊ̾", "product_name");
154    $objFormParam->addParam("µ¬³Ê1", "classcategory_id1");
155    $objFormParam->addParam("µ¬³Ê2", "classcategory_id2");
156    $objFormParam->addParam("µ¬³Ê̾1", "classcategory_name1");
157    $objFormParam->addParam("µ¬³Ê̾2", "classcategory_name2");
158    $objFormParam->addParam("¥á¥â", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
159    // DBÆɹþÍÑ
160    $objFormParam->addParam("¾®·×", "subtotal");
161    $objFormParam->addParam("¹ç·×", "total");
162    $objFormParam->addParam("»Ùʧ¤¤¹ç·×", "payment_total");
163    $objFormParam->addParam("²Ã»»¥Ý¥¤¥ó¥È", "add_point");
164    $objFormParam->addParam("¤ªÃÂÀ¸Æü¥Ý¥¤¥ó¥È", "birth_point");
165    $objFormParam->addParam("¾ÃÈñÀǹç·×", "tax");
166    $objFormParam->addParam("ºÇ½ªÊÝ»ý¥Ý¥¤¥ó¥È", "total_point");
167    $objFormParam->addParam("¸ÜµÒID", "customer_id");
168    $objFormParam->addParam("¸½ºß¤Î¥Ý¥¤¥ó¥È", "point");
169}
170
171function lfGetOrderData($order_id) {
172    global $objFormParam;
173    global $objPage;
174    if(sfIsInt($order_id)) {
175        // DB¤«¤é¼õÃí¾ðÊó¤òÆɤ߹þ¤à
176        $objQuery = new SC_Query();
177        $where = "order_id = ?";
178        $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
179        $objFormParam->setParam($arrRet[0]);
180        list($point, $total_point) = sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
181        $objFormParam->setValue('total_point', $total_point);
182        $objFormParam->setValue('point', $point);
183        $objPage->arrDisp = $arrRet[0];
184        // ¼õÃí¾ÜºÙ¥Ç¡¼¥¿¤Î¼èÆÀ
185        $arrRet = lfGetOrderDetail($order_id);
186        $arrRet = sfSwapArray($arrRet);
187        $objPage->arrDisp = array_merge($objPage->arrDisp, $arrRet);
188        $objFormParam->setParam($arrRet);
189       
190        // ¤½¤Î¾»Ùʧ¤¤¾ðÊó¤òɽ¼¨
191        if($objPage->arrDisp["memo02"] != "") $objPage->arrDisp["payment_info"] = unserialize($objPage->arrDisp["memo02"]);
192        if($objPage->arrDisp["memo01"] == PAYMENT_CREDIT_ID){
193            $objPage->arrDisp["payment_type"] = "¥¯¥ì¥¸¥Ã¥È·èºÑ";
194        }elseif($objPage->arrDisp["memo01"] == PAYMENT_CONVENIENCE_ID){
195            $objPage->arrDisp["payment_type"] = "¥³¥ó¥Ó¥Ë·èºÑ";
196        }else{
197            $objPage->arrDisp["payment_type"] = "¤ª»Ùʧ¤¤";
198        }
199    }
200}
201
202// ¼õÃí¾ÜºÙ¥Ç¡¼¥¿¤Î¼èÆÀ
203function lfGetOrderDetail($order_id) {
204    $objQuery = new SC_Query();
205    $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
206    $where = "order_id = ?";
207    $objQuery->setorder("classcategory_id1, classcategory_id2");
208    $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
209    return $arrRet;
210}
211
212/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
213function lfCheckError() {
214    global $objFormParam;
215    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
216    $arrRet =  $objFormParam->getHashArray();
217    $objErr = new SC_CheckError($arrRet);
218    $objErr->arrErr = $objFormParam->checkError();
219   
220    return $objErr->arrErr;
221}
222
223/* ·×»»½èÍý */
224function lfCheek($arrInfo) {
225    global $objFormParam;
226       
227    $arrVal = $objFormParam->getHashArray();
228           
229    // ¾¦ÉʤμïÎà¿ô
230    $max = count($arrVal['quantity']);
231    $subtotal = 0;
232    $totalpoint = 0;
233    $totaltax = 0;
234    for($i = 0; $i < $max; $i++) {
235        // ¾®·×¤Î·×»»
236        $subtotal += sfPreTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
237        // ¾®·×¤Î·×»»
238        $totaltax += sfTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
239        // ²Ã»»¥Ý¥¤¥ó¥È¤Î·×»»
240        $totalpoint += sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
241    }
242   
243    // ¾ÃÈñÀÇ
244    $arrVal['tax'] = $totaltax;
245    // ¾®·×
246    $arrVal['subtotal'] = $subtotal;
247    // ¹ç·×
248    $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
249    // ¤ª»Ùʧ¤¤¹ç·×
250    $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
251   
252    // ²Ã»»¥Ý¥¤¥ó¥È
253    $arrVal['add_point'] = sfGetAddPoint($totalpoint, $arrVal['use_point'], $arrInfo);
254       
255    list($arrVal['point'], $arrVal['total_point']) = sfGetCustomerPoint($_POST['order_id'], $arrVal['use_point'], $arrVal['add_point']);
256       
257    if($arrVal['total'] < 0) {
258        $arrErr['total'] = '¹ç·×³Û¤¬¥Þ¥¤¥Ê¥¹É½¼¨¤Ë¤Ê¤é¤Ê¤¤¤è¤¦¤ËÄ´À°¤·¤Æ²¼¤µ¤¤¡£<br />';
259    }
260   
261    if($arrVal['payment_total'] < 0) {
262        $arrErr['payment_total'] = '¤ª»Ùʧ¤¤¹ç·×³Û¤¬¥Þ¥¤¥Ê¥¹É½¼¨¤Ë¤Ê¤é¤Ê¤¤¤è¤¦¤ËÄ´À°¤·¤Æ²¼¤µ¤¤¡£<br />';
263    }
264
265    if($arrVal['total_point'] < 0) {
266        $arrErr['total_point'] = 'ºÇ½ªÊÝ»ý¥Ý¥¤¥ó¥È¤¬¥Þ¥¤¥Ê¥¹É½¼¨¤Ë¤Ê¤é¤Ê¤¤¤è¤¦¤ËÄ´À°¤·¤Æ²¼¤µ¤¤¡£<br />';
267    }
268
269    $objFormParam->setParam($arrVal);
270    return $arrErr;
271}
272
273/* DBÅÐÏ¿½èÍý */
274function lfRegistData($order_id) {
275    global $objFormParam;
276    $objQuery = new SC_Query();
277   
278    $objQuery->begin();
279
280    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
281    $arrRet =  $objFormParam->getHashArray();
282   
283    foreach($arrRet as $key => $val) {
284        // ÇÛÎó¤ÏÅÐÏ¿¤·¤Ê¤¤
285        if(!is_array($val)) {
286            $sqlval[$key] = $val;
287        }
288    }
289   
290    unset($sqlval['total_point']);
291    unset($sqlval['point']);
292           
293    $where = "order_id = ?";
294   
295    // ¼õÃí¥¹¥Æ¡¼¥¿¥¹¤ÎȽÄê
296    if ($sqlval['status'] == ODERSTATUS_COMMIT) {
297        // ¼õÃí¥Æ¡¼¥Ö¥ë¤ÎȯÁ÷ºÑ¤ßÆü¤ò¹¹¿·¤¹¤ë
298        $sqlval['commit_date'] = "Now()";
299    }
300   
301    $sqlval['update_date'] = "Now()";
302   
303    // ¼õÃí¥Æ¡¼¥Ö¥ë¤Î¹¹¿·
304    $objQuery->update("dtb_order", $sqlval, $where, array($order_id));
305
306    $sql = "";
307    $sql .= " UPDATE";
308    $sql .= "     dtb_order";
309    $sql .= " SET";
310    $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
311    $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
312    $sql .= " WHERE order_id = ?";
313   
314    if ($arrRet['deliv_time_id'] == "") {
315        $deliv_time_id = 0;
316    }else{
317        $deliv_time_id = $arrRet['deliv_time_id'];
318    }
319    $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
320    $objQuery->query($sql, $arrUpdData);
321
322    // ¼õÃí¾ÜºÙ¥Ç¡¼¥¿¤Î¹¹¿·
323    $arrDetail = $objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
324    $objQuery->delete("dtb_order_detail", $where, array($order_id));
325   
326    $max = count($arrDetail);
327    for($i = 0; $i < $max; $i++) {
328        $sqlval = array();
329        $sqlval['order_id'] = $order_id;
330        $sqlval['product_id']  = $arrDetail[$i]['product_id'];
331        $sqlval['product_code']  = $arrDetail[$i]['product_code'];
332        $sqlval['product_name']  = $arrDetail[$i]['product_name'];
333        $sqlval['price']  = $arrDetail[$i]['price'];
334        $sqlval['quantity']  = $arrDetail[$i]['quantity'];
335        $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
336        $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
337        $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
338        $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
339        $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];     
340        $objQuery->insert("dtb_order_detail", $sqlval);
341    }
342    $objQuery->commit();
343}
344?>
Note: See TracBrowser for help on using the repository browser.