Changeset 18478


Ignore:
Timestamp:
2010/01/07 17:50:46 (12 years ago)
Author:
Yammy
Message:

http://svn.ec-cube.net/open_trac/ticket/507
受注管理での編集が在庫に反映されない

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_4-dev/data/class/pages/admin/order/LC_Page_Admin_Order_Edit.php

    r18474 r18478  
    112112        $objDb = new SC_Helper_DB_Ex(); 
    113113        $objDate = new SC_Date(1901);  
    114           $this->arrYearDelivDate = $objDate->getYear('', date('Y'), '');  
    115             $this->arrMonthDelivDate = $objDate->getMonth(true);  
    116             $this->arrDayDelivDate = $objDate->getDay(true); 
     114        $this->arrYearDelivDate = $objDate->getYear('', date('Y'), '');  
     115        $this->arrMonthDelivDate = $objDate->getMonth(true);  
     116        $this->arrDayDelivDate = $objDate->getDay(true); 
    117117        $arrInfo = $objSiteInfo->data; 
    118118 
     
    381381        $this->objFormParam->addParam("お届け時間ID", "deliv_time_id", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
    382382        $this->objFormParam->addParam("対応状況", "status", INT_LEN, "n", array("EXIST_CHECK", "MAX_LENGTH_CHECK", "NUM_CHECK")); 
    383         $this->objFormParam->addParam("配達日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); 
    384           $this->objFormParam->addParam("お届け日(年)", "deliv_date_year", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));  
    385             $this->objFormParam->addParam("お届け日(月)", "deliv_date_month", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));  
    386             $this->objFormParam->addParam("お届け日(日)", "deliv_date_day", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"));  
     383        $this->objFormParam->addParam("お届け日", "deliv_date", STEXT_LEN, "KVa", array("SPTAB_CHECK", "MAX_LENGTH_CHECK")); 
    387384        $this->objFormParam->addParam("お支払方法名称", "payment_method"); 
    388385        $this->objFormParam->addParam("お届け時間", "deliv_time"); 
     
    428425            $this->objFormParam->setValue('point', $point); 
    429426            $delivDate = split(" ", $arrRet[0]["deliv_date"]);  
    430               $delivDate = split("-", $delivDate[0]);  
    431               $this->objFormParam->setValue('deliv_date_year', $delivDate[0]);  
    432               $this->objFormParam->setValue('deliv_date_month', isset($delivDate[1]) ? $delivDate[1] : "");  
    433               $this->objFormParam->setValue('deliv_date_day', isset($delivDate[2]) ? $delivDate[2] : ""); 
     427            $delivDate = split("-", $delivDate[0]);  
     428            $this->objFormParam->setValue('deliv_date_year', $delivDate[0]);  
     429            $this->objFormParam->setValue('deliv_date_month', isset($delivDate[1]) ? $delivDate[1] : "");  
     430            $this->objFormParam->setValue('deliv_date_day', isset($delivDate[2]) ? $delivDate[2] : ""); 
    434431            $this->arrForm = $arrRet[0]; 
    435432 
     
    603600        $objQuery->query($sql, $arrUpdData); 
    604601 
     602        $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2")); 
     603 
     604 
     605        // 変更しようとしている商品情報とDBに登録してある商品情報を比較することで、更新すべき数量を計算 
     606        $max = count($arrDetail); 
     607        $k = 0; 
     608        $arrStockData = array(); 
     609        for($i = 0; $i < $max; $i++) { 
     610            if (!empty($arrDetail[$i]['product_id'])) { 
     611                $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ? AND product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?", array($order_id, $arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2'])); 
     612                if (!empty($arrPreDetail) && $arrPreDetail[0]['quantity'] != $arrDetail[$i]['quantity']) { 
     613                    // 数量が変更された商品 
     614                    $arrStockData[$k]['product_id'] = $arrDetail[$i]['product_id']; 
     615                    $arrStockData[$k]['classcategory_id1'] = $arrDetail[$i]['classcategory_id1']; 
     616                    $arrStockData[$k]['classcategory_id2'] = $arrDetail[$i]['classcategory_id2']; 
     617                    $arrStockData[$k]['quantity'] = $arrPreDetail[0]['quantity'] - $arrDetail[$i]['quantity']; 
     618                    ++$k; 
     619                } elseif (empty($arrPreDetail)) { 
     620                    // 新しく追加された商品 もしくは 違う商品に変更された商品 
     621                    $arrStockData[$k]['product_id'] = $arrDetail[$i]['product_id']; 
     622                    $arrStockData[$k]['classcategory_id1'] = $arrDetail[$i]['classcategory_id1']; 
     623                    $arrStockData[$k]['classcategory_id2'] = $arrDetail[$i]['classcategory_id2']; 
     624                    $arrStockData[$k]['quantity'] = -$arrDetail[$i]['quantity']; 
     625                    ++$k; 
     626                } 
     627                $objQuery->delete("dtb_order_detail", "order_id = ? AND product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?", array($order_id, $arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2'])); 
     628            } 
     629        } 
     630 
     631        // 上記の新しい商品のループでDELETEされなかった商品は、注文より削除された商品 
     632        $arrPreDetail = $objQuery->select('*', "dtb_order_detail", "order_id = ?", array($order_id)); 
     633        foreach ($arrPreDetail AS $key=>$val) { 
     634            $arrStockData[$k]['product_id'] = $val['product_id']; 
     635            $arrStockData[$k]['classcategory_id1'] = $val['classcategory_id1']; 
     636            $arrStockData[$k]['classcategory_id2'] = $val['classcategory_id2']; 
     637            $arrStockData[$k]['quantity'] = $val['quantity']; 
     638            ++$k; 
     639        } 
     640 
     641        // 受注詳細データの初期化 
     642        $objQuery->delete("dtb_order_detail", $where, array($order_id)); 
     643 
     644 
    605645        // 受注詳細データの更新 
    606         $arrDetail = $this->objFormParam->getSwapArray(array("product_id", "product_code", "product_name", "price", "quantity", "point_rate", "classcategory_id1", "classcategory_id2", "classcategory_name1", "classcategory_name2")); 
    607         $objQuery->delete("dtb_order_detail", $where, array($order_id)); 
    608  
    609  
    610646        $max = count($arrDetail); 
    611647        for($i = 0; $i < $max; $i++) { 
     
    625661        } 
    626662 
     663        // 在庫数調整 
     664        $status = $sqlval['status']; 
     665        if (ORDER_DELIV != $status && ORDER_CANCEL != $status) { 
     666            $stock_sql = "UPDATE dtb_products_class SET stock = stock + ? WHERE product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?;"; 
     667            foreach ($arrStockData AS $key=>$val) { 
     668                $stock_sqlval = array(); 
     669                $stock_sqlval[] = $val['quantity']; 
     670                $stock_sqlval[] = $val['product_id']; 
     671                $stock_sqlval[] = $val['classcategory_id1']; 
     672                $stock_sqlval[] = $val['classcategory_id2']; 
     673 
     674                $objQuery->query($stock_sql, $stock_sqlval); 
     675            } 
     676        } 
    627677 
    628678        $objQuery->commit(); 
     
    712762            $sqlval['classcategory_name1'] = $arrDetail[$i]['classcategory_name1']; 
    713763            $sqlval['classcategory_name2'] = $arrDetail[$i]['classcategory_name2']; 
     764 
    714765            $objQuery->insert("dtb_order_detail", $sqlval); 
     766 
     767 
     768            // 在庫数減少処理 
     769            // 現在の実在庫数取得 
     770            $pre_stock = $objQuery->getone("SELECT stock FROM dtb_products_class WHERE product_id = ? AND classcategory_id1 = ?  AND classcategory_id2 = ?", array($arrDetail[$i]['product_id'], $arrDetail[$i]['classcategory_id1'], $arrDetail[$i]['classcategory_id2'])); 
     771 
     772            $stock_sqlval = array(); 
     773            $stock_sqlval['stock'] = intval($pre_stock - $arrDetail[$i]['quantity']); 
     774            if ($stock_sqlval['stock'] === 0) { 
     775                $stock_sqlval['stock'] = '0'; 
     776            } 
     777 
     778            $st_params = array(); 
     779            $st_params[] = $arrDetail[$i]['product_id']; 
     780            $st_params[] = $arrDetail[$i]['classcategory_id1']; 
     781            $st_params[] = $arrDetail[$i]['classcategory_id2']; 
     782 
     783            $objQuery->update("dtb_products_class", $stock_sqlval, 'product_id = ? AND classcategory_id1 = ? AND classcategory_id2 = ?', $st_params); 
    715784        } 
    716785        $objQuery->commit(); 
Note: See TracChangeset for help on using the changeset viewer.