source: branches/beta/html/admin/order/edit.php @ 14903

Revision 14903, 12.3 KB checked in by adati, 14 years ago (diff)

[マージ:dev(r14790-14791)]受注変更時に更新日時も変更する。

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