<?php
include_once CORE_INCLUDE_DIR.'/objectPage.php';

class admin_ome_order extends objectPage{
    var $object = 'plugins/ome/ome_queue';
    
    function showEdit($orderid){
        $this->path[] = array('text'=>__('订单编辑'));
        $objOrder = &$this->system->loadModel('trading/order');
        $aOrder = $objOrder->getFieldById($orderid);
        
        $aOrder['discount'] = 0 - $aOrder['discount'];

        $oCur = &$this->system->loadModel('system/cur');
        $aCur = $oCur->getSysCur();
        $aOrder['cur_name'] = $aCur[$aOrder['currency']];

        $aOrder['items'] = $objOrder->getItemList($orderid);
    
        
        $goodidarr=array();
        $goodidarrnum=array();
        if($aOrder['items']){
            foreach($aOrder['items'] as $key=>$value){
               $goodidarr[]=$value['bn'];
               $goodidarrnum[]=$value['nums'];
            }
        }
        

        
        $pweight=$objOrder->getweight($goodidarr);
        $arrweight=array();

        if(is_array($pweight)){
        foreach($pweight as $key=>$pval){
         $arrweight[]=$pval[0]['weight'];
        }
        }
        
        $goodidarrweight=array();
        foreach($arrweight as $wkey=>$wvalue){
            $goodidarrweight[]=$goodidarrnum[$wkey]*$wvalue;
        }
        
        $aOrder['pmt'] = $objOrder->getPmtList($orderid);

        if($aOrder['member_id'] > 0){
            $objMember = &$this->system->loadModel('member/member');
            $aOrder['member'] = $objMember->getFieldById($aOrder['member_id'], array('*'));
            $aOrder['ship_email'] = $aOrder['member']['email'];
        }else{
            $aOrder['member'] = array();
        }

        $objDelivery = &$this->system->loadModel('trading/delivery');
        $aArea = $objDelivery->getDlAreaList();
        foreach ($aArea as $v){
            $aTmp[$v['name']] = $v['name'];
        }
        $aOrder['deliveryArea'] = $aTmp;

        $aRet = $objDelivery->getDlTypeList();
        foreach ($aRet as $v){
            $aShipping[$v['dt_id']] = $v['dt_name'];
        }
        $aOrder['selectDelivery'] = $aShipping;

        $objPayment = &$this->system->loadModel('trading/payment');
        $aRet = $objPayment->getMethods();
        $aPayment[-1] = '货到付款';
        foreach ($aRet as $v){
            $aPayment[$v['id']] = $v['custom_name'];
        }
        $aOrder['extendCon'] = $objPayment->getExtendCon($aOrder['extend'],$aOrder['payment']);
        $aOrder['selectPayment'] = $aPayment;

        $objCurrency = &$this->system->loadModel('system/cur');
        $aRet = $objCurrency->curAll();
        foreach ($aRet as $v){
            $aCurrency[$v['cur_code']] = $v['cur_name'];
        }
        $aOrder['curList'] = $aCurrency;
        $shipping = &$this->system->loadModel('trading/delivery');
        $darea=$aOrder['ship_area'];
        $dt_id=$aOrder['shipping_id'];
        $aShippingsa = $shipping->getDlTypeByArea($darea, 0,$dt_id);
         foreach($aShippingsa as $k=>$s){
            $aShippingsa['price'] = cal_fee($s['expressions'],$aOrder['weight'],$aOrder['cost_item'],$s['price']);
            
            $s['pad']==0?$aShippingsa['has_cod'] = 0:$aShippingsa['has_cod'] = 1;
            if($s['protect']==1){
                $aShippingsa['protect'] = max($trading['totalPrice']*$s['protect_rate'],$s['minprice']);
            }else{
                $aShippingsa['protect'] = false;
            }
        }
        
        $this->pagedata['deliveryprice']=$aShippingsa['price'];
        $this->pagedata['order'] = $aOrder;
        $this->pagedata['arrweight'] = $arrweight;
        $this->pagedata['goodweight']=$goodidarrweight;
        
        $this->pagedata['goodnums']=count($goodidarrnum);
        // http://192.168.51.32/ekdome/shopadmin/?ctl=plugins/ome_order&act=showEdit&p[0]=20120706111387
        $this->singlepage('order/page.html');
    }
    
    public function edit($order_id){
        
        if ( !$order_id ) {
            $this->display('not-exists.html');
        }
        $this->pagedata['order'] = $this->db->selectrow("SELECT * FROM sdb_orders WHERE order_id=".$this->db->quote($order_id));
        
        $this->display('edit.html');
    }

    public function doedit(){
        
    }
}
