source: branches/comu-ver2/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php @ 18023

Revision 18023, 32.8 KB checked in by Seasoft, 15 years ago (diff)

#472「管理機能の配送業者の追加でエラー」を修正。

  • Property svn:eol-style set to LF
  • Property svn:keywords set to "Id Revision Date"
Line 
1<?php
2/*
3 * This file is part of EC-CUBE
4 *
5 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
6 *
7 * http://www.lockon.co.jp/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 */
23
24// {{{ requires
25require_once(CLASS_PATH . "pages/LC_Page.php");
26
27/* GMO決済モジュール連携用 */
28if (file_exists(MODULE_PATH . 'mdl_gmopg/inc/include.php') === TRUE) {
29    require_once(MODULE_PATH . 'mdl_gmopg/inc/include.php');
30}
31
32/* ペイジェント決済モジュール連携用 */
33if (file_exists(MODULE_PATH . 'mdl_paygent/include.php') === TRUE) {
34  require_once(MODULE_PATH . 'mdl_paygent/include.php');
35}
36
37/* F-REGI決済モジュール連携用 */
38if (file_exists(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php') === TRUE) {
39    require_once(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php');
40}
41
42/* SPS決済モジュール連携用 */
43if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) {
44    require_once(MODULE_PATH . 'mdl_sps/request.php');
45}
46
47
48/**
49 * 受注修正 のページクラス.
50 *
51 * @package Page
52 * @author LOCKON CO.,LTD.
53 * @version $Id$
54 */
55class LC_Page_Admin_Order_Edit extends LC_Page {
56
57    // {{{ properties
58
59    /** 表示モード */
60    var $disp_mode;
61
62    // }}}
63    // {{{ functions
64
65    /**
66     * Page を初期化する.
67     *
68     * @return void
69     */
70    function init() {
71        parent::init();
72        $this->tpl_mainpage = 'order/edit.tpl';
73        $this->tpl_subnavi = 'order/subnavi.tpl';
74        $this->tpl_mainno = 'order';
75        $this->tpl_subno = 'index';
76        $this->tpl_subtitle = '受注管理';
77        if (empty($_GET['order_id']) && empty($_POST['order_id'])) {
78            $this->tpl_subno = 'add';
79            $this->tpl_mode = 'add';
80            $this->tpl_subtitle = '新規受注入力';
81        }
82
83        $masterData = new SC_DB_MasterData_Ex();
84        $this->arrPref = $masterData->getMasterData("mtb_pref",
85                                 array("pref_id", "pref_name", "rank"));
86        $this->arrORDERSTATUS = $masterData->getMasterData("mtb_order_status");
87
88        /* ペイジェント決済モジュール連携用 */
89        if(function_exists("sfPaygentOrderPage")) {
90            $this->arrFormKind = sfPaygentOrderPage();
91        }
92
93        /* F-REGI決済モジュール連携用 */
94        if (file_exists(MODULE_PATH. 'mdl_fregi/LC_Page_Mdl_Fregi_Config.php') === TRUE) {
95            global $arrFregiPayment;
96            $this->arrFregiPayment = $arrFregiPayment;
97            global $arrFregiDispKind;
98            $this->arrFregiDispKind = $arrFregiDispKind;
99        }
100    }
101
102    /**
103     * Page のプロセス.
104     *
105     * @return void
106     */
107    function process() {
108        $conn = new SC_DBConn();
109        $objView = new SC_AdminView();
110        $objSess = new SC_Session();
111        $objSiteInfo = new SC_SiteInfo();
112        $objDb = new SC_Helper_DB_Ex();
113        $arrInfo = $objSiteInfo->data;
114
115        // パラメータ管理クラス
116        $this->objFormParam = new SC_FormParam();
117        // パラメータ情報の初期化
118        $this->lfInitParam();
119
120        // 認証可否の判定
121        SC_Utils_Ex::sfIsSuccess($objSess);
122
123        // 検索パラメータの引き継ぎ
124        foreach ($_POST as $key => $val) {
125            if (ereg("^search_", $key)) {
126                $this->arrSearchHidden[$key] = $val;
127            }
128        }
129
130        // 表示モード判定
131        if(isset($_GET['order_id']) &&
132            SC_Utils_Ex::sfIsInt($_GET['order_id'])) {
133            $this->disp_mode = true;
134            $order_id = $_GET['order_id'];
135        } else {
136            $order_id = $_POST['order_id'];
137        }
138        $this->tpl_order_id = $order_id;
139
140        // DBから受注情報を読み込む
141        $this->lfGetOrderData($order_id);
142
143        switch($_POST['mode']) {
144        case 'pre_edit':
145        case 'order_id':
146            break;
147        case 'edit':
148        case 'add':
149            // POST情報で上書き
150            $this->objFormParam->setParam($_POST);
151
152            // 入力値の変換
153            $this->objFormParam->convParam();
154            $this->arrErr = $this->lfCheek($arrInfo);
155            $this->arrErr = $this->lfCheckError();
156            if(count($this->arrErr) == 0) {
157                #if(count($this->arrErr) == 0) {
158                    if ($_POST['mode'] == 'add') {
159                        $this->lfRegistNewData();
160                        $text = "'新規受注を登録しました。'";
161                    } else {
162                        $this->lfRegistData($_POST['order_id']);
163                        $text = "'受注履歴を編集しました。'";
164                    }
165                    // DBから受注情報を再読込
166                    $this->lfGetOrderData($order_id);
167                    $this->tpl_onload = "window.alert(".$text.");";
168                #}
169            }
170            break;
171            // 再計算
172        case 'cheek':
173            // POST情報で上書き
174            $this->objFormParam->setParam($_POST);
175            // 入力値の変換
176            $this->objFormParam->convParam();
177            $this->arrErr = $this->lfCheckError();
178            #if(count($this->arrErr) == 0) {
179                $this->arrErr = $this->lfCheek($arrInfo);
180            #}
181            break;
182        /* ペイジェント決済モジュール連携用 */
183        case 'paygent_order':
184            $this->paygent_return = sfPaygentOrder($_POST['paygent_type'], $order_id);
185            break;
186        /* F-REGI決済モジュール連携用 */
187        case 'fregi_status':
188            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
189            $this->fregi_err = $objFregiConfig->getSaleInfo($order_id, $this->arrDisp);
190            $this->lfGetOrderData($order_id);
191            break;
192        case 'fregi_card':
193            $objFregiConfig = new LC_Page_Mdl_Fregi_Config();
194            $this->fregi_card_err = $objFregiConfig->setCardInfo($_POST['card_status'], $order_id, $this->arrDisp);
195            $this->lfGetOrderData($order_id);
196            break;
197        /* SPS決済モジュール連携用 */
198        case 'sps_request':
199            $objErr = new SC_CheckError($_POST);
200            $objErr->doFunc(array("年","sps_year"), array('EXIST_CHECK'));
201            $objErr->doFunc(array("月","sps_month"), array('EXIST_CHECK'));
202            $objErr->doFunc(array("日","sps_date"), array('EXIST_CHECK'));
203            $objErr->doFunc(array("売上・返金日", "sps_year", "sps_month", "sps_date"), array("CHECK_DATE"));
204            if ($objErr->arrErr) {
205                $this->arrErr = $objErr->arrErr;
206                break;
207            }
208            $sps_return = sfSpsRequest( $order_id, $_POST['request_type'] );
209            // DBから受注情報を再読込
210            $this->lfGetOrderData($order_id);
211            $this->tpl_onload = "window.alert('".$sps_return."');";
212            break;
213
214        /* GMOPG連携用 */
215        case 'gmopg_order_edit':
216            require_once(MODULE_PATH . 'mdl_gmopg/class/LC_Mdl_GMOPG_OrderEdit.php');
217            $objGMOOrderEdit = new LC_MDL_GMOPG_OrderEdit;
218            $this->gmopg_order_edit_result = $objGMOOrderEdit->proccess();
219            $this->lfGetOrderData($order_id);
220            break;
221        // 商品削除
222        case 'delete_product':
223            $delete_no = $_POST['delete_no'];
224            foreach ($_POST AS $key=>$val) {
225                if (is_array($val)) {
226                    foreach ($val AS $k=>$v) {
227                        if ($k != $delete_no) {
228                            $arrData[$key][] = $v;
229                        }
230                    }
231                } else {
232                    $arrData[$key] = $val;
233                }
234            }
235            $this->lfReCheek($arrData, $arrInfo);
236            break;
237        // 商品追加ポップアップより商品選択後、商品情報取得
238        case 'select_product_detail':
239            // POST情報で上書き
240            $this->objFormParam->setParam($_POST);
241            if (!empty($_POST['add_product_id'])) {
242                $this->lfInsertProduct($_POST['add_product_id'], $_POST['add_classcategory_id1'], $_POST['add_classcategory_id2']);
243
244            } elseif (!empty($_POST['edit_product_id'])) {
245                $this->lfUpdateProduct($_POST['edit_product_id'], $_POST['edit_classcategory_id1'], $_POST['edit_classcategory_id2'], $_POST['no']);
246            }
247
248            $arrData = $_POST;
249            foreach ($this->arrForm AS $key=>$val) {
250                if (is_array($val)) {
251                    $arrData[$key] = $this->arrForm[$key]['value'];
252                } else {
253                    $arrData[$key] = $val;
254                }
255            }
256            $this->lfReCheek($arrData, $arrInfo);
257            break;
258        default:
259            break;
260        }
261
262        // 支払い方法の取得
263        $this->arrPayment = $objDb->sfGetIDValueList("dtb_payment", "payment_id", "payment_method");
264        // 配送時間の取得
265        $arrRet = $objDb->sfGetDelivTime($this->objFormParam->getValue('payment_id'));
266        $this->arrDelivTime = SC_Utils_Ex::sfArrKeyValue($arrRet, 'time_id', 'deliv_time');
267
268        $this->arrForm = $this->objFormParam->getFormParamList();
269        $this->product_count = count($this->arrForm['quantity']['value']);
270
271        // アンカーを設定
272        if (isset($_POST['anchor_key']) && !empty($_POST['anchor_key'])) {
273            $anchor_hash = "location.hash='#" . $_POST['anchor_key'] . "'";
274        } else {
275            $anchor_hash = "";
276        }
277        $this->tpl_onload .= $anchor_hash;
278
279        $this->arrInfo = $arrInfo;
280
281        /**
282         * SPS決済 クレジット判定用処理
283         */
284        if (file_exists(MODULE_PATH . 'mdl_sps/request.php') === TRUE) {
285            $objQuery = new SC_Query();
286            $this->paymentType = $objQuery->getall("SELECT module_code, memo03 FROM dtb_payment WHERE payment_id = ? ", array($this->arrForm["payment_id"]['value']));
287            $objDate = new SC_Date();
288            $objDate->setStartYear(RELEASE_YEAR);
289            $this->arrYear = $objDate->getYear();
290            $this->arrMonth = $objDate->getMonth();
291            $this->arrDay = $objDate->getDay();
292        }
293
294        $objView->assignobj($this);
295        // 表示モード判定
296        if(!$this->disp_mode) {
297            $objView->display(MAIN_FRAME);
298        } else {
299            $objView->display('order/disp.tpl');
300        }
301    }
302
303
304    /**
305     * デストラクタ.
306     *
307     * @return void
308     */
309    function destroy() {
310        parent::destroy();
311    }
312
313    /* パラメータ情報の初期化 */
314    function lfInitParam() {
315       
316        // お客様情報
317        $this->objFormParam->addParam("顧客名1", "order_name01", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
318        $this->objFormParam->addParam("顧客名2", "order_name02", STEXT_LEN, "KVa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
319        $this->objFormParam->addParam("顧客名カナ1", "order_kana01", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
320        $this->objFormParam->addParam("顧客名カナ2", "order_kana02", STEXT_LEN, "KVCa", array("EXIST_CHECK", "SPTAB_CHECK", "MAX_LENGTH_CHECK"));
321        $this->objFormParam->addParam("メールアドレス", "order_email", MTEXT_LEN, "KVCa", array("NO_SPTAB", "EMAIL_CHECK", "EMAIL_CHAR_CHECK", "MAX_LENGTH_CHECK"));
322        $this->objFormParam->addParam("郵便番号1", "order_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
323        $this->objFormParam->addParam("郵便番号2", "order_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
324        $this->objFormParam->addParam("都道府県", "order_pref", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
325        $this->objFormParam->addParam("住所1", "order_addr01", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
326        $this->objFormParam->addParam("住所2", "order_addr02", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
327        $this->objFormParam->addParam("電話番号1", "order_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
328        $this->objFormParam->addParam("電話番号2", "order_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
329        $this->objFormParam->addParam("電話番号3", "order_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
330
331        // 配送先情報
332        $this->objFormParam->addParam("お名前1", "deliv_name01", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
333        $this->objFormParam->addParam("お名前2", "deliv_name02", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
334        $this->objFormParam->addParam("フリガナ1", "deliv_kana01", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
335        $this->objFormParam->addParam("フリガナ2", "deliv_kana02", STEXT_LEN, "KVCa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
336        $this->objFormParam->addParam("郵便番号1", "deliv_zip01", ZIP01_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
337        $this->objFormParam->addParam("郵便番号2", "deliv_zip02", ZIP02_LEN, "n", array("NUM_CHECK", "NUM_COUNT_CHECK"));
338        $this->objFormParam->addParam("都道府県", "deliv_pref", INT_LEN, "n", array( "MAX_LENGTH_CHECK", "NUM_CHECK"));
339        $this->objFormParam->addParam("住所1", "deliv_addr01", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
340        $this->objFormParam->addParam("住所2", "deliv_addr02", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK"));
341        $this->objFormParam->addParam("電話番号1", "deliv_tel01", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
342        $this->objFormParam->addParam("電話番号2", "deliv_tel02", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
343        $this->objFormParam->addParam("電話番号3", "deliv_tel03", TEL_ITEM_LEN, "n", array("MAX_LENGTH_CHECK" ,"NUM_CHECK"));
344
345        // 受注商品情報
346        $this->objFormParam->addParam("値引き", "discount", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
347        $this->objFormParam->addParam("送料", "deliv_fee", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
348        $this->objFormParam->addParam("手数料", "charge", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
349        $this->objFormParam->addParam("利用ポイント", "use_point", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
350        $this->objFormParam->addParam("お支払い方法", "payment_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
351        $this->objFormParam->addParam("配送時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));
352        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"));
353        $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
354        $this->objFormParam->addParam("お支払方法名称", "payment_method");
355        $this->objFormParam->addParam("配送時間", "deliv_time");
356
357        // 受注詳細情報
358        $this->objFormParam->addParam("単価", "price", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
359        $this->objFormParam->addParam("数量", "quantity", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
360        $this->objFormParam->addParam("商品ID", "product_id", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK"), '0');
361        $this->objFormParam->addParam("ポイント付与率", "point_rate");
362        $this->objFormParam->addParam("商品コード", "product_code");
363        $this->objFormParam->addParam("商品名", "product_name");
364        $this->objFormParam->addParam("規格1", "classcategory_id1");
365        $this->objFormParam->addParam("規格2", "classcategory_id2");
366        $this->objFormParam->addParam("規格名1", "classcategory_name1");
367        $this->objFormParam->addParam("規格名2", "classcategory_name2");
368        $this->objFormParam->addParam("メモ", "note", MTEXT_LEN, "KVa", array("MAX_LENGTH_CHECK"));
369        // DB読込用
370        $this->objFormParam->addParam("小計", "subtotal");
371        $this->objFormParam->addParam("合計", "total");
372        $this->objFormParam->addParam("支払い合計", "payment_total");
373        $this->objFormParam->addParam("加算ポイント", "add_point");
374        $this->objFormParam->addParam("お誕生日ポイント", "birth_point");
375        $this->objFormParam->addParam("消費税合計", "tax");
376        $this->objFormParam->addParam("最終保持ポイント", "total_point");
377        $this->objFormParam->addParam("顧客ID", "customer_id");
378        $this->objFormParam->addParam("現在のポイント", "point");
379        $this->objFormParam->addParam("注文番号", "order_id");
380        $this->objFormParam->addParam("受注日", "create_date");
381    }
382
383    function lfGetOrderData($order_id) {
384        if(SC_Utils_Ex::sfIsInt($order_id)) {
385            // DBから受注情報を読み込む
386            $objQuery = new SC_Query();
387            $objDb = new SC_Helper_DB_Ex();
388            $where = "order_id = ?";
389            $arrRet = $objQuery->select("*", "dtb_order", $where, array($order_id));
390            $this->objFormParam->setParam($arrRet[0]);
391            list($point, $total_point) = $objDb->sfGetCustomerPoint($order_id, $arrRet[0]['use_point'], $arrRet[0]['add_point']);
392            $this->objFormParam->setValue('total_point', $total_point);
393            $this->objFormParam->setValue('point', $point);
394            $this->arrForm = $arrRet[0];
395            // 受注詳細データの取得
396            $arrRet = $this->lfGetOrderDetail($order_id);
397            $arrRet = SC_Utils_Ex::sfSwapArray($arrRet);
398            $this->arrForm = array_merge($this->arrForm, $arrRet);
399            $this->objFormParam->setParam($arrRet);
400
401            // その他支払い情報を表示
402            if($this->arrForm["memo02"] != "") $this->arrForm["payment_info"] = unserialize($this->arrForm["memo02"]);
403            if($this->arrForm["memo01"] == PAYMENT_CREDIT_ID){
404                $this->arrForm["payment_type"] = "クレジット決済";
405            }elseif($this->arrForm["memo01"] == PAYMENT_CONVENIENCE_ID){
406                $this->arrForm["payment_type"] = "コンビニ決済";
407            }else{
408                $this->arrForm["payment_type"] = "お支払い";
409            }
410        }
411    }
412
413    // 受注詳細データの取得
414    function lfGetOrderDetail($order_id) {
415        $objQuery = new SC_Query();
416        $col = "product_id, classcategory_id1, classcategory_id2, product_code, product_name, classcategory_name1, classcategory_name2, price, quantity, point_rate";
417        $where = "order_id = ?";
418        $objQuery->setorder("classcategory_id1, classcategory_id2");
419        $arrRet = $objQuery->select($col, "dtb_order_detail", $where, array($order_id));
420        return $arrRet;
421    }
422
423    /* 入力内容のチェック */
424    function lfCheckError() {
425        // 入力データを渡す。
426        $arrRet =  $this->objFormParam->getHashArray();
427        $objErr = new SC_CheckError($arrRet);
428        $objErr->arrErr = $this->objFormParam->checkError();
429
430        return $objErr->arrErr;
431    }
432
433    /* 計算処理 */
434    function lfCheek($arrInfo) {
435        $objDb = new SC_Helper_DB_Ex();
436        $arrVal = $this->objFormParam->getHashArray();
437        $arrErr = array();
438
439        // 商品の種類数
440        $max = count($arrVal['quantity']);
441        $subtotal = 0;
442        $totalpoint = 0;
443        $totaltax = 0;
444        for($i = 0; $i < $max; $i++) {
445            // 小計の計算
446            $subtotal += SC_Utils_Ex::sfPreTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
447            // 小計の計算
448            $totaltax += SC_Utils_Ex::sfTax($arrVal['price'][$i], $arrInfo['tax'], $arrInfo['tax_rule']) * $arrVal['quantity'][$i];
449            // 加算ポイントの計算
450            $totalpoint += SC_Utils_Ex::sfPrePoint($arrVal['price'][$i], $arrVal['point_rate'][$i]) * $arrVal['quantity'][$i];
451        }
452
453        // 消費税
454        $arrVal['tax'] = $totaltax;
455        // 小計
456        $arrVal['subtotal'] = $subtotal;
457        // 合計
458        $arrVal['total'] = $subtotal - $arrVal['discount'] + $arrVal['deliv_fee'] + $arrVal['charge'];
459        // お支払い合計
460        $arrVal['payment_total'] = $arrVal['total'] - ($arrVal['use_point'] * POINT_VALUE);
461
462        // 加算ポイント
463        $arrVal['add_point'] = SC_Utils_Ex::sfGetAddPoint($totalpoint, $arrVal['use_point'], $arrInfo);
464
465        list($arrVal['point'], $arrVal['total_point']) = $objDb->sfGetCustomerPoint($_POST['order_id'], $arrVal['use_point'], $arrVal['add_point']);
466
467        if($arrVal['total'] < 0) {
468            $arrErr['total'] = '合計額がマイナス表示にならないように調整して下さい。<br />';
469        }
470
471        if($arrVal['payment_total'] < 0) {
472            $arrErr['payment_total'] = 'お支払い合計額がマイナス表示にならないように調整して下さい。<br />';
473        }
474
475        if($arrVal['total_point'] < 0) {
476            $arrErr['total_point'] = '最終保持ポイントがマイナス表示にならないように調整して下さい。<br />';
477        }
478
479        $this->objFormParam->setParam($arrVal);
480        return $arrErr;
481    }
482
483    function lfReCheek($arrData, $arrInfo) {
484        // 情報上書き
485        $this->objFormParam->setParam($arrData);
486        // 入力値の変換
487        $this->objFormParam->convParam();
488        #if(count($this->arrErr) == 0) {
489            $this->arrErr = $this->lfCheek($arrInfo);
490        #}
491        $this->arrErr = $this->lfCheckError();
492    }
493
494    /* DB登録処理 */
495    function lfRegistData($order_id) {
496        $objQuery = new SC_Query();
497
498        $objQuery->begin();
499
500        // 入力データを渡す。
501        $arrRet =  $this->objFormParam->getHashArray();
502        foreach($arrRet as $key => $val) {
503            // 配列は登録しない
504            if(!is_array($val)) {
505                $sqlval[$key] = $val;
506            }
507        }
508
509        unset($sqlval['total_point']);
510        unset($sqlval['point']);
511
512        $where = "order_id = ?";
513
514        // 受注ステータスの判定
515        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
516            // 受注テーブルの発送済み日を更新する
517            $addcol['commit_date'] = "Now()";
518            // 発送済みに変更の際ポイント付与
519            $customer_id = $sqlval['customer_id'];
520        $add_point = $sqlval['add_point'];
521        if($customer_id != "" && $customer_id >= 1) {
522            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
523            $arrRet[0]['point']+= $add_point;
524            $sqlval2['point'] = $arrRet[0]['point'];
525            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
526           }
527        } elseif ($sqlval['status'] == 1 || $sqlval['status'] == 3) {
528                $customer_id = $sqlval['customer_id'];
529        $add_point = $sqlval['add_point'];
530        if($customer_id != "" && $customer_id >= 1) {
531            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
532            $arrRet[0]['point']-= $add_point;
533            $sqlval2['point'] = $arrRet[0]['point'];
534            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
535              }
536        }else {
537                $customer_id = $sqlval['customer_id'];
538        $add_point = $sqlval['add_point'];
539        if($customer_id != "" && $customer_id >= 1) {
540            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
541            $sqlval2['point'] = $arrRet[0]['point'];
542            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
543           }
544        }
545
546        /*
547         * XXX 本来なら配列だが, update 関数を string として
548         *     チェックしているため...
549         */
550        if (!isset($addcol)) $addcol = "";
551
552        // 受注テーブルの更新
553        $objQuery->update("dtb_order", $sqlval, $where, array($order_id), $addcol);
554       
555        // 受注テーブルの名称列を更新
556        $objDb = new SC_Helper_DB_Ex();
557        $objDb->sfUpdateOrderNameCol($order_id);
558       
559        // 受注詳細データの更新
560        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
561        $objQuery->delete("dtb_order_detail", $where, array($order_id));
562
563        $max = count($arrDetail);
564        for($i = 0; $i < $max; $i++) {
565            $sqlval = array();
566            $sqlval['order_id'] = $order_id;
567            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
568            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
569            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
570            $sqlval['price']  = $arrDetail[$i]['price'];
571            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
572            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
573            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
574            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
575            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
576            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
577            $objQuery->insert("dtb_order_detail", $sqlval);
578        }
579        $objQuery->commit();
580    }
581
582    /* DB登録処理(追加) */
583    function lfRegistNewData() {
584        $objQuery = new SC_Query();
585
586        $objQuery->begin();
587
588        // 入力データを渡す。
589        $arrRet =  $this->objFormParam->getHashArray();
590        foreach($arrRet as $key => $val) {
591            // 配列は登録しない
592            if(!is_array($val)) {
593                $sqlval[$key] = $val;
594            }
595        }
596        $sqlval['create_date'] = "Now()";
597
598        // 注文ステータス:指定が無ければ新規受付に設定
599        if($sqlval["status"] == ""){
600            $sqlval['status'] = '1';
601        }
602
603        // customer_id
604        if($sqlval["customer_id"] == ""){
605            $sqlval['customer_id'] = '0';
606        }
607       
608        unset($sqlval['order_id']);
609        unset($sqlval['total_point']);
610        unset($sqlval['point']);
611
612        $where = "order_id = ?";
613
614        // 受注ステータスの判定
615        if ($sqlval['status'] == ODERSTATUS_COMMIT) {
616            // 受注テーブルの発送済み日を更新する
617            $sqlval['commit_date'] = "Now()";
618            // 発送済みに変更の際ポイント付与
619            $customer_id = $sqlval['customer_id'];
620        $add_point = $sqlval['add_point'];
621        if($customer_id != "" && $customer_id >= 1) {
622            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
623            $arrRet[0]['point']+= $add_point;
624            $sqlval2['point'] = $arrRet[0]['point'];
625            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
626           }
627        } elseif ($sqlval['status'] == 1 || $sqlval['status'] == 3) {
628                $customer_id = $sqlval['customer_id'];
629        $add_point = $sqlval['add_point'];
630        if($customer_id != "" && $customer_id >= 1) {
631            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
632            $arrRet[0]['point']-= $add_point;
633            $sqlval2['point'] = $arrRet[0]['point'];
634            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
635              }
636        }else {
637                $customer_id = $sqlval['customer_id'];
638        $add_point = $sqlval['add_point'];
639        if($customer_id != "" && $customer_id >= 1) {
640            $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
641            $sqlval2['point'] = $arrRet[0]['point'];
642            $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
643           }
644        }
645
646        // 受注テーブルの登録
647        $objQuery->insert("dtb_order", $sqlval);
648        $order_id = $objQuery->currval('dtb_order', 'order_id');
649       
650        // 受注テーブルの名称列を更新
651        $objDb = new SC_Helper_DB_Ex();
652        $objDb->sfUpdateOrderNameCol($order_id);
653       
654        // 受注詳細データの更新
655        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
656        $objQuery->delete("dtb_order_detail", $where, array($order_id));
657
658        $max = count($arrDetail);
659        for($i = 0; $i < $max; $i++) {
660            $sqlval = array();
661            $sqlval['order_id'] = $order_id;
662            $sqlval['product_id']  = $arrDetail[$i]['product_id'];
663            $sqlval['product_code']  = $arrDetail[$i]['product_code'];
664            $sqlval['product_name']  = $arrDetail[$i]['product_name'];
665            $sqlval['price']  = $arrDetail[$i]['price'];
666            $sqlval['quantity']  = $arrDetail[$i]['quantity'];
667            $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
668            $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
669            $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
670            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
671            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
672            $objQuery->insert("dtb_order_detail", $sqlval);
673        }
674        $objQuery->commit();
675    }
676
677
678    function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) {
679        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
680        $this->arrForm = $this->objFormParam->getFormParamList();
681        $existes = false;
682        $existes_key = NULL;
683        if (!empty($this->arrForm['product_id']['value'])) {
684            foreach ($this->arrForm['product_id']['value'] AS $key=>$val) {
685                if ($val == $product_id && $this->arrForm['product_id']['classcategory_id1'][$key] == $classcategory_id1 && $this->arrForm['product_id']['classcategory_id2'][$key] == $classcategory_id2) {
686                    // 既に同じ商品がある場合
687                    $existes = true;
688                    $existes_key = $key;
689                }
690            }
691        }
692
693        if ($existes) {
694            // 既に同じ商品がある場合
695            ++$this->arrForm['quantity']['value'][$existes_key];
696        } else {
697            // 既に同じ商品がない場合
698            $this->lfSetProductData($arrProduct);
699        }
700    }
701
702    function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) {
703        $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
704        $this->arrForm = $this->objFormParam->getFormParamList();
705        $this->lfSetProductData($arrProduct, $no);
706    }
707
708    function lfSetProductData($arrProduct, $no = null) {
709        foreach ($arrProduct AS $key=>$val) {
710            if (!is_array($this->arrForm[$key]['value'])) {
711                unset($this->arrForm[$key]['value']);
712            }
713            if ($no === null) {
714                $this->arrForm[$key]['value'][] = $arrProduct[$key];
715            } else {
716                $this->arrForm[$key]['value'][$no] = $arrProduct[$key];
717            }
718        }
719    }
720
721    function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) {
722        $objDb = new SC_Helper_DB_Ex();
723        $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
724        $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2));
725
726        $arrProduct['price'] = $arrRet['price02'];
727        $arrProduct['quantity'] = 1;
728        $arrProduct['product_id'] = $arrRet['product_id'];
729        $arrProduct['point_rate'] = $arrRet['point_rate'];
730        $arrProduct['product_code'] = $arrRet['product_code'];
731        $arrProduct['product_name'] = $arrRet['name'];
732        $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1'];
733        $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2'];
734        $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']];
735        $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']];
736
737        return $arrProduct;
738    }
739}
740?>
Note: See TracBrowser for help on using the repository browser.