Source for file LC_Page_Admin_Order_Edit.php

Documentation is available at LC_Page_Admin_Order_Edit.php

  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
  25. require_once(CLASS_PATH . "pages/LC_Page.php");
  26.  
  27. /* GMO決済モジュール連携用 */
  28. if (file_exists(MODULE_PATH . 'mdl_gmopg/inc/include.php') === TRUE) {
  29.     require_once(MODULE_PATH . 'mdl_gmopg/inc/include.php');
  30. }
  31.  
  32. /* ペイジェント決済モジュール連携用 */
  33. if (file_exists(MODULE_PATH . 'mdl_paygent/include.php') === TRUE) {
  34.   require_once(MODULE_PATH . 'mdl_paygent/include.php');
  35. }
  36.  
  37. /* F-REGI決済モジュール連携用 */
  38. if (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決済モジュール連携用 */
  43. if (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.  */
  55. class 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.         }
  528.  
  529.         /*
  530.          * XXX 本来なら配列だが, update 関数を string として
  531.          *     チェックしているため...
  532.          */
  533.         if (!isset($addcol)) $addcol = "";
  534.  
  535.         // 受注テーブルの更新
  536.         $objQuery->update("dtb_order", $sqlval, $where, array($order_id), $addcol);
  537.  
  538.         $sql = "";
  539.         $sql .= " UPDATE";
  540.         $sql .= "     dtb_order";
  541.         $sql .= " SET";
  542.         $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
  543.         $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
  544.         $sql .= " WHERE order_id = ?";
  545.  
  546.         if ($arrRet['deliv_time_id'] == "") {
  547.             $deliv_time_id = 0;
  548.         }else{
  549.             $deliv_time_id = $arrRet['deliv_time_id'];
  550.         }
  551.         $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
  552.         $objQuery->query($sql, $arrUpdData);
  553.  
  554.         // 受注詳細データの更新
  555.         $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
  556.         $objQuery->delete("dtb_order_detail", $where, array($order_id));
  557.  
  558.         $max = count($arrDetail);
  559.         for($i = 0; $i < $max; $i++) {
  560.             $sqlval = array();
  561.             $sqlval['order_id'] = $order_id;
  562.             $sqlval['product_id']  = $arrDetail[$i]['product_id'];
  563.             $sqlval['product_code']  = $arrDetail[$i]['product_code'];
  564.             $sqlval['product_name']  = $arrDetail[$i]['product_name'];
  565.             $sqlval['price']  = $arrDetail[$i]['price'];
  566.             $sqlval['quantity']  = $arrDetail[$i]['quantity'];
  567.             $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
  568.             $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
  569.             $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
  570.             $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
  571.             $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
  572.             $objQuery->insert("dtb_order_detail", $sqlval);
  573.         }
  574.         $objQuery->commit();
  575.     }
  576.  
  577.     /* DB登録処理(追加) */
  578.     function lfRegistNewData() {
  579.         $objQuery = new SC_Query();
  580.  
  581.         $objQuery->begin();
  582.  
  583.         // 入力データを渡す。
  584.         $arrRet =  $this->objFormParam->getHashArray();
  585.         foreach($arrRet as $key => $val) {
  586.             // 配列は登録しない
  587.             if(!is_array($val)) {
  588.                 $sqlval[$key] = $val;
  589.             }
  590.         }
  591.         $sqlval['create_date'] = "Now()";
  592.  
  593.         // 注文ステータス:指定が無ければ新規受付に設定
  594.         if($sqlval["status"] == ""){
  595.             $sqlval['status'] = '1';
  596.         }
  597.  
  598.         // customer_id
  599.         if($sqlval["customer_id"] == ""){
  600.             $sqlval['customer_id'] = '0';
  601.         }
  602.         
  603.         unset($sqlval['order_id']); 
  604.         unset($sqlval['total_point']);
  605.         unset($sqlval['point']);
  606.  
  607.         $where = "order_id = ?";
  608.  
  609.         // 受注ステータスの判定
  610.         if ($sqlval['status'] == ODERSTATUS_COMMIT) {
  611.             // 受注テーブルの発送済み日を更新する
  612.             $sqlval['commit_date'] = "Now()";
  613.             // 発送済みに変更の際ポイント付与
  614.             $customer_id = $sqlval['customer_id'];
  615.             $add_point = $sqlval['add_point'];
  616.             if($customer_id != "" && $customer_id >= 1) {
  617.                 $arrRet = $objQuery->select("point", 'dtb_customer', 'customer_id = ?', array($customer_id));
  618.                 $arrRet[0]['point']+= $add_point;
  619.                 $sqlval2['point'] = $arrRet[0]['point'];
  620.                 $objQuery->update('dtb_customer', $sqlval2, 'customer_id = ?', array($customer_id));
  621.             }
  622.         }
  623.  
  624.         // 受注テーブルの登録
  625.         $objQuery->insert("dtb_order", $sqlval);
  626.         $order_id = $objQuery->currval('dtb_order', 'order_id'); 
  627.         
  628.         $sql = "";
  629.         $sql .= " UPDATE";
  630.         $sql .= "     dtb_order";
  631.         $sql .= " SET";
  632.         $sql .= "     payment_method = (SELECT payment_method FROM dtb_payment WHERE payment_id = ?)";
  633.         $sql .= "     ,deliv_time = (SELECT deliv_time FROM dtb_delivtime WHERE time_id = ? AND deliv_id = (SELECT deliv_id FROM dtb_payment WHERE payment_id = ? ))";
  634.         $sql .= " WHERE order_id = ?";
  635.  
  636.         if ($arrRet['deliv_time_id'] == "") {
  637.             $deliv_time_id = 0;
  638.         }else{
  639.             $deliv_time_id = $arrRet['deliv_time_id'];
  640.         }
  641.         $arrUpdData = array($arrRet['payment_id'], $deliv_time_id, $arrRet['payment_id'], $order_id);
  642.         $objQuery->query($sql, $arrUpdData);
  643.  
  644.         // 受注詳細データの更新
  645.         $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2"));
  646.         $objQuery->delete("dtb_order_detail", $where, array($order_id));
  647.  
  648.         $max = count($arrDetail);
  649.         for($i = 0; $i < $max; $i++) {
  650.             $sqlval = array();
  651.             $sqlval['order_id'] = $order_id;
  652.             $sqlval['product_id']  = $arrDetail[$i]['product_id'];
  653.             $sqlval['product_code']  = $arrDetail[$i]['product_code'];
  654.             $sqlval['product_name']  = $arrDetail[$i]['product_name'];
  655.             $sqlval['price']  = $arrDetail[$i]['price'];
  656.             $sqlval['quantity']  = $arrDetail[$i]['quantity'];
  657.             $sqlval['point_rate']  = $arrDetail[$i]['point_rate'];
  658.             $sqlval['classcategory_id1'] = $arrDetail[$i]['classcategory_id1'];
  659.             $sqlval['classcategory_id2'] = $arrDetail[$i]['classcategory_id2'];
  660.             $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1'];
  661.             $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2'];
  662.             $objQuery->insert("dtb_order_detail", $sqlval);
  663.         }
  664.         $objQuery->commit();
  665.     }
  666.  
  667.  
  668.     function lfInsertProduct($product_id, $classcategory_id1, $classcategory_id2) {
  669.         $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
  670.         $this->arrForm = $this->objFormParam->getFormParamList();
  671.         $this->lfSetProductData($arrProduct);
  672.     }
  673.  
  674.     function lfUpdateProduct($product_id, $classcategory_id1, $classcategory_id2, $no) {
  675.         $arrProduct = $this->lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2);
  676.         $this->arrForm = $this->objFormParam->getFormParamList();
  677.         $this->lfSetProductData($arrProduct, $no);
  678.     }
  679.  
  680.     function lfSetProductData($arrProduct, $no = null) {
  681.         foreach ($arrProduct AS $key=>$val) {
  682.             if (!is_array($this->arrForm[$key]['value'])) {
  683.                 unset($this->arrForm[$key]['value']);
  684.             }
  685.             if ($no === null) {
  686.                 $this->arrForm[$key]['value'][] = $arrProduct[$key];
  687.             } else {
  688.                 $this->arrForm[$key]['value'][$no] = $arrProduct[$key];
  689.             }
  690.         }
  691.     }
  692.  
  693.     function lfGetProductsClass($product_id, $classcategory_id1, $classcategory_id2) {
  694.         $objDb = new SC_Helper_DB_Ex();
  695.         $arrClassCatName = $objDb->sfGetIDValueList("dtb_classcategory", "classcategory_id", "name");
  696.         $arrRet = $objDb->sfGetProductsClass(array($product_id, $classcategory_id1, $classcategory_id2));
  697.  
  698.         $arrProduct['price'] = $arrRet['price02'];
  699.         $arrProduct['quantity'] = 1;
  700.         $arrProduct['product_id'] = $arrRet['product_id'];
  701.         $arrProduct['point_rate'] = $arrRet['point_rate'];
  702.         $arrProduct['product_code'] = $arrRet['product_code'];
  703.         $arrProduct['product_name'] = $arrRet['name'];
  704.         $arrProduct['classcategory_id1'] = $arrRet['classcategory_id1'];
  705.         $arrProduct['classcategory_id2'] = $arrRet['classcategory_id2'];
  706.         $arrProduct['classcategory_name1'] = $arrClassCatName[$arrRet['classcategory_id1']];
  707.         $arrProduct['classcategory_name2'] = $arrClassCatName[$arrRet['classcategory_id2']];
  708.  
  709.         return $arrProduct;
  710.     }
  711. }
  712. ?>

Documentation generated on Tue, 28 Apr 2009 18:11:24 +0900 by phpDocumentor 1.4.2