OrderscourierController.php 4.8 KB
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use think\Db;
class OrderscourierController extends AdminBaseController{

    /**
     *平台订单列表
     */
    public function order_list(){
        $param = $this->request->param();
        $where = [
            "indent_type" => 1
        ];
        if(!empty($param['start_time']) && !empty($param['end_time'])){
            $start_time = strtotime($param['start_time']);
            $end_time = strtotime($param['end_time']);
            $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
        }
        if(!empty($param['keyword'])){
            $where['order_number'] = ['like','%'.trim($param['keyword']).'%'];
        }
        if(!empty($param['state'])){
            $where['state'] = $param['state'];
        }
        $data = Db::name('indent')->where($where)->where("state = 2 or state = 3 or state = 5")->order('create_time','DESC')->paginate(12);
        $this->assign('start_time',!empty($param['start_time']) ? $param['start_time'] : '');
        $this->assign('end_time',!empty($param['end_time']) ? $param['end_time'] : '');
        $this->assign('keyword',!empty($param['keyword']) ? trim($param['keyword']) : '');
        $this->assign('state',!empty($param['state']) ? $param['state'] : '');
        $this->assign('data',$data);
        return $this->fetch();

    }

    /**
     *平台订单查看
     */
    public function plat_view(){

        $id = $this -> request -> param();
        $indent_id = $id['id'];
        $data_goods = Db::name('indent_goods') -> where('indent_id',$indent_id) -> select();
        $data_in = Db::name('indent') -> where('id',$indent_id) -> find();
        $this -> assign('data_goods',$data_goods);
        $this -> assign('data_in',$data_in);
        //地址查询
        $address = Db::name('address') -> where("id",$data_in['indent_address']) -> find();
        if(!empty($address)){
            $this -> assign('address',$address);
        }else{
            $this -> assign('address',null);
        }

        return $this -> fetch();

    }

    /**
     * 查看物流信息
     */
    public function logistics_information(){

        $indent_id = $this -> request -> param();
        $bird = new BirdController();
        $logistics = $bird -> getOrder($indent_id['id']);
        $this -> assign('logistics',$logistics['data']['traces']);
        return $this -> fetch();

    }

    /**
     * 发货
     * @adminMenu(
     *     'name'   => '发货',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '发货',
     *     'param'  => ''
     * )
     */
    public function fahuo()
    {
        $id = $this->request->param('id', 0, 'intval');
        if($this->request->isPost()) {
            $param = $this->request->param();
            $url = $param['url'];
            unset($param['url']);
            // 判断订单是否可发货
            $info = Db::name('indent')->where('id',$param['id'])->find();
            if (!$info) {
                $this->error("订单不存在!");
            }
            if ($info['state'] != 2) {
                $this->error("订单无法发货!");
            }
            // 修改发货状态
            $param['state'] = 5;
            $result = Db::name('indent')->update($param);
            if ($result) {
                $this->success("发货成功!",$url);
            } else {
                $this->error('发货失败!');
            }
        } else {
            if ($id) {
                $info = Db::name('indent')->where('id',$id)->find();
                $this->assign('info',$info);
                $this->assign('url',$_SERVER['HTTP_REFERER']);
                return $this->fetch();
            } else {
                $this->error('数据传入失败!');
            }
        }
    }



    /**
     * 完成
     * @adminMenu(
     *     'name'   => '完成',
     *     'parent' => 'index',
     *     'display'=> false,
     *     'hasView'=> false,
     *     'order'  => 10000,
     *     'icon'   => '',
     *     'remark' => '完成',
     *     'param'  => ''
     * )
     */
    public function complete()
    {
        $param = $this->request->param();
        // 判断订单是否可发货
        $info = Db::name('indent')->where('id',$param['id'])->find();
        if (!$info) {
            $this->error("订单不存在!");
        }
        if ($info['state'] != 5) {
            $this->error("订单无法完成!");
        }
        // 修改发货状态
        $param['state'] = 3;
        $result = Db::name('indent')->update($param);
        if ($result) {
            $this->success("操作成功!");
        } else {
            $this->error('操作失败!');
        }
    }





}