<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;
use Think\DB;
class OrderController extends Controller {
public $pay_status;
public $shipping_status;
public $order_status;
public function __construct(){
parent::__construct();
$pay_status=C('pay_status');
$shipping_status=C('shipping_status');
$order_status=C('order_status');
$this->assign('pay_status',$pay_status);
$this->assign('shipping_status',$shipping_status);
$this->assign('order_status',$order_status);
}
public function orderlist(){
$where = '1=1';
$time_start=strtotime(I('time_start'));
$time_end=strtotime(I('time_end'));
if($time_start && $time_end){
}
I('pay_code') && $where="$where and pay_code=".I('pay_code');
I('pay_status') && $where="$where and pay_status=".I('pay_status');
I('shipping_status') && $where="$where and shipping_status=".I('shipping_status');
I('order_status') && $where="$where and order_status=".I('order_status');
$count=D('order')->where($where)->count();
$page=new \Think\Page($count,25);
$show=$page->show();
$order=D('order')->where($where)->limit($page->firstRow.','.$page->listRows)->select();
$this->assign('page',$show);
$this->assign('count',$count);
$this->assign('order',$order);
$this->display();
}
public function detail($order_id){
if(IS_AJAX){
}
$order_info=M('order')->where('order_id='.$order_id)->find();
$user_id=$order_info['user_id'];
$user_action=M('order_action')
->join('user on order_action.action_user=user.user_id')
->where('order_id='.$order_id)
->select();
$this->assign('user_action',$user_action);
$this->assign('detail',D('order')->where('order_id='.I('order_id'))->find());
$this->assign('order_goods',M('order_goods')->where('order_id='.I('order_id'))->select());
$this->assign('order_action',$user_action);
$this->display();
}
public function orderadd(){
$order = [];
$order['province'] = I('parent_id');
$order['city']=I('city');
$order['county']=I('county');
$province=D('region')->where(['parent_id'=>'0','level'=>'1'])->select();
$city=D('region')->where([['parent_id'=>$order['province']],['level'=>'2']])->select();
foreach($city as $value){
echo "<option value='{$value['id']}'>{$value['name']}</option>";
}
$shipping=D('plugin')->where( ['type'=>'shipping'],['status'=>'1'])->select();
$payment=D('plugin')->where([['type'=>'payment'],['status'=>'1']])->select();
if(IS_POST){
$order['user_id'] = I('mobile');
$order['consignee'] = I('consignee');
$order['mobile'] = I('mobile');
$order['province'] = I('province');
$order['city'] = I('city');
$order['county'] = I('county');
$order['shipping_code'] = I('shipping_code');
$order['pay_code'] = I('pay_code');
$order['pay_name'] = I('pay_name');
$order['invoice_title'] = I('invoice_title');
$order['admin_note'] = I('admin_note');
print_r($order);
}
$this->assign('shipping',$shipping);
$this->assign('payment',$payment);
$this->assign('province',$province);
$this->assign('city',$city);
$this->display();
}
public function orderdel($order_id){
$order_del=D('order')->where('order_id='.$order_id)->delete();
if($order_del){
$this->ajaxReturn(['status'=>'1','msg'=>'删除成功']);
}else{
$this->ajaxReturn(['status'=>'0','msg'=>'删除失败']);
}
}
public function order_log(){
$where=[];
$where= "1=1";
$order_id=trim(I('order_id'));
$order_id && $where.= " and order_id like '%$order_id%' ";
$begintime=strtotime(I('begintime'));
$endtime=strtotime(I('endtime'));
if($begintime && $endtime){
$where['log_time']=['between',"$begintime,$endtime"];
}
$count=D('order_action')->where($where)->count();
$Page=new Page($count,25);
$show=$Page->show();
$order_action=D('order_action')
->order(['log_time'=>desc])
->where($where)
->limit($Page->firstRow.','.$Page->listRows)
->select();
$this->assign('count',$count);
$this->assign('page',$show);
$this->assign('order_action',$order_action);
$admin=M('admin')->getField('admin_id,user_name');
$this->assign('admin',$admin);
$this->display();
}
public function order_log_del(){
$order_log = M('order_action')->where('order_id='.I('order_id'))->delete();
if($order_log){
$this->ajaxReturn(['status'=>1,'msg'=>'删除成功']);
}else{
$this->ajaxReturn(['status'=>0,'msg'=>'删除失败']);
}
}
public function order_print(){
$order_goods=M('order_goods')->where('order_id='.I('order_id'))->select();
$this->assign('order_goods',$order_goods);
$this->display();
}
public function ajax_delivery_list(){
$where = [];
$where['order_status'] = ['in','1,2,4'];
I('consignee')?$where['consignee'] = trim(I('consignee')) :false;
I('order_sn') != "" ?$where['order_sn'] = trim(I('order_sn')) :false;
$shipping_status = I('shipping_status');
$where['shipping_status'] = empty(I('shipping_status'))?['neq',1]:$shipping_status;
$count = D('order')->where($where)->count();
$Page = new Page($count,20);
$show = $Page->show();
$delivery = D('order')->where($where)->limit($Page->firstRow.','.$Page->listRows)->select();
$this->assign('count',$count);
$this->assign('page',$show);
$this->assign('delivery',$delivery);
$this->display();
}
public function delivery_info(){
}
public function delivery_list(){
$this->display();
}
}