<?php
/**
 * [LJCMS] (C)2012-2099 LJdev,Inc.
 * <E-Mail：aspcms@qq.com>
 * Url http://www.liangjing.org
 *     http://www.8CMS.com
 * Update 2014.04.03
*/

class control extends salebase {

    
    public function action_index(){
        $searchsql = " AND status not in ('待付款')";
        $model = parent::model('order', 'sa');
        list($total, $data) = $model->getList(array('page'=>$this->page, 'pagesize'=>$this->pagesize, 'searchsql'=>$searchsql));
        $url = XRequest::getPhpSelf();
        $url .= '?c=htmllabel';
        $var_array = array(
            'page'=>$this->page,
            'nextpage'=>$this->page+1,
            'prepage'=>$this->page-1,
            'pagecount'=>ceil($total/$this->pagesize),
            'pagesize'=>$this->pagesize,
            'total'=>$total,
            'showpage'=>XPage::admin($total, $this->pagesize, $this->page, $url, 10),
            'product'=>$data,
        );
        unset($model);
        TPL::assign($var_array);
        TPL::display($this->cptpl.'salesorder/index.tpl');
    }

    public function action_out()
    {
        $id=$_GET['id'];
        $model = parent::model('product', 'im');
        $data = $model->getorderinfo($id);
        unset($model);
        if (empty($data)) {
            XHandle::halt('对不起，读取数据不存在！', '', 1);
        } else {
            $var_array = array(
                'data'=>$data,
            );
            TPL::assign($var_array);
            TPL::display($this->cptpl.'salesorder/out.tpl');
        }
    }

    public function action_doOut()
    {
        $id=$_REQUEST['id'];
        $data['code']=1;
        if($id==''){
            $data['msg']="ID丢失，请正确操作";
        }
       
        $coompany=$_REQUEST['company'];
        if($coompany==''){
            $data['msg']="物流公司不能为空";
        }
        $wuliunum=$_REQUEST['wuliunum'];
        if($wuliunum==''){
            $data['msg']="物流单号不能为空";
        }
        $args['expresscompany']=$coompany;
        $args['expressnum']=$wuliunum;
        $args['status']='已发货';
        $args1['goodsname'] = $_REQUEST['goodsname'];
        $args1['goodsnum'] = $_REQUEST['goodsnum'];

        $model = parent::model('product', 'im');
        $result = $model->doEditInfo($id, $args, $args1);

        if (true === $result) {
            $data['code']=1;
            $data['msg']="修改成功";
        } else {
             $data['msg']="修改失败";
        }
        unset($model);



        echo json_encode($data);


    }

}