PlatformordersController.php 2.7 KB
<?php
namespace app\admin\controller;

use app\admin\model\RouteModel;
use cmf\controller\AdminBaseController;
use function GuzzleHttp\Psr7\str;
use think\Db;
class PlatformordersController extends AdminBaseController{

    /**
     * 平台订单列表
     */
    public function plat_list(){

        if($this -> request -> isPost()){
            $where = [
                "indent_type" => 1
            ];
            if(!empty($_POST['start_time']) && !empty($_POST['end_time'])){
                $start_time = strtotime($_POST['start_time']);
                $end_time = strtotime($_POST['end_time']);
                $where['create_time'] = [['>=',$start_time],['<=',$end_time]];
            }
            if(!empty($_POST['keyword'])){
                $where['order_number'] = $_POST['keyword'];
            }
            if(!empty($_POST['state'])){
                $where['state'] = $_POST['state'];
            }
            $data = Db::name('indent') -> where($where) -> paginate(1000000);
            $data1 = $data -> toArray();
            if(count($data1['data'])!=0){
                foreach ($data1['data'] as $key => $val){
                    $data1['data'][$key]['dizhi'] = Db::name('address') -> where('id',$val['indent_address']) -> find();
                }
            }
            $this -> assign('data1',$data1['data']);
        }else{
            $data = Db::name('indent') -> where('indent_type','1') -> paginate(12);
            $data1 = $data -> toArray();
            foreach ($data1['data'] as $key => $val){
                $data1['data'][$key]['dizhi'] = Db::name('address') -> where('id',$val['indent_address']) -> find();
            }
            $this -> assign('data1',$data1['data']);
        }
        $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 plat_del(){

        $id = $_POST['id'];
        Db::name('indent') -> delete($id);
        Db::name('indent_goods') -> where('indent_id',$id) -> delete();
        return true;

    }










}