<?php
/**
 * 订单管理
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author xiaogg <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class OrderInfoController extends BaseController{
    public function _initialize() {
        parent::_initialize();
        /*$is_auth=check_use_auth("WEBSHOP");
        if($is_auth['status']==0){
            $this->error('该版本没有此权限',$is_auth['url']);return;
        }*/
        $this->order_type=strtoarray(C('ORDER_TYPE'));$this->assign('order_type',$this->order_type);
		// $wm_order_type=strtoarray(array('13'=>'收银','14'=>'商品'));$this->assign('wm_order_type',$wm_order_type);
		// $wm_order_type=strtoarray(array('13'=>'线下','14'=>'线上','3'=>'积分商城'));$this->assign('wm_order_type',$wm_order_type);
        $wm_order_type=strtoarray(array('14'=>'线上','3'=>'积分商城'));$this->assign('wm_order_type',$wm_order_type);   
        $send_type_status_arr=strtoarray(array('1'=>'预约自提','2'=>'同城配送','3'=>'快递发货'));$this->assign('send_type_status_arr',$send_type_status_arr);
        $pt_status=strtoarray(array('1'=>'已成团','6'=>'待成团'));$this->assign('pt_status',$pt_status);
        $send_type_status=strtoarray(array('2'=>'同城配送','3'=>'快递发货'));$this->assign('send_type_status',$send_type_status);
		$this->order_status=strtoarray(C('ORDER_STATUS'));$this->assign('order_status',$this->order_status);
		$this->order_pay=strtoarray(C('ORDER_PAY'));$this->assign('order_pay',$this->order_pay);
		$this->order_shipping=strtoarray(C('ORDER_SHIPPING'));
		$this->assign('order_shipping',$this->order_shipping);
        
        $this->three_ship_status=array('1'=>'待接单',2=>'待取货',3=>'配送中',4=>'已送达',5=>'已取消',7=>'已过期',8=>'指派单');
        $this->admin_info=session('admin_info');
        $map=array();
        $map['uid']=$this->admin_info['id'];
        $this->auth_group_id=M("AuthGroupAccess")->where($map)->getField('group_id');
		
		$map = array();
        $map['id']=array('gt',0);;
		$shops_list = M('Shops')->where($map)->getField('id,name',true);
		$this->assign('shops_list',$shops_list);
    } 
    public function index(){
        $this->zt_index();
    }
    public function purindex(){
        $name = CONTROLLER_NAME;
        $map=array();
		$postdata=I('param.');
        if($postdata['order_sn'])$map['order_sn']=$postdata['order_sn'];
        $map['type']=10;
        $map['goods_allmoney']=array('gt',0);
        if($postdata['status'])$map['status']=$postdata['status'];
        if($postdata['pay_status'])$map['pay_status']=$postdata['pay_status'];
        if($postdata['shipping_status'])$map['shipping_status']=$postdata['shipping_status'];
        // if($postdata['keyword']){
            // $whereor['uid']=$postdata['keyword'];
            // $whereor['consignee']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['address']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['mobile']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['email']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['sign_building']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['temp']=array('like','%'.$postdata['keyword'].'%');
            // $whereor['_logic'] = 'or';
            // $map['_complex'] = $whereor;
        // }
		$list = $this->lists('OrderInfo',$map);
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
    public function pview() {//公共查看
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $operable_list=$this->operable_list($id);
        $this->assign('operable_list',$operable_list);
        $ordergoods=M('OrderGoods')->where('order_id='.$id)->field(true)->select();
        $ordershipping=M('ShipOrder')->where('order_id='.$id)->field(true)->select();
        $ordership=array();
        foreach($ordershipping as $v){
            $goodsid=explode(',',$v['goods_id']);
            foreach($goodsid as $val){
                $ordership[$val]=$v;
            }
        }
        foreach($ordergoods as $k=>$v){
            $attr=unserialize($v['goods_attr']);
            $ordergoods[$k]['attr_name']=$attr['name'];
            $ordergoods[$k]['org_parce']=$v['attr_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['shipping']=$ordership[$v['goods_id']];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
        } 
        $this->assign('ordergoods',$ordergoods);
        $actionlog=M('ActionLog')->where('action_id in (9,10) and record_id='.$id)->order('id desc')->select();
        $this->assign('actionlog',$actionlog);
        $model = D (CONTROLLER_NAME);
        if(!empty($request))$this->assign ('views',serialize($request));
        $vo = $model->field(true)->getByid($id);
        $this->assign($vo);
        $this->display ();
    }
	public function service_view() {//服务查看
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $operable_list=$this->operable_list($id);
        $this->assign('operable_list',$operable_list);
        $ordergoods=M('OrderGoods')->where('order_id='.$id)->field(true)->select();
        $ordershipping=M('ShipOrder')->where('order_id='.$id)->field(true)->select();
        $ordership=array();
        foreach($ordershipping as $v){
            $goodsid=explode(',',$v['goods_id']);
            foreach($goodsid as $val){
                $ordership[$val]=$v;
            }
        }
        foreach($ordergoods as $k=>$v){
            $attr=unserialize($v['goods_attr']);
            $ordergoods[$k]['attr_name']=$attr['name'];
            $ordergoods[$k]['org_parce']=$v['attr_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['shipping']=$ordership[$v['goods_id']];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
        } 
        $this->assign('ordergoods',$ordergoods);
        $actionlog=M('ActionLog')->where('action_id in (9,10) and record_id='.$id)->order('id desc')->select();
        $this->assign('actionlog',$actionlog);
        $model = D (CONTROLLER_NAME);
        $pk=ucfirst($model->getPk ());
        $id = intval(I($model->getPk ()));
        if(empty($id))$this->error(L('PARAM_ERROR'));
        $do='getBy'.$pk;
        if(!empty($request))$this->assign ('views',serialize($request));
        $vo = $model->field(true)->$do($id);
		
		//服务方式
		$service_type = idtoname($id,'MemberPackage','service_type','order_id',false);
		$this->assign('service_type',$service_type);
        $this->assign($vo);
        $this->display ();
    }
    public function wm_index(){
        $name = CONTROLLER_NAME;
        $map=array();
        $postdata=I('param.');
        $map['goods_allmoney'] = array('gt',0);
        if($postdata['wm_type'] == 13){
            $map['type']=13;
        }elseif($postdata['wm_type'] == 14){
            $map['type']=array('in','6,14');
        }elseif($postdata['wm_type'] == 3){
            $map['type']=3;
        }else{
            // $map['type']=array('in','6,13,14,3');//拼团和收银订单和外卖
            $map['type']=array('in','6,14,3');//拼团和收银订单和外卖  xyy 118
        }
        $map['send_type']=array('neq',1);
        if($postdata['order_sn'])$map['order_sn']=$postdata['order_sn'];
        if($postdata['status']){
            if($postdata['status']==1 || $postdata['status']==2){$map['status']=array('in','1,2,6,8');}else{$map['status']=$postdata['status'];}
        }
        if($postdata['pay_status'])$map['pay_status']=$postdata['pay_status'];
        if($postdata['shipping_status'])$map['shipping_status']=$postdata['shipping_status'];
        if($postdata['shop_id'])$map['shop_id']=$postdata['shop_id'];
        if($postdata['send_type'])$map['send_type']=$postdata['send_type'];
        //仓库管理员
        if($this->auth_group_id==2){
            $map['shop_id']=$this->admin_info['shop_id'];
        }
        $list = $this->lists('OrderInfo',$map);
        foreach($list as $k=>$v){
            if($v['type']==3){
                $list[$k]['goods_amount']=format_decimal($v['goods_amount']-$v['used_score_money']);
            }else{
                $list[$k]['goods_amount']=$v['goods_amount'];
            }
        }
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
    public function pt_index(){
        $name = CONTROLLER_NAME;
        $map = array();
        $postdata = I('param.');
        $map['goods_allmoney'] = array('gt',0);
        $map['type'] = 6;
        if($postdata['order_sn'])$map['order_sn'] = $postdata['order_sn'];
        if($postdata['status'])$map['status'] = $postdata['status'];
        if($postdata['pay_status'])$map['pay_status'] = $postdata['pay_status'];
        if($postdata['shipping_status'] == 1){
             $map['shipping_status'] = array('neq',6);
        }else if($postdata['shipping_status'] == 6){
             $map['shipping_status'] = 6;
        }
        if($postdata['shop_id'])$map['shop_id'] = $postdata['shop_id'];
        if($postdata['send_type'])$map['send_type'] = $postdata['send_type'];
        //仓库管理员
        if($this->auth_group_id == 2){
            $map['shop_id']=$this->admin_info['shop_id'];
        }
        $list = $this->lists('OrderInfo',$map);
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
    public function zt_index(){
        $name = CONTROLLER_NAME;
        $map=array();
        $postdata=I('param.');
        $map['goods_allmoney'] = array('gt',0);
        if($postdata['wm_type'] == 13){
            $map['type']=13;
        }elseif($postdata['wm_type'] == 14){
            $map['type']=array('in','6,14');
        }elseif($postdata['wm_type'] == 3){
            $map['type']=3;
        }else{
            $map['type']=array('in','6,13,14,3');//拼团和收银订单和外卖
        }
        $order_shipping=array('5'=>'已备货','4'=>'已收货','3'=>'未备货');
        $this->assign('order_shipping',$order_shipping);
        if($postdata['order_sn'])$map['order_sn']=$postdata['order_sn'];
        if($postdata['status'])$map['status']=$postdata['status'];
        if($postdata['pay_status'])$map['pay_status']=$postdata['pay_status'];
        if($postdata['shipping_status'])$map['shipping_status']=$postdata['shipping_status'];
        if($postdata['shop_id'])$map['shop_id']=$postdata['shop_id'];
        $map['send_type']=1;
        //仓库管理员
        if($this->auth_group_id==2){
            $map['shop_id']=$this->admin_info['shop_id'];
        }
        $list = $this->lists('OrderInfo',$map);
        foreach($list as $k=>$v){
            if($v['type']==3){
                $list[$k]['goods_amount']=format_decimal($v['goods_amount']-$v['used_score_money']);
            }else{
                $list[$k]['goods_amount']=$v['goods_amount'];
            }
        }
        $this->assign('list',$list);$this->assign($postdata);
        $this->display('zt_index');
    }
    public function zt_view(){
        $order_shipping=array('5'=>'已备货','4'=>'已收货','3'=>'未备货');
        $this->assign('order_shipping',$order_shipping);
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $operable_list=$this->operable_list($id);
        $this->assign('operable_list',$operable_list);
        $map_oi= $map = array();
        $map_oi['id']=$map['order_id'] = $id;
        $order_info=M('OrderInfo')->where($map_oi)->find();
        $ordergoods=M('OrderGoods')->where($map)->field(true)->select();
        $ordershipping=M('ShipOrder')->where($map)->field(true)->select();
        $ordership=array();
        foreach($ordershipping as $v){
            $goodsid=explode(',',$v['goods_id']);
            foreach($goodsid as $val){
                $ordership[$val]=$v;
            }
        }
        foreach($ordergoods as $k=>$v){
            $attr=unserialize($v['goods_attr']);
            $ordergoods[$k]['attr_name']=$attr['name'];
            $ordergoods[$k]['org_parce']=$v['goods_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
            $ordergoods[$k]['shipping']=$ordership[$v['goods_id']];
            $goods_ids[]=$v['goods_id'];
        }

        $this->assign('ordergoods',$ordergoods);
        $actionlog=M('ActionLog')->where('action_id in (9,10) and record_id='.$id)->order('id desc')->select();
        $this->assign('actionlog',$actionlog);
        $map_pl['order_id']=array('like','%,'.$id.',%');
        $use_score_money=M('PayLog')->where($map_pl)->getfield('use_score_money');
        $this->assign('use_score_money',$use_score_money);

  
        $rest_discount=$order_info['discount']-$order_info['bonus_money']-$order_info['member_discount']-$order_info['custom_discount']-$order_info['goods_custom_discount']-$order_info['used_score_money']-$order_info['first_money'];
        $promote_money=format_decimal($rest_discount);
        $this->assign('promote_money',$promote_money);
        $this->assign($order_info);
        $this->display();
    }
	public function service_index(){
        $name = CONTROLLER_NAME;
        $map=array();
        $postdata=I('param.');
        $map['type']=11;
        $map['goods_allmoney'] = array('gt',0);
        if($postdata['order_sn'])$map['order_sn']=$postdata['order_sn'];
        if($postdata['status'])$map['status']=$postdata['status'];
        if($postdata['pay_status'])$map['pay_status']=$postdata['pay_status'];
        if($postdata['shipping_status'])$map['shipping_status']=$postdata['shipping_status'];
        if($postdata['service_type'] == 1){
			$map['province']=array('neq','');$map['city']=array('neq','');
		}elseif($postdata['service_type'] == 2){
			$map['province']=array('eq','');
		}
		if($postdata['data_from'])
			$map['addtime'][] = array('egt',strtotime($postdata['data_from']));
		if($postdata['data_to'])
			$map['addtime'][] = array('elt',strtotime($postdata['data_to']));
        if($postdata['keyword']){
            $whereor['uid']=$postdata['keyword'];
            $whereor['consignee']=array('like','%'.$postdata['keyword'].'%');
            $whereor['address']=array('like','%'.$postdata['keyword'].'%');
            $whereor['mobile']=array('like','%'.$postdata['keyword'].'%');
            $whereor['email']=array('like','%'.$postdata['keyword'].'%');
            $whereor['temp']=array('like','%'.$postdata['keyword'].'%');
            $whereor['_logic'] = 'or';
            $map['_complex'] = $whereor;
        }
        //仓库管理员
        if($this->auth_group_id==2){
            $map['shop_id']=$this->admin_info['shop_id'];
        }
        $list = $this->lists('OrderInfo',$map);
		$servicedata = array('1'=>'上门服务','2'=>'到店服务');
		$this->assign('servicedata',$servicedata);
		$this->order_shipping = array('3'=>'待核销','4'=>'已核销');
		$this->assign('order_shipping',$this->order_shipping);
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
    public function _before_edit(){
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $this->getNodeTree();
		$ordergoods=M('OrderGoods')->where('order_id='.$id)->select();
        $orderinfo=M('OrderInfo')->where('id='.$id)->field(true)->find();
		$ordershipping=M('ShipOrder')->where('order_id='.$id)->select();
		$ordership=array();
		foreach($ordershipping as $v){
			$goodsid=explode(',',$v['goods_id']);
			foreach($goodsid as $val){
				$ordership[$val]=$v;
			}
		}
		foreach($ordergoods as $k=>$v){
			$attr=unserialize($v['goods_attr']);
			$ordergoods[$k]['attr_name']=$attr['name'];
			$ordergoods[$k]['org_parce']=$v['attr_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
            $ordergoods[$k]['shipping']=$ordership[$v['goods_id']];
		}
		$this->assign('ordergoods',$ordergoods);
		$this->assign($orderinfo);
        $map_pl['order_id']=array('like','%,'.$id.',%');
        $use_score_money=M('PayLog')->where($map_pl)->getfield('use_score_money');
        $this->assign('use_score_money',$use_score_money);
    }
    public function _before_update(){
        $_POST['province']=$_POST['area_sheng'];
        $_POST['city']=$_POST['area_shi'];
        $_POST['district']=$_POST['area_xian'];
        if($_POST['pay_fee_old']!=$_POST['pay_fee'] || $_POST['shipping_fee_old']!=$_POST['shipping_fee']){
            $_POST['order_amount']=$_POST['goods_amount']+$_POST['pay_fee']+$_POST['shipping_fee'];
        }
        $save['shipping_sn']=I('post.shipping_sn');
        $where['id']=I('post.id');
        M('OrderInfo')->where($where)->save($save);
        unset($_POST['area_sheng'],$_POST['area_shi'],$_POST['area_xian'],$_POST['pay_fee_old'],$_POST['shipping_fee_old']);
        action_log('update_order', 'Admin',I('id'),UID);
    }    
    public function _before_view(){
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $operable_list=$this->operable_list($id);
        $this->assign('operable_list',$operable_list);
        $map = array();
        $map['order_id'] = $id;
        $ordergoods=M('OrderGoods')->where($map)->field(true)->select();
        $ordershipping=M('ShipOrder')->where($map)->field(true)->select();
        $ordership=array();
        foreach($ordershipping as $v){
            $goodsid=explode(',',$v['goods_id']);
            foreach($goodsid as $val){
                $ordership[$val]=$v;
            }
        }
        foreach($ordergoods as $k=>$v){
            $attr=unserialize($v['goods_attr']);
            $ordergoods[$k]['attr_name']=$attr['name'];
            $ordergoods[$k]['org_parce']=$v['goods_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
            $ordergoods[$k]['shipping']=$ordership[$v['goods_id']];
            $goods_ids[]=$v['goods_id'];
        }
		
        $this->assign('ordergoods',$ordergoods);
        $actionlog=M('ActionLog')->where('action_id in (9,10) and record_id='.$id)->order('id desc')->select();
        $this->assign('actionlog',$actionlog);
        $map_pl['order_id']=array('like','%,'.$id.',%');
        $use_score_money=M('PayLog')->where($map_pl)->getfield('use_score_money');
        $this->assign('use_score_money',$use_score_money);
		
        $map = array();
        $map['id'] = $id;
        $orderinfo=M('OrderInfo')->where($map)->field(true)->find();
        // $promot_id=$orderinfo['promot_id'];
        // if($promot_id){
        //     $act_ids = explode(',', $promot_id);
        //     $act_ids=array_filter($act_ids);
        //     $promote_arr = D('Common/Takeout')->getpromote($act_ids,$id);
        //     $promote_money = array_sum(i_array_column($promote_arr,'money'));
        $rest_discount=$orderinfo['discount']-$orderinfo['bonus_money']-$orderinfo['member_discount']-$orderinfo['custom_discount']-$orderinfo['goods_custom_discount']-$orderinfo['used_score_money']-$orderinfo['first_money'];
            $promote_money=format_decimal($rest_discount);
            $this->assign('promote_money',$promote_money);
        // }        
        $DIS_TRIBUTE=C("DIS_TRIBUTE");
        if($DIS_TRIBUTE == 1 && $orderinfo['distribute']){
            $reqStatus = D('Common/Distribute')->details_order($orderinfo);            
            $this->assign('reqstatus',$reqStatus);
        }
        $this->assign('DIS_TRIBUTE',$DIS_TRIBUTE);
        if($orderinfo['pay_status']==3 && $orderinfo['shipping_status']==3 && $orderinfo['send_type']!=1){
            $is_tui=1;
        }else{
            $is_tui=0;
        }
        $this->assign('is_tui',$is_tui);
    }
    public function sy_view(){
		$id=I('id');
		if(empty($id))$this->error('参数不正确');
		$orderinfo=M('OrderInfo')->where('id='.$id)->field(true)->find();
		$ordergoods=M('OrderGoods')->where('order_id='.$id)->field(true)->select();
		foreach($ordergoods as $k=>$v){
			$attr=unserialize($v['goods_attr']);
			$ordergoods[$k]['attr_name']=$attr['name'];
			$ordergoods[$k]['org_parce']=$v['attr_price']*$v['goods_number'];
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
		}
		$this->assign('ordergoods',$ordergoods);
		$this->assign($orderinfo);
        $this->display();
    }
	public function th_index(){
        $map=array();
		$postdata=I('param.');
        if($postdata['order_sn'])
			$map['oi.order_sn']=$postdata['order_sn'];
		
        $map['rg.type']=0;
        $map['oi.type']=array('in','11,13,14');
        $map['goods_allmoney']=array('gt',0);
		$list = M('ReturnGoods')->alias('rg')
								->JOIN('__ORDER_INFO__ oi on rg.order_id = oi.id')
								->where($map)
								->field('rg.id,rg.reason,rg.money,rg.add_time,rg.status as rg_status,oi.order_sn,oi.order_amount,oi.uid,oi.province,oi.city,oi.district,oi.shipping_status,oi.addtime')
								->order('rg.id desc')
								->select();
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
    public function tk_index(){
        $map=array();
        $postdata=I('param.');
        if(!empty($postdata['order_sn'])){
            $order_id=idtoname($postdata['order_sn'],'OrderInfo','id','order_sn');
            if($order_id){$map['order_id']=$order_id;}else{$map['order_id']=-1;}
        }

        if(empty($postdata['is_first'])){
            if(empty($postdata['data_from']))$postdata['data_from'] = date('Y-m-d 00:00:00', time());
            if(empty($postdata['data_to']))$postdata['data_to'] = date('Y-m-d 23:59:59', time());
        }
        if ($postdata['data_from']) {$map['addtime'][] = array('egt', strtotime($postdata['data_from']));}
        if ($postdata['data_to']) {$map['addtime'][] = array('elt', strtotime($postdata['data_to']));}
        //仓库管理员
        if($this->auth_group_id==2){
            $map['shop_id']=$this->admin_info['shop_id'];
        }        
//        $field='a.id,a.reason,a.money,a.refund_money,a.refund_scores,a.refund_web,a.addtime as ro_addtime,a.status as rg_status,oi.order_sn,oi.type,oi.order_amount,oi.uid,oi.province,oi.city,oi.district,oi.shipping_status,oi.addtime,oi.status as oi_status';
        $field='id,reason,money,refund_money,refund_scores,refund_web,addtime as ro_addtime,status as rg_status,order_id,uid';
//        $join='__ORDER_INFO__ oi on a.order_id = oi.id';
        $list=page_list('RefundOrder',$map,'id desc',$field,0);
        // $this->assign('list',$list['list']);
        $this->assign($postdata);
        $this->assign($list);
        $this->display();
    }
    /**
    * 编辑退款
    */
    public function tk_edit(){
        $id=I('id');
        $info=M('RefundOrder')->where('id='.$id)->field('id,uid,money,addtime,refund_money,refund_scores,refund_web')->find();
        $this->assign($info);
        $this->display();
    }
    /**
    * 处理退款
    */
    public function edit_refund(){
        $return=array('status'=>0,'msg'=>'');
        $postdata=I('param.');
        $id=$postdata['id'];

        //判断是否已经退款
        $info=idtoname($id,'RefundOrder','status,uid,order_id,order_goods');
        if($info['status']){$return['msg']='退款已处理';$this->ajaxReturn($return);}

        //如果是退货生成的 判断退货单是否同意了
        $org_map['uid']=$info['uid'];

        if(strpos($info['org_id'],',')){
            $org_map['id']=array('in',$info['org_id']);
        }else{
            $org_map['order_id']=$info['order_id'];
        }
        $org_map['org_id']=$info['order_goods'];
        $reg_info=M('ReturnGoods')->where($org_map)->field('id,status,shop_status')->find();
        if(!empty($reg_info)){
            if($reg_info['status']==0 || $reg_info['shop_status']==0 ){
                $return['msg']='请先处理退货单';
                $return['url']=U('OrderInfo/tk_index',array('id'=>$reg_info['id']));
                $this->ajaxReturn($return);
            }
        }
        $admin_id=UID;
        if($admin_id){
            if(isset($postdata['money']))$org_save['refund_money']=$money=$postdata['money'];
            if(isset($postdata['refund_scores']))$org_save['refund_scores']=$refund_scores=$postdata['refund_scores'];
            if(isset($postdata['refund_money']))$org_save['refund_money']=$refund_money=$postdata['refund_money'];
            if(isset($postdata['refund_web']))$org_save['refund_web']=$refund_web=$postdata['refund_web'];
        }
        $map['id']=$id;
        $res=M('RefundOrder')->where($map)->save($org_save);
        if($res===false){$return['msg']='修改失败';$this->ajaxReturn($return);}

        $result=D('Common/OrderInfo')->handle_order($id,'Admin',UID,0);
        if($result['status']==1 && !empty($reg_info)){ //加退款退货物流单
            $reg_info=unserialize($reg_info['goods_info']);
            $map=array();
            $map['id']=$info['order_goods'];
            $goods=M('OrderGoods')->where($map)->field(true)->find();
            if($goods['goods_attr_key']){
                $map=array();
                $map['goods_id']=$goods['goods_id'];
                $map['attr_key']=$goods['goods_attr_key'];
                $sn= M('GoodsAttrStock')->where($map)->cache(true)->getField('goods_attr_sn');
                if($sn)$goods['goods_sn']=$sn;
            }
            $goods_info=idtoname($goods['goods_id'],'Goods','supply_price,shop_price,suppliers_id');
            $attr=unserialize($goods['goods_attr']);
            $data=array();
            $data['infos']['goods_id'][]=$goods['goods_id'];
            $data['infos']['goods_attr_sn'][]=$goods['goods_attr_key']?$goods['goods_attr_key']:'';//属性id
            $data['infos']['request_num'][]=$reg_info['number'];//请求量
            $data['infos']['freight_num'][]=$reg_info['number'];//实际发货数
            $data['infos']['fact_num'][]=$reg_info['number'];//实际收货数量
            $data['infos']['goods_sn'][]=$goods['goods_sn'];
            $data['infos']['stock'][]='';
            $data['infos']['goods_name'][]=$goods['goods_name'];
            $data['infos']['all_money'][]=$goods_info['supply_price']*$reg_info['number'];//进货价
            $data['infos']['goods_attr_name'][]=$attr?$attr['name']:'';
            $data['infos']['supplier_id'][]=$goods_info['suppliers_id'];
            $data['infos']['supply_price'][]=$goods_info['supply_price'];
            $data['infos']['shop_price'][]=$goods_info['shop_price'];
            $data['shop_id_in'] =$goods['shop_id'];
            $data['status'] = 2;
            $data['goods_status'] = 2;
            $data['out_type'] = '';
            $data['out_price'] = '';
            $data['remarks'] = '';
            $data['type']=5;
            $data['is_sn']=1;
            $data['log_name']='return_goods';
            D('Common/InvoicingOrder')->order_in_insert($data);
        }
        $this->ajaxReturn($result);
    }
    /**
    * 同意退货
    */
    public function agree(){
        $post['id']=I('id');
        $post['type']=1;
        $post['admin_id']=UID;//操作日志用
        $post['margin_type']='Admin';//操作日志用
        $return=D('Common/OrderInfo')->return_pgoods($post);
        $this->ajaxReturn($return);
    }
    /**
    * 拒绝页面
    */
    public function th_content(){
        $id=I('id');
        $this->assign('id',$id);
        $this->display();
    }
	/**
     * 拒绝退货
     */
    public function notagree(){
        $post['id']=I('id');
        $post['type']=2;
        $post['admin_id']=UID;//操作日志用
        $post['margin_type']='Admin';//操作日志用
        $return=D('Common/OrderInfo')->return_goods($post);
        $this->ajaxReturn($return);
    }
    public function ordergoods(){
        $id=I('id');
        if(empty($id))$this->error('参数不正确');
        $ordergoods=M('OrderGoods')->where('order_id='.$id)->select();
        foreach($ordergoods as $k=>$v){
            $attr=unserialize($v['goods_attr']);
            $ordergoods[$k]['attr_name']=$attr['name'];
            $ordergoods[$k]['goods_price_format']=format_price($v['goods_price']);
            $ordergoods[$k]['org_parce']=$v['goods_price']*$v['goods_number'];
            $ordergoods[$k]['org_parce_format']=format_price($ordergoods[$k]['org_parce']);
            $ordergoods[$k]['org_integral']=$v['goods_integral']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
        }
        $this->assign('ordergoods',$ordergoods);
		$this->assign('order_id',$id);
        $this->display();
    }
	public function delete_goods(){exit();
		$get=I('get.');
		$delete['id']=$get['id'];
		$delete_goods=M('OrderGoods')->where($delete)->delete();
		$url=U('Admin/OrderInfo/ordergoods',array('id'=>$get['order_id']));
		if($delete_goods!= false){
			$this->success('操作成功！',$url);
		}else{
			$this->error('操作失败！',$url);
		}
	}
	public function new_og(){
		$getdata=I('get.');
		$map['id']=$getdata['id'];
		$map['order_id']=$getdata['order_id'];
		$info=M('OrderGoods')->where($map)->find();
        $info['goods_number']=floatval($info['goods_number']);
        $goods_attr=unserialize($info['goods_attr']);
        // print_r($info['goods_attr']);
		//print_r($getdata);exit;
		$this->assign($info);
		$this->assign('goods_attrs',$goods_attr);
		$this->assign('id',$getdata['id']);
		$this->assign('order_id',$getdata['order_id']);
		$this->display();
	}
	//编辑订单商品
	public function new_og_edit(){
	    $data=I('post.');
        $map['id']=$data['id'];
        $goods_id=M("OrderGoods")->where($map)->getField('goods_id');
		if($data){
			$where['id']=$data['id'];
			$where['order_id']=$data['order_id'];
            $attr=$data['attr_key'];
            $name=$data['attr_name'];
            $attrstock = D("Common/GoodsAttr")->check_attr_stock($attr, $goods_id, $data['goods_number'], $name);
            if ($attrstock['status'] == 0) {
               $this->error("商品库存不足",U('OrderInfo/ordergoods',array('id'=>$data['order_id'])));
            }
            //判断商品库存以及最大购买量和最少购买量
            $check_goods_count = D("Common/Cart")->check_cart_number($goods_id, $data['goods_number']);
            if ($check_goods_count['status'] == 1) {
                $this->error("商品库存不足",U('OrderInfo/ordergoods',array('id'=>$data['order_id'])));
            }
            $goods_attr=array(
                'key'=>$data['attr_key'],
                'name'=>$data['attr_name']
            );
            $data['goods_arrt']=$goods_attr;
            $info=M('OrderGoods')->where($where)->save($data);
			if($info !== false){
            	$this->success('编辑成功！',U('OrderInfo/ordergoods',array('id'=>$data['order_id'])));
        	}else{
            	$this->error('编辑失败！',U('OrderInfo/ordergoods',array('id'=>$data['order_id'])));
        }
		}
	}
	//已下订单添加商品
	public function order_add_goods(){
		$id=I('order_id');
		$map['id']=$id;
		$info=M('OrderInfo')->where($map)->find();
		$this->assign('u_id',$info['uid']);
		$this->assign('shop_id',$info['shop_id']);
		$this->assign('order_id',$id);
		$this->display();
	}

    /**
     * 更新订单价格
     */
    public function updateordergoods(){

        $mod=M('OrderInfo');

        $id=I('post.order_id');if(empty($id))$this->error('参数不正确');
		
		$orderinfo=$mod->field('goods_amount,order_amount,order_money')->find($id);

		$where['order_id']=$id;
		
		$order_goods=M('OrderGoods')->where($where)->field(true)->select();
		$new_order_amount=0;
        //修改订单价格
		foreach($order_goods as $k=>$v){
			$new_order_amount+=$v['goods_price']*$v['goods_number'];
		}
        if($new_order_amount>=$orderinfo['order_amount']){
            $data['order_money']=$new_order_amount;
            $data['order_amount']=$new_order_amount;
        }else{
            $data['order_money']=$new_order_amount;
            $data['order_amount']=$orderinfo['order_amount'];
        }
        $mod->where('id='.$id)->save($data);
        action_log('update_order', 'Admin',I('id'),UID,'更新订单商品价格');
        //作废支付单，
        $p_where['is_delete'] = 0;
        $p_where['order_id'] = array("like", "%," . $id. ",%");
        $o_data['is_delete']=1;
        $pay_info = M("PayLog")->where($p_where)->field(true)->find();

        $del_pay= M("PayLog")->where($p_where)->save($o_data);

        //重新生成支付单
        $p_where['id']=array("in",$pay_info['order_id']);
        $pay_order=M("OrderInfo")->where($p_where)->select();
        foreach(array_filter($pay_order) as $key=>$val){
            if($val['id']==0){
                unset($val['id']);
            }
            $pay_order_id[]=$val['id'];
        }
        $pay_order_id=array_filter($pay_order_id);
        if(!empty($pay_order_id)){
            $payment_id=','.implode(',',$pay_order_id).',';
            $map['id']=array('in',implode(',',$pay_order_id));
            $order_info=M("OrderInfo")->where($map)->field('sum(order_money) as total_price')->find();
            $payment=array();
            $payment['order_id']=$payment_id;
            $payment['type']=$pay_info['type'];
            $payment['user_id']=$pay_info['user_id'];
            $payment['order_sn']=createOrderNo();
            $payment['use_money']=0;
            $payment['use_score']=0;
            $payment['use_score_money']=0;
            $payment['pay_amount']=$order_info['total_price'];
            $payment['order_total_price']=$order_info['total_price'];
            $payment['payment_id']=$pay_info['payment_id'];
            $payment['pay_code']=$pay_info['pay_code'];
            $payment['is_paid']=0;
            $payment['create_time']=NOW_TIME;
            M("PayLog")->add($payment);

        }
        $this->success('更新成功',U('OrderInfo/view',array('id'=>$id)));

    }
	public function add_user(){
		$store=M('Store')->field(true)->select();
		foreach($store as $k=>$v){
			$store_option[$v['id']]=$v['name'];	
		}
		$this->assign('store_option',$store_option);
		$this->display();
    }
	public function add_goods(){
		$order=I('get.');
		$info=I('post.');
		if($info){
			$map['uid']=$info['user_list'];
			if($info['consignee'])$map['consignee']=$info['consignee'];
			if($info['area_sheng'])$map['province']=$info['area_sheng'];
			if($info['area_shi'])$map['city']=$info['area_shi'];
			if($info['area_xian'])$map['district']=$info['area_xian'];
			if($info['address'])$map['address']=$info['address'];
			if($info['store_id'])$map['store_id']=$info['store_id'];
			if($info['mobile'])$map['mobile']=$info['mobile'];
			if($info['best_time'])$map['best_time']=$info['best_time'];
			$map['status']=0;
			$map['addtime']=NOW_TIME;
			$map['order_sn']= createOrderNo();
			//print_r($map);exit;
			$add_order=M('OrderInfo')->add($map);
			$this->assign('order_id',$add_order);
			$this->assign('u_id',$map['uid']);
		}
		if($order){
			$order_info=M('OrderGoods')->where('order_id='.$order['id'])->field(true)->select();
			foreach($order_info as $k=>$v){
				$order_info[$k]['only_price']=$order_info[$k]['goods_price']/$order_info[$k]['goods_number'];
			}
			$goods_amount=M('OrderInfo')->where('id='.$order['id'])->field('goods_amount')->find();
			$this->assign('goods_amount',$goods_amount['goods_amount']);
			$this->assign('order_id',$order['id']);
			$this->assign('u_id',$order['u_id']);
			$this->assign('order_info',$order_info);
		}
		$this->display();
	}
	public function add_info(){
		$order_id=I('post.order_id');
		$u_id=I('post.u_id');
		//echo $order_id;exit;
		$order_info=M('OrderInfo')->where('id='.$order_id)->field(true)->find();
		if(!empty($order_info['consignee'])){
			$send=M('Shipping')->where('status=1')->field(true)->select();
			//print_r($send);exit;
			$this->assign('send_goods',$send);	
		}
		$this->assign('order_info',$order_info);
		//print_r($order_info);exit;
		$goods_id=M('OrderGoods')->alias('og')->where('og.order_id='.$order_id)->field('og.goods_id,g.catid')->JOIN('LEFT JOIN __GOODS__ g ON og.goods_id=g.id')->select();		
		$a=$buy_integral=$rank_integral=0;
		foreach($goods_id as $key=>$value){
			$bonus_goods[$a] = M('Goods')->field(true)->where('id='.$value['goods_id'])->find();
			if($bonus_goods[$a]['integral'] = 0){
				if($bonus_goods[$a]['give_integral'] >= 0){
					$buy_integral += $bonus_goods[$a]['give_integral'];
				}elseif($cart_info[$i]['give_integral'] == -1){
					$buy_integral += $bonus_goods[$a]['price_goods_attr'];
				}
				if($bonus_goods[$a]['rank_integral'] >= 0){
					$rank_integral += $bonus_goods[$a]['rank_integral'];
				}elseif($bonus_goods[$a]['rank_integral'] == -1){
					$rank_integral += $bonus_goods[$a]['price_goods_attr'];
				}
				$a++;
			}
		}
		$bonus_user = M('MemberBonus')->alias('mb')->field('b.*,mb.*')->where('mb.used_time=0 and b.id != 4')->JOIN('LEFT JOIN __BONU__ b ON b.id=mb.bonus_type_id')->select();
		//print_r($bonus_user);exit;
		foreach($goods_id as $key=>$value2){
			foreach($bonus_user as $key1=>$value1){
				if($value1['cat_id']==0){
					if(!empty($bonus_user[$key1]['type_name']) && ($bonus_user[$key1]['min_goods_money'] <= $all_money ) && ($bonus_user[$key1]['start_time'] <= NOW_TIME && $bonus_user[$key1]['end_time'] >= NOW_TIME)){
							if($bonus_user[$key1]['bonus_type_id']==1 && $bonus_user[$key1]['user_id']==$sess['id']){
								$bonu_user[$key1]=$value1;
							}elseif($bonus_user[$key1]['bonus_type_id']==2 && $bonus_user[$key1]['bonus_sn']==$goods_id[$key]['goods_id']){
								$bonu_user[$key1]=$bonus_user[$key1];
								$cat=M('Goods')->where('id='.$bonus_user[$key1]['bonus_sn'])->field('catid')->find();
								$bonu_user[$key1]['cat_id']=$cat['catid'];
							}elseif($bonus_user[$key1]['bonus_type_id']>4 && $bonus_user[$key1]['user_id']==$sess['id']){
								$bonu_user[$key1]=$bonus_user[$key1];
							}
					}
				}else{
					if(!empty($bonus_user[$key1]['type_name']) && ($bonus_user[$key1]['min_goods_money'] <= $all_money ) && ($bonus_user[$key1]['start_time'] <= NOW_TIME && $bonus_user[$key1]['end_time'] >= NOW_TIME)){
							if($bonus_user[$key1]['bonus_type_id']==1 && $bonus_user[$key1]['user_id']==$sess['id'] && $bonus_user[$key1]['cat_id']==$goods_id[$key]['catid']){
								$bonu_user[$key1]=$value1;
							}elseif($bonus_user[$key1]['bonus_type_id']==2 && $bonus_user[$key1]['bonus_sn']==$goods_id[$key]['goods_id']){
								$bonu_user[$key1]=$bonus_user[$key1];
								$cat=M('Goods')->where('id='.$bonus_user[$key1]['bonus_sn'])->field('catid')->find();
								$bonu_user[$key1]['cat_id']=$cat['catid'];
							}elseif($bonus_user[$key1]['bonus_type_id']>4 && $bonus_user[$key1]['user_id']==$sess['id'] && $bonus_user[$key1]['cat_id']==$goods_id[$key]['catid']){
								$bonu_user[$key1]=$bonus_user[$key1];
							}
					}
				}
			}
		}
		if($order_info['uid']){
			$userank = M('Member')->where('id='.$order_info['uid'])->field('money')->find();
			$this->assign('use_money',$userank['money']);
		}
		$pay=M('Payment')->where('status=1')->field(true)->select();
		$this->assign('payment',$pay);
		$this->assign('buy_integral',$buy_integral);
		$this->assign('rank_integral',$rank_integral);
		$this->assign('bonus',$bonu_user);
		$this->assign('order_id',$order_id);
		$this->display();
    }
	public function order_all_info(){
		$info=I('post.');
		//支付费用
		$pay=M('Payment')->where("code='".$info['paytype']."'")->field('fee')->find();
		$pay_fee= getfeemoney($info['order_money'],$pay['fee'],'1');
		$id=M('OrderInfo')->where('id='.$info['order_id'])->field('uid')->find();
		//是否使用余额
		$user_money = I('post.money',0);
		if($user_money && $user_money<=$info['order_money']){
			$use_mon['money']=$pri['money']-$user_money;
			M('Member')->where('id='.$sess['id'])->save($use_mon);
			$add_log['uid']=$id;
			$add_log['adminid']=0;
			$add_log['change_type']=1;
			$add_log['change_num']=$user_money;
			$add_log['change_time']=NOW_TIME;
			$add_log['type']=1;
			$add_log['status']=4;
			M('AccountLog')->add($add_log);
		}
		//是否使用红包
		if($all_info['use_bonu_goods']){
		$boun_user_money=M('MemberBonus')->where('bonus_id='.$all_info['use_bonu_goods'])->field(true)->find();					
			if($boun_user_money){
				$bonus=$boun_user_money['money'];
				if($boun_user_money['bonus_type_id']!=2){
				$user_bonu['used_time']=NOW_TIME;}
				$user_bonu['user_id']=$id;
				$where_mb['bonus_id']=$all_info['use_bonu_goods'];
				//print_r($user_bonu);exit;
				$boun_user_del=M('MemberBonus')->where($where_mb)->save($user_bonu);	
			}
		}
		//是否满足订单红包
		$order_bonus_3=M('Bonu')->where('id=3')->field(true)->find();
		if(($order_bonus_3['min_goods_amount'] <= $info['order_money'] ) && ($order_bonus_3['send_start_date'] < NOW_TIME && $order_bonus_3['send_end_date'] > NOW_TIME)){
			$order_bonus_money=$order_bonus_3['type_money'];
		}
		//改变积分
		if($id){
			$pri=M('Member')->where('id='.$id['uid'])->field('money,points,usepoints')->find();
			$huan['points']=$pri['points']+$all_info['rank_integral'];
			$huan['usepoints']=$pri['usepoints']+$all_info['buy_integral'];
			M('Member')->where('id='.$id['uid'])->save($huan);
			$add_log_rank['uid']=$id;
			$add_log_rank['adminid']=0;
			$add_log_rank['change_type']=3;
			$add_log_rank['change_num']=$all_info['rank_integral'];
			$add_log_rank['change_time']=NOW_TIME;
			$add_log_rank['type']=0;
			$add_log_rank['status']=6;
			M('AccountLog')->add($add_log_rank);
			$add_log_buy['uid']=$id;
			$add_log_buy['adminid']=0;
			$add_log_buy['change_type']=4;
			$add_log_buy['change_num']=$all_info['buy_integral'];
			$add_log_buy['change_time']=NOW_TIME;
			$add_log_buy['type']=0;
			$add_log_buy['status']=6;
			M('AccountLog')->add($add_log_buy);
		}
		//是否有运费
		if($info['order_money'] < $yunfei)$send_fee=$money; else $send_fee=0;
		$arr['shipping_id']=$info['sendtype'];
		$arr['shipping_fee']=$send['code_fee'];
		$arr['shipping_status']=1;
		$arr['pay_code']=$info['paytype'];
		$arr['pay_fee']=$pay_fee;
		$arr['status']=1;
		$arr['order_amount']=$info['order_money']+$send_fee-$use_money-$bonus-$order_bonus_money;
		$save_order=M('OrderInfo')->where('id='.$info['order_id'])->save($arr);
		if($save_order){
            $this->success('添加成功！',U('OrderInfo/index'));
        }else{
            $this->error('添加失败！',U('OrderInfo/index'));
        }
		//print_r($info);exit;
	}
	//商品搜索
	public function search_goods(){
		$g_ingo=I('get.goods_info');
		if($g_ingo){
            $whereor['id']=array('like','%'.$g_ingo.'%');
            $whereor['goods_name']=array('like','%'.$g_ingo.'%');
            $whereor['goods_sn']=array('like','%'.$g_ingo.'%');
            $whereor['_logic'] = 'or';
            $map['_complex'] = $whereor;
        }
		$g_list=M('Goods')->where($map)->field('id,goods_name,goods_sn,status,shop_id')->select();
		//print_r($g_list);exit;
		$result="<option>请选择商品</option>";
		foreach($g_list as $k=>$v){
			if($v['status']==1){
				$result.="<option value='".$v['id']."'>".$v['goods_name']."</option>";	
			}
		}
		echo $result;exit;
	}
	//添加商品
	public function change_goods(){
		$g_id=I('get.goods_id');
		$u_id=I('get.user_info');
        //debug 这里需验证某个区域内的商品
		$g_info=M('Goods')->where('id='.$g_id)->find();
		$g_info['cat_name']=idtoname($g_info['cat_id'],'GoodsCategory','name');
		$g_info['brand_name']=idtoname($g_info['brand_id'],'Brand','brand_name');
		//print_r($g_info);exit;
		$goods_attr = M('goods_attr')->alias('ga')->field('ga.attr_id,ga.attr_value,ga.attr_price,g.type,ga.attr_img,g.name,g.options')->where('goods_id='.$g_id)->JOIN('LEFT JOIN __GOODS_ATTRIBUTE__ g ON g.id=ga.attr_id')->order('ga.id')->select();
		 $goodsattr=$goodsattr_price=array();
		foreach($goods_attr as $k=>$row){
			$valarr_img=$valarr=$attrarr='';
			if(in_array($row['type'],array('select','radio','checkbox'))){
				$valarr=explode(',',$row['attr_value']);
				$attrarr=strtoarray($row['options']);
				if(!empty($row['attr_img']))$valarr_img=explode(',',$row['attr_img']);
			}else{
				$valarr=$row['attr_value'];
				$attrarr=$row['options'];
				if(!empty($row['attr_img']))$valarr_img=$row['attr_img'];
			}
			$goodsattr[$row['attr_id']]['name']=$row['name'];
			$goodsattr[$row['attr_id']]['is_price']=$row['is_price'];			 
			if(is_array($valarr)){
				$arrval=array();
				$i=0;
				foreach($valarr as $key=> $rows){
					if(empty($rows) && !is_numeric($rows))continue;
					if($i==0)$goodsattr[$row['attr_id']]['first_key']=$key;
					$arrval[$rows]=$attrarr[$rows];
					if(!empty($valarr_img[$key]))$goodsattr[$row['attr_id']]['img'][$key]=$valarr_img[$key];
					$goodsattr[$row['attr_id']]['option'][$key]=$attrarr[$rows];
				++$i;}$goodsattr[$row['attr_id']]['value']=implode(',',$arrval);
			}else{
				$goodsattr[$row['attr_id']]['value']=$valarr;
			}
		}
		$attrid=$attr=$price='';
		$price.="<input type='radio' id='market_price' name='price' value='".$g_info['market_price']."'>市场价：".$g_info['market_price']."</br>";
		$price.="<input type='radio' id='shop_price' name='price' value='".$g_info['shop_price']."'>本店价:".$g_info['shop_price']."</br>";
		$price.="<input type='radio' name='price'>自定义价格：<input type='text' name='defind_price' id='defind_price'>";
		//print_r($goodsattr);
			foreach($goodsattr as $ke=>$va){
				//$attrid.=$va['name'].':'.$va['value']."</br>";
				if(count($va['option'])>1){
					$attrid=$va['name'].":".$attrid;
					foreach($va['option'] as $k1=>$v1){
						$attrid.="<input type='radio' name='goods_attr' value='".$v1."'>".$v1;
					}
				}else{
					$attrid.=$va['name'].":".$va['value']."</br>";
				}
			}
			//echo $attrid;exit;
		$attr=rtrim($attr,',');	
			//echo $attrid;exit;
        $result='';
		if($g_info['status']==1){
			$result.="<table width='100%' cellpadding='2' cellspacing='1' class='table_form'>";
			$result.="<tr><th width=100 scope='row'>商品名称:</th><td>".$g_info['goods_name']."<input type='hidden' id='goods_id' value='".$g_info['id']."'></td></tr>";
			$result.="<tr><th width=100 scope='row'>货号:</th><td>".$g_info['goods_sn']."</td></tr>";	
			$result.="<tr><th width=100 scope='row'>分类:</th><td>".$g_info['cat_name']."</td></tr>";	
			$result.="<tr><th width=100 scope='row'>品牌:</th><td>".$g_info['brand_name']."</td></tr>";	
			$result.="<tr><th width=100 scope='row'>价格:</th><td>".$price."</td></tr>";
			$result.="<tr><th width=100 scope='row'>属性:</th><td>".$attrid."</td></tr>";	
			$result.="<tr><th width=100 scope='row'>数量:</th><td><input type='text' name='number' value='1'></td></tr>";
			$result.="<input type='hidden' id='shop_id' value='".$g_info['shop_id']."'>";
			$result.="</table>";						
		}
		echo $result;exit;
	}
	//会员信息
	public function change_user(){
		$u_id=I('get.user_id');
		//echo $u_id;exit;
		$g_info=M('Member')->where('id='.$u_id)->find();
		$address_info=M('MemberAddress')->where('uid='.$u_id)->select();
		$attrid=$attr=$address='';
		$address.="<table width='100%' cellpadding='2' cellspacing='1' class='table_form'>";
		$address.="<tr><th width='95'><b>收货地址信息</b></th><td colspan='6'></td></tr>";
		foreach($address_info as $k=>$v){
			$address.="<tr><th></th><td><input type='radio' onclick='change_add()' id='market_price' name='address_id' value='".$v['id']."'>".idtoname($v['province'],'Area','name').idtoname($v['city'],'Area','name').idtoname($v['district'],'Area','name').$v['address']."&nbsp;&nbsp;".$v['consignee']."&nbsp;手机：&nbsp;".$v['mobile']."</td></tr>";
		}
		$address.="</table>";
		$where['uid']=$u_id;
		$card=M('MemberCard')->where($where)->field('card_sn')->find();
		$order=M('OrderInfo')->where($where)->field('id')->order('id desc')->select();
		$where_or['order_id']=$order[0]['id'];
		$order_goods=M('OrderGoods')->where($where_or)->field('goods_name')->order('id desc')->select();
		if($g_info['status']==1){
			$result.="<table width='100%' cellpadding='2' cellspacing='1' class='table_form'>";
			$result.="<tr><th style='text-align:left;'><b>会员信息</b></th><td colspan='7'></td></tr>";
			$result.="<tr><th class='color' style='text-align:center;'>用户名:</th><td>".$g_info['username']."</td>";
			$result.="<th class='color' style='text-align:center;'>手机:</th><td class='red'>".$g_info['mobile']."</td>";	
			$result.="<th class='color' style='text-align:center;'>注册时间:</th><td>".time_format($g_info['reg_time'])."</td>";	
			$result.="<th class='color' style='text-align:center;'>会员卡号:</th><td class='red'>".$card['card_sn']."</td></tr>";	
			$result.="<tr><th class='color' style='text-align:center;'>可用资金:</th><td>".$g_info['money']."</td>";
			$result.="<th class='color' style='text-align:center;'>上次登录时间:</th><td class='red'>".time_format($g_info['last_login'])."</td>";	
			$result.="<th class='color' style='text-align:center;'>消费积分:</th><td>".$g_info['usepoints']."</td>";
			$result.="<th class='color' style='text-align:center;'>上次购买的商品:</th><td class='red'>".$order_goods[0]['goods_name']."</td></tr>";
			$result.="</table>";						
		}
		$data['add']=$address;
		$data['info']=$result;
		$this->ajaxReturn($data);exit;
	}
	//会员收货地址信息
	public function change_address(){
		$id=I('get.address_id');
		//echo $u_id;exit;
		$address_info=M('MemberAddress')->where('id='.$id)->find();
		$data['consignee']=$address_info['consignee'];
		$area=M('Area')->field('id,name,pid')->select();
		$sheng_option="<option>请选择市</option>";
		foreach($area as $k=>$v){
			if($v['pid']<=1){
				if($v['id']==$address_info['province']){
					$sheng_option.="<option value='".$v['id']."' selected='selected'>".$v['name']."</option>";
				}else{
					$sheng_option.="<option value='".$v['id']."'>".$v['name']."</option>";
				}
			}
		}
		$shi_option="<option>请选择区县</option>";
		foreach($area as $ke=>$va){
			if($va['pid']>1 && $va['pid']<=12){
				if($va['id']==$address_info['city']){
					$shi_option.="<option value='".$va['id']."' selected='selected'>".$va['name']."</option>";
				}else{
					$shi_option.="<option value='".$va['id']."'>".$va['name']."</option>";
				}
			}
		}
		$xian_option="<option>请选择乡镇</option>";
		foreach($area as $key=>$val){
			if($val['pid']>12){
				if($val['id']==$address_info['district']){
					$xian_option.="<option value='".$val['id']."' selected='selected'>".$val['name']."</option>";
				}else{
					$xian_option.="<option value='".$val['id']."'>".$val['name']."</option>";
				}
			}
		}
		$store=M('Store')->field(true)->select();
		$store_option="<option>请选择服务站</option>";
		foreach($store as $k1=>$v1){
			if($v1['id']==$address_info['store_id']){
				$store_option.="<option value='".$v1['id']."' selected='selected'>".$v1['name']."</option>"; 
			}else{
				$store_option.="<option value='".$v1['id']."'>".$v1['name']."</option>";
			}
		}
		$data['store']=$store_option;
		$data['sheng']=$sheng_option;
		$data['shi']=$shi_option;
		$data['xian']=$xian_option;
		$data['mobile']=$address_info['mobile'];
		$data['address']=$address_info['address'];
		$data['best_time']=time_format($address_info['best_time']);				
		$this->ajaxReturn($data);exit;
	}
	public function add_addre(){
		$c=I('get.');//0修改成功；1修改失败；2添加成功；3添加失败；4收货地址最多为5个
		if($c['address_id']){
			$where['id']=$c['address_id'];
			$save['consignee']=$c['consignee'];
			$save['province']=$c['area_sheng'];
			$save['city']=$c['area_shi'];
			$save['district']=$c['area_xian'];
			$save['store_id']=$c['store_id'];
			$save['mobile']=$c['mobile'];
			$save['address']=$c['address'];
			$save['best_time']=$c['best_time'];
			$address_save=M('MemberAddress')->where($where)->save($save);
			if($address_save !=false){
				$data['status']=0;
			}else{
				$data['status']=1;
			}
		}else{
			$where_a['uid']=$c['user_list'];
			$address_count=M('MemberAddress')->where($where)->count();
			if($address_count<5){
				$add['consignee']=$c['consignee'];
				$add['province']=$c['area_sheng'];
				$add['city']=$c['area_shi'];
				$add['district']=$c['area_xian'];
				$add['store_id']=$c['store_id'];
				$add['mobile']=$c['mobile'];
				$add['address']=$c['address'];
				$add['best_time']=$c['best_time'];
				$address_add=M('MemberAddress')->add($add);
				if($address_add !=false){
					$data['status']=2;
				}else{
					$data['status']=3;
				}
			}else{
				$data['status']=4;
			}
		}
		$this->ajaxReturn($data);exit;
	}
	public function add_order_goods(){
		$c=I('get.');
		//print_r($c);exit;
		$attr=str_replace('&lt;/br&gt;',',',$c['goods_attr']);
		$goods_info=M('Goods')->where('id='.$c['id'])->field(true)->find();

		if($c['price'] && !$c['defind_price']){
			$goods_info['shop_price']=$c['price'];
		}elseif($c['defind_price']){
			$goods_info['shop_price']=$c['defind_price'];
		}
		$arrt['goods_id']=$c['id'];
		$arrt['goods_sn']=$goods_info['goods_sn'];
		$arrt['order_id']=$c['order_id'];
		$arrt['goods_name']=$goods_info['goods_name'];
		$arrt['goods_number']=$c['number'];
		$arrt['goods_price']=$goods_info['shop_price']*$c['number'];
		$arrt['attr_price']=$goods_info['shop_price']*$c['number'];
		$arrt['goods_attr']=$attr;

		$arrt['shop_id']=$goods_info['shop_id'];	
		//print_r($arrt);exit;
		$a=M('OrderGoods')->add($arrt);
		$order_info=M('OrderInfo')->where('id='.$c['order_id'])->field('order_amount,goods_amount')->find();
		$order_arr['order_amount']=$order_info['order_amount']+$goods_info['shop_price'];
		$order_arr['goods_amount']=$order_info['goods_amount']+$goods_info['shop_price'];
		$order_arr['shop_id']=$goods_info['shop_id'];
		$b=M('OrderInfo')->where('id='.$c['order_id'])->save($order_arr);
		if($a && $b){
			$data['info']='添加成功！';
			$data['url']=U('Admin/OrderInfo/add_goods', array('id' =>$c['order_id'],'u_id'=>$c['u_id'],'shop_id'=>$c['shop_id']));
			$data['shop_id']=$goods_info['shop_id'];
			$this->ajaxReturn($data);
		}
	}
	public function add_order_goods_order(){
		$c=I('get.');
		//print_r($c['shop_id']);$this->ajaxReturn($c);
        $time=NOW_TIME;
		$attr=str_replace('&lt;/br&gt;',',',$c['goods_attr']);
		$where['id']=$c['id'];
		$goods_info=M('Goods')->where($where)->field(true)->find();

		if($c['price'] && !$c['defind_price']){
			$goods_info['shop_price']=$c['price'];
		}elseif($c['defind_price']){
			$goods_info['shop_price']=$c['defind_price'];
		}
		$arrt['goods_id']=$c['id'];
		$arrt['goods_sn']=$goods_info['goods_sn'];
		$arrt['order_id']=$c['order_id'];
		$arrt['goods_name']=$goods_info['goods_name'];
		$arrt['goods_number']=$c['number'];
		$arrt['goods_price']=$goods_info['shop_price']*$c['number'];
		$arrt['attr_price']=$goods_info['shop_price']*$c['number'];
		$arrt['goods_attr']=$attr;

		$arrt['shop_id']=$goods_info['shop_id'];	
		//print_r($arrt);exit;
		$a=M('OrderGoods')->add($arrt);
		if($a){
			$data['info']='添加成功！';
			$data['url']=U('Admin/OrderInfo/ordergoods', array('id' =>$c['order_id']));
			$this->ajaxReturn($data);
		}
	}
	public function save_order_goods(){
		$c=I('get.');
		//print_r($c);exit;
		$order_id=$c['order_id'];
		$shop_id=$c['shop_id'];
		$count=count($c['goods_id']);
        $arrts=array();
		for($i=0;$i<=$count;$i++){
			$arrt['attr_price']=$arrt['goods_price']=$c['goods_price'][$i];
			$arrt['goods_number']=$c['goods_number'][$i];
			$arrt['goods_attr']=$c['goods_attr'][$i];
			$goods_id=$c['goods_id'][$i];
			$a=M('OrderGoods')->where('order_id='.$order_id.' and goods_id='.$goods_id)->save($arrt);
			$arrts['goods_price']+=$c['goods_price'][$i];
		}
		$order_arr['order_amount']=$arrts['goods_price'];
		$order_arr['goods_amount']=$arrts['goods_price'];
		$b=M('OrderInfo')->where('id='.$order_id)->save($order_arr);
		$data['info']='更新成功！';
		$data['url']=U('Admin/OrderInfo/add_goods', array('id' =>$c['order_id'],'u_id'=>$c['u_id'],'shop_id'=>$shop_id));
		$this->ajaxReturn($data);
	}
	//会员搜索
	public function searchuser(){
		$like=I('get.like');
		//echo $like;exit;
		if($like){
            $whereor['mobile']=$like;
			/*$where['card_sn']=$like;
			$user=M('MemberCard')->where($where)->field('uid')->find();
			//print_r($user);exit;
			if($user){
				$whereor['id']=$user['uid'];	
			}*/
            //$whereor['_logic'] = 'or';
            $map['_complex'] = $whereor;
			$list=M('Member')->where($map)->field('id,username,status')->select();
			$result="<option>请选择该会员</option>";
			foreach($list as $k=>$v){
				if($v['status']==1){
					$result.="<option value='".$v['id']."'>".$v['username']."</option>";	
				}	
			}
        }
		echo $result;exit;
	}
	public function order_print(){
		$id = I('get.id');
		$template = 'CARGO_LIST';
		$price='';
		$order_info = M('OrderInfo')->where('id='.$id)->field(true)->find();
        if($order_info['pay_code']=='' && $order_info['pay_status']==3){
            $order_info['pay_code']='Hanchao';
        }
		$pay_name = M('Payment')->where("code='".$order_info['pay_code']."'")->field('name')->find();
		
		if($order_info['promot_id']){
            $act_ids = explode(',', $order_info['promot_id']);
            $act_ids=array_filter($act_ids);
            $promote_arr = D('Common/Takeout')->getpromote($act_ids,$id);
			$promote_money = array_sum(i_array_column($promote_arr,'money'));
        }
		$order_info['discount'] = $promote_money;
		$order_goods = M('OrderGoods')->where('order_id='.$id)->field(true)->select();
		foreach($order_goods as $ke=>$va){
            $attr=unserialize($va['goods_attr']);
            $order_goods[$ke]['attr_name']=$attr['name'];
            $order_goods[$ke]['goods_price_format']=format_price($va['goods_price']);
            $order_goods[$ke]['org_parce']=$va['goods_price']*$va['goods_number'];
            $price +=  $order_goods[$ke]['org_parce'];
            $order_goods[$ke]['org_parce_format']=format_price($order_goods[$ke]['org_parce']);
            $order_goods[$ke]['org_integral']=$va['goods_integral']*$va['goods_number'];
            $order_goods[$ke]['goods_number']=floatval($va['goods_number']);
		}
		$url = C('WEB_URL');
		$phone = C('WEB_SITE_PHONE');
		$name = C('WEB_SITE_TITLE');
		$admin = idtoname(UID,'admin','username');
		$time = date('Y-m-d H:i:s',NOW_TIME);
		$this->assign('url',$url);
		$this->assign('phone',$phone);
		$this->assign('name',$name);
		$this->assign('admin',$admin);
		$this->assign('print_time',$time);
		$this->assign('pay_name',$pay_name['name']);
		$this->assign('order_info',$order_info);
		$this->assign('price',$price);
		$this->assign('order_goods',$order_goods);
		if($template){
			$map = array();
			$map['code'] = $template;       
			$content = M('PrintTemplate')->where($map)->getField('content');
			$content1 = $this->fetch('',htmlspecialchars_decode($content));
			$this->assign('info',$content1);
		}
		$this->display();
    }
	public function store_shou(){
		$id = I('get.id');
		$where['id']=$id;
		$date['status']=6;
		$change=M('OrderInfo')->where($where)->save($date);
		if($change){
            $this->success('签收成功！',U('OrderInfo/index'));
        }else{
            $this->error('签收失败！',U('OrderInfo/index'));
        }
    }

    /**
     * 后台处理发货
     */
    public function deliver_goods(){
        $data=idtoname($data['order_id'],'OrderInfo','*');
        $data['order_id']=I('order_id');
        $data['notice_sn']=I('notice_sn');
        $data['send_type']=I('send_type');
        $data['order_type']=idtoname($data['order_id'],'OrderInfo','type','id');
        if(I('get_type')==1) {
            $location_id=I('locaion_id');
            if(empty($location_id)){
                $this->error('请选择附近仓库');
            }
            $data['take_location_id'] = I('locaion_id');
        }
        $data['type']='Admin';
		$data['admin_id']=UID;
        $result=D("Common/OrderInfo")->ship_goods($data);
        if($result['status']){
            $this->success($result['info'],geturl('Admin/OrderInfo/ship_print',array('id'=>$result['id'])));
        }else{
            $this->error($result['info']);
        }
    }
    public function manage(){
        $order_id=I('post.order_id');
		$content=I('post.content');
		$order=I('post.order');
		$store_id=I('post.store_id');
		$orderss=idtoname($order_id,'OrderInfo','*');
		if(empty($order_id))$this->error('参数不正确');
        $postdata=I('post.');
        if($postdata['localship'] && $postdata['code']){//自有配送修改状态            
            $apitype=$postdata['code'];
            if(empty($apitype)){$this->error('第三方类型错误');}
            $dis = new \Common\Vendor\Distribute($apitype);
            $accept_time=$fetch_time=$finish_time='';
            if($postdata['createTime'])$add_time=strtotime($postdata['createTime']);
            if($postdata['acceptTime'])$accept_time=strtotime($postdata['acceptTime']);
            if($postdata['fetchTime'])$fetch_time=strtotime($postdata['fetchTime']);
            if($postdata['finishTime'])$finish_time=strtotime($postdata['finishTime']);
            $input=array(
                'origin_id'=>$order_id,
                'client_id'=>$order_id,
                'order_code'=>$order_id,
                'order_sn'=>$order_id,
                'shipping_status'=>$postdata['statusMsg'],
                'add_time'=>$add_time,
                'accept_time'=>$accept_time,
                'fetch_time'=>$fetch_time,
                'finish_time'=>$finish_time,
                'knightname'=>$postdata['transporterName'],
                'knightphone'=>$postdata['transporterPhone'],
            );
            $result= $dis->notify_order($input);
            if($result['status']==1){
                $this->success('更新成功');
            }else{
                $this->error('更新失败');
            }
            return;
        }
        
        
        $mod=M('OrderInfo');
        if(I('post.confirm')){$log='确认';$data['confirm_time']=NOW_TIME;$data['status']='2';}
        if(I('post.pay')){
			$log='付款';
			$data['pay_time']=NOW_TIME;
			$data['pay_status']='3';
            if($data)$mod->where('id='.$order_id)->save($data);
            if(C('BUCKLE_STOCK')==1) {//            扣库存
                $kucun_re = D('Shop/OrderInfo')->lessstock($order_id);
                if ($kucun_re['status'] == 0) {
                    $return['msg'] = $kucun_re['info'];
                    $this->error($return['msg']);
                    exit;
                }//	扣库存结束
            }
            $discount = idtoname($order_id, 'OrderInfo', 'discount,first_money', 'id', false);
            D('Common/OrderInfo')->get_profit($order_id, $discount['discount'], $discount['first_money']);
            // 增加营业额
            $shop_unsettled = D('Common/OrderInfo')->shop_unbalance($order_id, 0);
            if (!$shop_unsettled) {
                $root['msg'] = "增加商户待结算金额失败";

                $this->error($root['msg']);exit;
            }

			//分成记录，待处理分成
			$ex=C('EXTENSION_SETTING');
			if($ex){$a=affiliate($order_id);}//print_r($a);exit;

		}
        if(I('post.unpay')){$log='设为未付款';$data['pay_time']=NOW_TIME;$data['pay_status']='1';}
        if(I('post.prepare')){$log='配送';}
        if(I('post.ship')){$log='发货';}
        if(I('post.unship')){$log='未发货';$data['shipping_status']='1';}
        if(I('post.receive')){$log='已收货';$data['status']='3';}
        if(I('post.return')){$log='退货';$data['status']='6';}
        if(I('post.cancel')){$log='取消';$data['status']='4';}
        if(I('post.invalid')){$log='无效';$data['status']='5';}
        if(I('post.after_service') && I('post.content')){$log='售后';}
        if(I('post.order_take')){$log='备货';$data['shipping_status']='5';}
        if(I('post.after_service')){
            $postdata['content']=$content;
            $postdata['order_id']=$order_id;
            $postdata['type']=2;
            if(empty($postdata['order_id'])){$this->error('参数错误');}
            if(empty($postdata['content'])){$this->error('请输入内容，以便我们及时解决您的问题');}
            $data = D('Common/Member')->submit_service($postdata);
            if($data['status']){
                $this->success($data['msg']);
            }else{
                $this->error($data['msg']);
            }exit();
        }

        if($log=='备货'){
            $param=array();$param['type']=14;
            if($orderss['type']==3)$param['type']=3;
			if($orderss['type']==6)$param['type']=6;
            
            $param['shipping_status']=5;
            $param['id']=$order_id;
            $return=D('Common/OrderInfo')->order_change($param);
            if($return['status']==1){
                $this->success('备货成功',U('OrderInfo/view',array('id'=>$order_id)));exit;
            }else{
                $this->error($return['msg']);exit;
            }
        }
        if($log=='配送' || I('post.code')){
            $param=array();$param['order_type']=14;
            if($orderss['type']==3)$param['order_type']=3;
			if($orderss['type']==6)$param['type']=6;
            $param['order_id']=$order_id;
            $param['type']='Admin';//店铺发货日志
            if(I('post.code')){
                $param['wuliu']=I('post.code');
            }
            $return=D('Common/OrderInfo')->ship_goods($param);
            if($return['status']==1){
                $this->order_manage($order_id);
                $this->success($return['info'],U('OrderInfo/view',array('id'=>$order_id)));exit;
            }else{
                $this->error($return['info']);exit;
            }
        }
		$user_info = M('OrderInfo')->where('id='.$order_id)->field('consignee,email')->find();
		if($log == '发货'){
            if(C('BUCKLE_STOCK')!=1){
                $kucun_re = D('Shop/OrderInfo')->lessstock($order_id);
                if ($kucun_re['status'] == 0) {
                    $this->error($kucun_re['info']);exit;
                }
            }
			$save['store_id']=$store_id;
			M('OrderInfo')->where('id='.$order_id)->save($save);
			$member=M('OrderInfo')->where('id='.$order_id)->field('uid,mobile')->find();
			if(!empty($member['uid'])){
				//echo 123;
				$moblie=M('Member')->where('id='.$member['uid'])->field('mobile')->find();
				//print_r($moblie);
				$phone=$moblie['mobile'];
				//echo $phone;
			}else{
				$phone=$member['mobile'];
			}
			//echo $phone;exit;
			$data['to']=$phone;   
        	$result=sendbytheme($data,'SEND_GOODS');
		}
		if($log == '已收货'){
			$postdata['order_id']=$order_id;
			$postdata['admin_id']=MID;
			$postdata['type']=='Admin';
			$return=D('Common/OrderInfo')->confirm_order($postdata);
            if($return['status'])$this->order_manage($order_id);
			if($return['status'] && $orderss['send_type'] !=1){
				$this->success($return['msg'],U('OrderInfo/view',array('id'=>$order_id)));exit;
			}elseif($return['status'] && $orderss['send_type'] ==1){
                $this->success($return['msg'],U('OrderInfo/zt_view',array('id'=>$order_id)));exit;
            }else{
				$this->error($return['msg']);exit;
			}
		}
        if($log=="退货"){
            $member_info=session('member_info');
                $order_info=M("OrderInfo")->where('id='.$order_id)->field(true)->find();
                    $money=$order_info['order_amount']-$order_info['delivery_fee'];
                    $info=M("OrderGoods")->where('order_id='.$order_id)->field('id,goods_id,goods_number')->select();
                    foreach($info as $k=>$v){
                        $goods_info[$k]['goods_id']=$v['goods_id'];
                        $goods_info[$k]['number']=$v['goods_number'];
                        //改变商品状态
                        $g_map['id']=$v['id'];
                        $g_map['status']=1;
                        $save['status']=3;
                        $res=M('OrderGoods')->where($g_map)->save($save);
                        $org_id[]=$v['id'];//要生成退货单 org_id
                    }

                $str_orgids=implode(',',$org_id);
                //添加退货单
                $add['org_id']=$str_orgids;
                $add['uid']=$member_info['id'];
                $add['shop_id']=$order_info['shop_id'];
                $add['order_id']=$order_id;
                $add['goods_info']=serialize($goods_info);
                $add['reason']=$content;
                $add['money']=$money;
                $add['add_time']=NOW_TIME;
                $res=M('ReturnGoods')->add($add);
                //生成退款单
                $refund_data['reason']=$content;
                $refund_data['type']=0;
                $refund_data['order_goods']=$str_orgids;
                $result=D("Common/OrderInfo")->add_refund($money,$order_id,$refund_data);
                if($result){
                    action_log('user_apply_return', 'Member', $res, $member_info['id']);
                    //$this->success("退货申请提交成功",U('OrderInfo/view',array('id'=>$order_id)));
                }//日志,$res退货单ID


        }
        if($log=='取消'){
            $postdata = array();
            $postdata['order_id']=$order_id;
            $postdata['admin_id']=MID;
            $postdata['type']=='Admin';
            $return = D("Common/OrderInfo")->cancel_order($postdata);

            if($return['status'] && $orderss['send_type'] !=1){
                $this->success($return['msg'],U('OrderInfo/view',array('id'=>$order_id)));exit;
            }elseif($return['status'] && $orderss['send_type'] ==1){
                $this->success($return['msg'],U('OrderInfo/zt_view',array('id'=>$order_id)));exit;
            }else{
                $this->error($return['msg']);exit;
            }
        }
        if($log){
            if($data && $log!='付款')$mod->where('id='.$order_id)->save($data);
			$where_oi['id']=$order_id;
			$orderinfo = M('OrderInfo')->where($where_oi)->find();
			if($orderinfo['shipping_status']==3){
				$where_og['order_id']=$order_id;
				$ordergoods = M('OrderGoods')->where($where_og)->select();
				foreach($ordergoods as $k=>$v){
					$where_g['id']=$v['goods_id'];
					$old_num = M('Goods')->where($where_g)->find();
					$con['goods_number']=$old_num['goods_number']-$v['goods_number'];
					$con['sell_count']=$old_num['sell_count']+$v['goods_number'];
					M('Goods')->where($where_g)->save($con);
				}
			}
            $log=$log.' '.I('post.content');
            action_log('manage_order', 'OrderInfo',$order_id,UID,$log);
            if($orderss['send_type'] !=1){
                $this->success(L('DO_OK'),U('OrderInfo/view',array('id'=>$order_id)));exit;
            }elseif($orderss['send_type'] ==1){
                $this->success(L('DO_OK'),U('OrderInfo/zt_view',array('id'=>$order_id)));exit;
            }
        }else{
            $this->error('参数不正确!');
        }
    }
    /**
    *更新第三方配送
    */
    public function order_manage($id){
        $return=array('status'=>'0','msg'=>'');
        $order_info=M('OrderInfo')->where('id='.$id)->field(true)->find();
        $apitype=$order_info['distribute'];
        if(empty($apitype))return $return;
        if($apitype=='Dada' || $apitype=='Meituan')$order_id=$order_sn=$order_info['order_sn'];
        if($apitype=='Local'){
            $map=array();
            $map['order_sn']=$order_info['order_sn'];
            $order_sn=M('LocalOrder')->where($map)->getField('origin_id');
            $order_id=$order_info['order_sn'];
        }
        $dis = new \Common\Vendor\Distribute($apitype);
        $input=array(
            'origin_id'=>$order_sn,
            'client_id'=>$order_id,
            'order_code'=>$order_id,
            'order_sn'=>$order_id,
            'shipping_status'=>$order_info['shipping_status'],
            'finish_time'=>NOW_TIME,
        );
        $result= $dis->notify_order($input);
        if($result['status']==1){
            $return['status']=1;
        }
        return $return;
    }
    /* 订货订单处理 */
    public function pmanage(){
        $order_id=I('post.order_id');
        $content=I('post.content');
         $order=I('post.order');
        $orderss=idtoname($order_id,'OrderInfo','*');
        if(empty($order_id))$this->error('参数不正确');
        $mod=M('OrderInfo');
        if(I('post.confirm')){$log='确认';$data['confirm_time']=NOW_TIME;$data['status']='2';}
        if(I('post.pay')){
            $log='付款';
            $data['pay_time']=NOW_TIME;
            $data['pay_status']='3';
            $data['status']='2';
            //供货商待结算金额
            $shop_map['id']=$orderss['shop_id'];
             // 获取结算价
            $price_info=get_balance_suprice($order_id);
            $all_supplymoney=$price_info['price'];
            $old_total_revenues=idtoname($shop_map['id'],'Suppliers','total_revenues');
            $old_unbalance=idtoname($shop_map['id'],'Suppliers','unbalance');
            $order_info['id']=$order_id;
            $shop_where['id']=$shop_map['id'];
            $con_data['total_revenues']=$old_total_revenues+$all_supplymoney;
            $con_data['unbalance']=$old_unbalance+$all_supplymoney;
            $up_shop=M('Suppliers')->where($shop_where)->save($con_data);
            supplier_balance_log($shop_map['id'], $price_info['price'], 2,3,$orderss['order_sn'] . '订单付款,未结算总额增加', $orderss);
            supplier_balance_log($shop_map['id'], $price_info['price'], 5,3,$orderss['order_sn'] . '订单付款,销售总额增加', $orderss);
           
        }
        if(I('post.unpay')){$log='设为未付款';$data['pay_time']=NOW_TIME;$data['pay_status']='1';}
        if(I('post.prepare')){$log='配货';$data['shipping_status']='2';}
        if(I('post.ship')){$log='发货';$data['shipping_time']=NOW_TIME;$data['shipping_status']='3';}
        if(I('post.unship')){$log='未发货';$data['shipping_status']='1';}
        if(I('post.receive')){$log='已收货';$data['status']='3';}
        if(I('post.return')){$log='退货';$data['status']='6';}
        if(I('post.cancel')){$log='取消';$data['status']='4';}
        if(I('post.invalid')){$log='无效';$data['status']='5';}
        if(I('post.after_service') && I('post.content')){$log='售后';}
        $user_info = M('OrderInfo')->where('id='.$order_id)->field('consignee,email')->find();
        //print_r($user_info);exit;
        if($log == '发货'){
            $member=M('OrderInfo')->where('id='.$order_id)->field('uid,mobile')->find();
            if(!empty($member['uid'])){
                $moblie=M('Shops')->where('id='.$member['uid'])->field('phone')->find();
                $phone=$moblie['phone'];
            }else{
                $phone=$member['mobile'];
            }
            $data['to']=$phone;   
            $result=sendbytheme($data,'SEND_GOODS');
        }
        if($log == '已收货'){
            $postdata['order_id']=$order_id;
            $postdata['admin_id']=MID;
            $postdata['type']=='Admin';
            $postdata['og_id']=I('post.og_id');
            $postdata['number']=I('post.number');
            $return=D('Common/OrderInfo')->pconfirm_order($postdata);
            if($return['status']){
                // $this->success($return['msg']);exit;
            }else{
                $this->error($return['msg']);exit;
            }
        }
        if($log=="退货"){
                $order_info=M("OrderInfo")->where('id='.$order_id)->field(true)->find();
                $money=$order_info['order_amount']-$order_info['delivery_fee'];
                $info=M("OrderGoods")->where('order_id='.$order_id)->field('id,goods_id,goods_number')->select();
                foreach($info as $k=>$v){
                    $goods_info[$k]['goods_id']=$v['goods_id'];
                    $goods_info[$k]['number']=$v['goods_number'];
                    //改变商品状态
                    $g_map['id']=$v['id'];
                    $g_map['status']=1;
                    $save['status']=3;
                    $res=M('OrderGoods')->where($g_map)->save($save);
                    $org_id[]=$v['id'];//要生成退货单 org_id
                }

                $str_orgids=implode(',',$org_id);
                //添加退货单
                $add['org_id']=$str_orgids;
                $add['uid']=$order_info['uid'];
                $add['shop_id']=$order_info['shop_id'];
                $add['order_id']=$order_id;
                $add['goods_info']=serialize($goods_info);
                $add['reason']=$content;
                $add['money']=$money;
                $add['add_time']=NOW_TIME;
                $add['type']=1;
                $res=M('ReturnGoods')->add($add);
                //生成退款单
                $refund_data['reason']=$content;
                $refund_data['type']=0;
                $refund_data['order_goods']=$str_orgids;
                $result=D("Common/OrderInfo")->add_refund($money,$order_id,$refund_data);
                if($result){
                    action_log('shop_apply_return', 'Shop', $res, $order_info['uid']);
                    //$this->success("退货申请提交成功",U('OrderInfo/view',array('id'=>$order_id)));
                }//日志,$res退货单ID


        }
        if($log){
            if($data)$mod->where('id='.$order_id)->save($data);
            $where_oi['id']=$order_id;
            $orderinfo = M('OrderInfo')->where($where_oi)->find();
            if($orderinfo['shipping_status']==3){
                $where_og['order_id']=$order_id;
                $ordergoods = M('OrderGoods')->where($where_og)->select();
                foreach($ordergoods as $k=>$v){
                    $where_g['id']=$v['goods_id'];
                    $old_num = M('Goods')->where($where_g)->find();
                    $con['goods_number']=$old_num['goods_number']-$v['goods_number'];
                    $con['sell_count']=$old_num['sell_count']+$v['goods_number'];
                    M('Goods')->where($where_g)->save($con);
                }
            }
            $log=$log.' '.I('post.content');
            action_log('manage_order', 'OrderInfo',$order_id,UID,$log);
            $this->success(L('DO_OK'),U('OrderInfo/pview',array('id'=>$order_id)));
        }else{
            $this->error('参数不正确!');
        }
    }
    /* 得到节点树 */
	private function getNodeTree($pid = '') {
	   //支付方式
       $payment_select=M('Payment')->where(array('status'=>array('egt',0)))->field('code,name')->order('sort,id desc')->select();
       foreach($payment_select as $v){$payment[$v['code']]=$v['name'];}
       //配送方式
       $shipping_select=M('Shipping')->where(array('status'=>array('egt',0)))->field('id,name')->order('sort,id desc')->select();
       foreach($shipping_select as $v){$shipping[$v['id']]=$v['name'];}
       $this->assign('payment',$payment);
       $this->assign('shipping',$shipping);
       unset($payment_select,$payment,$shipping_select,$shipping);
	}
	/**
	 * 返回某个订单可执行的操作列表，包括权限判断
	 * @param   array   $order      订单信息 order_status, shipping_status, pay_status
	 * @param   bool    $is_cod     支付方式是否货到付款
	 * @return  array   可执行的操作  confirm, pay, unpay, prepare, ship, unship, receive, cancel, invalid, return, drop
	 * 格式 array('confirm' => true, 'pay' => true)
	 */
	public function operable_list($orderid){
		$order=M('OrderInfo')->field('status,shipping_status,pay_status,pay_code,send_type,check_status')->find($orderid);
		$os = $order['status'];$ss = $order['shipping_status'];$ps = $order['pay_status'];
		$priv_list  = array('os'=> true,'ss'=>true,'ps'=>true,'edit'=>true);/* 取得订单操作权限 */ 
		if($order['pay_code']=='HANCHAObank')$is_cod= $payment = 1;   
		//return $payment; /* 取得订单支付方式是否货到付款 */
		$list = array();/* 根据状态返回可执行操作 */
		if (1 == $os){//未确认
			if ($priv_list['os']){/* 状态：未确认 => 未付款、未发货 */
				$list['confirm']= true; /*确认*/$list['invalid']= true;/* 无效*/$list['cancel']= true; /* 取消*/
				if ($is_cod){if ($priv_list['ss']){$list['prepare'] = true; }// 货到付款  配货
				}else{if ($priv_list['ps']) { $list['pay'] = true;}}  // 不是货到付款 付款
			}
		}elseif (2 == $os ){//已确认
			if (1 == $ps){/* 状态：已确认 未付款*/
				if ((1 == $ss || 2 == $ss) && $order['send_type'] !=2){$list['ship'] = true;/* 状态：已确认、未付款 未发货/备货中*/
					if ($priv_list['os']){$list['cancel'] = true; /*取消*/$list['invalid'] = true;} // 无效                
                    //if ($is_cod){if ($priv_list['ss'] && 1 == $ss){$list['prepare'] = true;}} // 货到付款 配货
					else if ($priv_list['ps']){$list['pay'] = true;}// 不是货到付款 付款
				}else{
					if ($priv_list['ps']){$list['pay'] = true;} /* 状态：已确认、未付款、已发货或已收货 => 货到付款 */       
					if ($priv_list['ss']){if (3 == $ss){$list['receive'] = true;}} /*收货确认*/
                    if ($priv_list['os']){$list['return'] = true;} /*退货*/
                    if($order['send_type'] ==0 || $order['send_type'] ==3){$list['unship'] = true;} // 设为未发货
				}
			}else{
				if (1 == $ss || 2 == $ss){
                    if($order['send_type']!=1 && $order['send_type']!=2){
                        $list['ship'] = true;
                    }/* 状态：已确认、已付款和付款中、未发货（配货中） => 不是货到付款 */
                    $list['order_take'] = true;
                    //	if ($priv_list['ss'] && 1 == $ss && $order['send_type'] != 3){$list['prepare'] = true;} // 配货
					if ($priv_list['ps']){$list['unpay'] = true; /* 设为未付款*/if ($priv_list['os']){$list['cancel'] = true;} } // 取消                    
				}else{/* 状态：已确认、已付款和付款中、已发货或已收货 */
                    if($order['send_type']==1 && 5 != $ss){
                        $list['order_take'] = true;
                    }
					if ($priv_list['ss']){
                        if (3 == $ss){

                            if($order['send_type']==1 && $order['check_status']==0){
                                $list['receive'] = true;
                            }else{
                                $list['receive'] = true;
                            }
                        }elseif(5 == $ss && $order['send_type']==1){
                            $list['receive'] = true;
                        }
                        /*收货确认*/
                        if (!$is_cod && $order['send_type']!=1 && $order['send_type']!=2 && $priv_list['ss'] != 5){$list['unship'] = true;}
                    } // 设为未发货
                    if ($priv_list['ss'] && 5 == $ss && $order['send_type']==2){$list['prepare'] = true;} // 配货
                    if ($priv_list['ss'] && 5 == $ss && $order['send_type']==3){$list['ship'] = true;} /* 状态：已确认、已付款和付款中、未发货（配货中） => 不是货到付款 */
					if ($priv_list['ps'] && $is_cod){$list['unpay']  = true;} // 设为未付款                
					if ($priv_list['os'] && $priv_list['ss'] && $priv_list['ps'] && $order['send_type']!=1){$list['return'] = true;} // 退货（包括退款）
                    if ($order['send_type']==1){$list['cancel'] = true;/*取消*/$list['invalid'] = true;} // 无效
				}
			}
		}elseif (4 == $os){//已取消
        //if($priv_list['os']){$list['confirm'] = true;}
            if($priv_list['edit']){$list['remove'] = true;}
		}elseif (5 == $os){/* 状态：无效 */
			if($priv_list['os']){$list['confirm'] = true;}if($priv_list['edit']){$list['remove'] = true;}
		}elseif (6 == $os && $priv_list['os']){/*退货 */  
			$list['confirm']=true;
		}
		if($is_cod && $priv_list['ps']){$list['pay']=true;} 
		//$list['payment']= $order['pay_code'];
		$list['after_service'] = true;/* 售后 */
		return $list;
		//return $payment;
    }
    public function ship(){
        $id=I('id');if(empty($id))$this->error('参数不正确');
		$ordergoods=M('OrderGoods')->where('order_id='.$id)->select();
		foreach($ordergoods as $k=>$v){
			$attr=unserialize($v['goods_attr']);
			$ordergoods[$k]['attr_name']=$attr['name'];
			$ordergoods[$k]['org_parce']=$v['goods_price']*$v['goods_number'];
            $ordergoods[$k]['goods_number']=floatval($v['goods_number']);
		}
        $this->assign('ordergoods',$ordergoods);
        $order_info=M('OrderInfo')->where('id='.$id)->find();
        $this->assign($order_info);
        $shipping_list=M('Shipping')->where('status=1')->field('code,name')->select();
        foreach($shipping_list as $k=>$v){
            $shipping_info[$v['code']]=$v['name'];
        }
        $this->assign('shipping',$shipping_info);
        //店铺
        $shop_info=D("Shops")->get_shops_info($order_info['uid']);
        foreach($shop_info as $k=>$v){
            $shop_infos[$v['id']]=$v['name'];
        }
        $this->assign('shop_info',$shop_infos);
        if($order_info['type']==10){
            $this->display ('pship');
        }else{
            $this->display ();
        }
    }
    /**
     * 配货
     */
    public function distribution(){
        $id=I('order_id');
        $store_id=I('store_id');
        if(empty($id) || empty($store_id)){
            $return['status']=0;
            $return['msg']='参数错误！';
            $this->ajaxReturn($return);
        }
        $g_map=array();
        $g_map['order_id']=$id;
        $order_goods=M("OrderGoods")->where($g_map)->getField('goods_id',true);
        foreach($order_goods as $key=>$val){
            $s_map=array();
            $s_map['goods_id']=$val;
            $s_map['storage_id']=$store_id;
            $count=M("StorageStock")->where($s_map)->getField('stock');
            if($count<=0){
                $return['status']=0;
                $return['msg']='该仓库商品库存不足';
                $this->ajaxReturn($return);
            }
        }
        $map=$data=$return=array();
        $map['id']=$id;
        $data['storage_id']=$store_id;
        $data['shipping_status']=5;
        $info=M("OrderInfo")->where($map)->save($data);
        if($info){
            $return['status']=1;
            $return['msg']='配货成功！';
        }else{
            $return['status']=0;
            $return['msg']='配货失败！';
        }
        $this->ajaxReturn($return);
    }
    /**
     * 删除，回收站
     * @param $is_delete 0恢复,1删除
     */
    public function recycling()
    {exit();
        $name = 'OrderInfo';
        $postdata = I('post.');
        $id = I('get.id');
        if (empty($postdata['id']) && !empty($id)) $postdata['id'][] = $id;
        $is_delete = I('is_delete');
        if (empty($postdata['id'])) {
            if ($is_delete == 1) $this->error(L('PLEASE_SELECT_DELETE_GOODS'));
            else $this->error('请选择要恢复的订单！');
        }
        $where['is_delete'] = $is_delete;
        foreach ($postdata['id'] as $key => $value) {
            $map['id'] = $value;
            $g_info = M($name)->where($map)->save($where);
        }
        if ($is_delete == 1) {
            if (isset($g_info)) {
                $this->success(L('HAVE_PUT_IN_RECYCLE'));
            } else {
                $this->error(L('DELETE_FAILED'));
            }
        } else {
            if (isset($g_info)) {
                $this->success(L('RECOVER_SUCCESS'));
            } else {
                $this->error(L('RECOVER_FAILED'));
            }
        }
    }
    //快递点打印
	public function ship_print(){
		$id = I('get.id','','intval');
		$test = I('get.test','0','intval');
        $res=D('Shop/Shipping')->ship_print($id);
        if($res['status']){
            $this->assign($res['info']);
        }else{
            $this->error($res['info']);exit;
        }
        $this->assign('test',$test);
		$this->display();
    }
    /**
     *选择物流
     */
    public function order_take(){
        if(C("DIS_TRIBUTE") == 0)return;
        $id = I('get.id');
        $distribute = M('Distribute')->field("name,code")->where(array('status'=>1))->cache(true)->select();
        $this->assign('id',$id);
        $this->assign('distribute',$distribute);
        $this->display('order_take');
    }
	//打印小票
	public function receipt_print(){
		$id = I('get.id','','intval');
		if(empty($id)){$this->error('参数错误！');}
		$print_type=C("PRINT_TYPE");
		$map = array();
		$map['id'] = $id;
		$order_info = M('OrderInfo')->where($map)->field(true)->find();
		if($order_info){
			$map = array();
			$map['id'] = $order_info['sa_id'];
			$cashier = M('ShopsAccount')->where($map)->getField('name');
			$map = array();
			$map['id'] = $order_info['uid'];
			$member_info = M('Member')->where($map)->field('code,usepoints')->find();
			$map = array();
			$map['id'] = array('in',$order_info['promot_id']);
			$dis_way = M('PromotAct')->where($map)->getField('act_name',true);
			$promot_names = implode(",",$dis_way);
			$zero = 0;
			$map = array();
			$map['order_id'] = $id;
			$order_goods_arr = M('OrderGoods')->where($map)->field('goods_name,goods_price,goods_number,goods_price*goods_number as all_price')->select();
			$order_goods = array();
			foreach($order_goods_arr as $k => $v){
				if($v['all_price']){
					$v['all_price'] = format_price($v['all_price']);
				}
                $v['goods_number'] = floatval($v['goods_number']);
                $order_goods[$k] = $v;
			}
			$map = array();
			$map['change_desc'] = array('like','%'.$order_info['order_sn'].'参与会员等级特权活动赠送%');
			$integral_num1 = M('AccountLog')->where($map)->getField('change_num');
			if($integral_num1){
				$integral_num1 = intval($integral_num1);
			}else{
				$integral_num1 = 0;
			}
			$map = array();
			$map['change_desc'] = array('like','%'.$order_info['order_sn'].'消费赠积分%');
			$integral_num2 = M('AccountLog')->where($map)->getField('change_num');
			if($integral_num2){
				$integral_num2 = intval($integral_num2);
			}else{
				$integral_num2 = 0;
			}
			$integral = $integral_num1+$integral_num2;
			
			if($order_info['promot_id']){
				$act_ids = explode(',', $order_info['promot_id']);
				$act_ids=array_filter($act_ids);
				$promote_arr = D('Common/Takeout')->getpromote($act_ids,$id);
				$promote_money = array_sum(i_array_column($promote_arr,'money'));
			}
			$order_info['discount'] = $promote_money;
		}
		
		$map = array();
		$map['is_select'] = 1;
		$map['status'] = 1;
		$map['id'] = array('gt',0);
		$info = M('TplReceipt')->where($map)->field(true)->find();
		if($info){
			$tpl = json_decode($info['tpl_info'],true);
			if(!empty($info['set_info'])){
				$set = json_decode($info['set_info'],true);
				foreach($tpl as $k => $v){
					if($set['is_show'] == 0){
						if($v['type'] == 'qrcode'){
							unset($tpl[$k]);
						}
					}
				}
			}
            if($print_type==1){
                $print = new \Common\Vendor\Printtpl('Yilianyun');
            }elseif($print_type==0){
                $print = new \Common\Vendor\Printtpl('Local');
            }
		}else{
			$this->error('小票模板错误！');
		}
        $line="";
        if(!empty($order_goods)) $line="--------------------------------";
        /*支付方式支付金额统计start*/
        if($order_info['cash_money']>0){
            $cash_in_hand=$order_info['cash_in_hand'];
            $cash_money=$order_info['cash_money'];
            $back_money=$order_info['back_money'];
        }
        if($order_info['scan_money']>0){
            if($order_info['assist_code']=='HANCHAO_S_WEIXIN') $weixin_money=$order_info['scan_money'];
            if($order_info['assist_code']=='HANCHAO_S_ALIPAY') $alipay_money=$order_info['scan_money'];
        }
        if($order_info['bank_money']>0) $bank_money=$order_info['bank_money'];
        if($order_info['card_money']>0) $card_money=$order_info['card_money'];
        if($order_info['used_money']>0) $used_money=$order_info['used_money'];
        if($set['is_yue']==1) $user_money=$member_info['money']?$member_info['money']:'0.00';
        else $user_money='';
        /*支付方式支付金额统计end*/
        $qrcode_url='';
		$data = array(
            'shopname'=>$set['shopname'],
            'ordersn'=>$order_info['order_sn'],
            'cashier'=>$cashier,
			'goodslist'=>$order_goods,
            'zongji'=>$order_info['goods_allmoney'],
            'dis_way'=>$promot_names,
            //'discount'=>format_price($order_info['discount']),
            'firstmoney'=>$order_info['first_money'],
            'scoremoney'=>$order_info['used_score_money'],
            'bonusmoney' => $order_info['bonus_money'],//代金券优惠金额
            'customdiscount'=>$order_info['custom_discount'],
            'zero'=>format_price($zero),
            'w_money'=>$order_info['order_amount'],
            'cashinhand' => $cash_in_hand,//现金实际支付金额
            'cashmoney' => $cash_money,//现金应支付金额
            'backmoney' => $back_money,//找零
            'weixinmoney' => $weixin_money,//微信支付金额
            'alipaymoney' => $alipay_money,//支付宝支付金额
            'bankmoney' => $bank_money,//台卡支付金额
            'cardmoney' => $card_money,//刷卡支付金额
            'usedmoney' => $used_money,//余额支付金额
            'temp' => $order_info['temp'] ? $order_info['temp'] : "",
            'addtime' => time_format(empty($order_info['confirm_time'])?$order_info['addtime']:$order_info['confirm_time']),
            'mobile'=>$order_info['mobile'],
            'card_num'=>$member_info['code'],
            'lunch_box_price'=>$order_info['lunch_box_price'],
            'delivery_fee'=>$order_info['delivery_fee'],
            'integral'=>$integral,
            'sum_integral'=>$member_info['usepoints'],
            'bottom_temp' => $set['temp'] ? $set['temp'] : '',
            'qrcode_url'=>$qrcode_url,
            'line'=>$line,
        );
        $text = $print->fetch($tpl,$data);
        if($print_type==1){
            $print_sn=C("PRINT_SN");
            if (empty($print_sn)) {
                $this->error('添加打印机终端号!');
            }
            $print = doPrint($print_sn, $text, $order_info['order_sn']);
            $print['status'] = $print['status'] == 0 ? 3 : $print['status'];
            $print['msg'] = empty($print['msg']) ? $print['info'] : $print['msg'];
        }
		// echo $text;exit;
		$this->assign('text',$text);
		$this->display();
    }
/**
* 退货页面
*/
    public function tui_huo(){
        $order_id=I("order_id");
        $og_id=I("order_goods");
        $this->assign("order_id",$order_id);
        $map=array();
        $map['id']=$og_id;
        $order_goods = M('OrderGoods')->where($map)->field('id,goods_number,goods_price')->find();
        $this->assign('money',($order_goods['goods_number']*$order_goods['goods_price']));
        $this->assign($order_goods);
        $this->assign('types','退货');
        $this->display();
    }
/**
* 退货审核操作
*/
    public function check_tui(){
        $data=I("post.");
        $return=D('Common/OrderInfo')->check_tui($data);
        $this->ajaxReturn($return);
    }
}