<?php
/**
 * 直营发货单
 * @Copyright (C) 2016 汉潮 All rights reserved.
 * @License http://www.hanchao9999.com
 * @Author zhao <xiaogg@sina.cn>
 */
 
namespace Admin\Controller;
class ShipGoodsOrderController extends BaseController{
    public function _initialize() {
        parent::_initialize();
    } 
    public function index(){
        $name = "ShipOrder";
        $map=array();
        $map['type']=1;
		$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;
		}
		if(!empty($postdata['time_form']))$map['ship_time'][]=array('egt',strtotime($postdata['time_form']));
		if(!empty($postdata['time_to']))$map['ship_time'][]=array('elt',strtotime($postdata['time_to']));
		$list = $this->lists($name,$map);
		if($list){
			foreach($list as $k=>$v){
				$goods_ids=explode(',',$v['goods_id']);
				$str='';
				foreach($goods_ids as $ke=>$vo){
					if($ke!=0){
						$goods_name="&nbsp;&nbsp;|&nbsp;&nbsp;".idtoname($vo,'Goods','goods_name');
					}else{
						$goods_name=idtoname($vo,'Goods','goods_name');
					}
					$str.=$goods_name;
				}
				$list[$k]['goods_list']=$goods_ids;
				$list[$k]['str']=$str;
			}
		}
        $this->assign('list',$list);$this->assign($postdata);
        $this->display();
    }
	/**
	 * 修改发货单弹窗
	 */
    public function edit(){
		$id=I('id');
		$info=M('ShipOrder')->where('id='.$id)->field('id,order_id,notice_sn,remark,send_type,express_id')->find();
		$this->assign($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);
        $this->display();
    }
	/**
	 * 修改发货单
	 */
    public function edit_ship(){
		$return=array('status'=>0,'msg'=>'');
		$postdata=I('param.');
		$id=$postdata['id'];
		if(!$id){$return['msg']='参数错误';$this->ajaxReturn($return);}
		
        $map['id']=$id;
		$save['send_type']=$postdata['send_type'];
		$save['notice_sn']=$postdata['notice_sn'];
		$save['remark']=$postdata['remark'];
		$res=M('ShipOrder')->where($map)->save($save);
		if($res===false){
			$return['msg']='修改失败';$this->ajaxReturn($return);
		}else{
			$return['status']=1;
			$return['msg']='修改成功';
		}
		$this->ajaxReturn($return);
    }
}