<?php
if(!defined('APP_PATH')||!defined('I_PATH')){exit('Access Denied');}

class ld_order extends controllerBase
{
	function __construct(){
		parent::__construct();
		$this->a=$this->sysParams('a',1);
		$this->gopage=$this->sysParams('page',0,1);		
    	$this->orderStatus = array('1'=>'已下单','8'=>'已发货');
	}
	
    
    
    function index()
    {
    	$this->toptxt = '订单管理';
    	
    	$this->orderlist = syDB('order')->syPager($this->gopage,15)->findAll(' status>0','id desc');
    	$this->pages = pagetxt(syDB('order')->syPager()->getPager());    	
    	
    	$this->display("order_agent.html");
    } 
    
    function modify_order()
    {
    	if(!$orderid= $this->sysParams('orderid',1))
    	{
    		message_a("参数不完整",'/admin.php?c=ld_order');
    	}
    	$status=$this->sysParams('status',1);
    	$fields=array('status'=>$status);
    	$model=	syDB('order');
    	$model->update('id='.$orderid, $fields);
    	message_a('修改状态成功', '/admin.php?c=ld_order&a=ordershow&orderid='.$orderid);
    }
    //订单详情
    function ordershow()
    {	
    	if(!$this->sysParams('orderid',1))
    	{
    		message_a("参数不完整" ,'/admin.php?c=ld_order&a=ordershow&orderid='.$orderid);
    	}
    	$this->toptxt = '订单详情';
    	$condition = array('id'=>$this->sysParams('orderid',1));
    	
    	$sql = "select orders.*,product.title,product.litpic,detail.pid,detail.price,detail.number from ld_order orders left join
				ld_order_detail detail on orders.id=detail.order_id
				left join ld_product product on product.id=detail.pid
				where orders.id='{$condition['id']}' and status > 0 and product.id > 0 order by orders.id desc limit 0,3";
    	$data = getlistData ( "order", " id='{$condition['id']}' ", $sql );
		$this->ordershow = $data ['list'];
    	$orderuid = array('id'=>$this->ordershow['mid']);
    	$this->orderUserMessage = syDB('member')->find($orderuid);

    	
    	
    
    	
    	$this->display("order_show.html");
    }
}