SalesmanorderController.php 3.1 KB
<?php
namespace app\admin\controller;

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

class SalesmanorderController extends AdminBaseController{

    /**
     * 业务员订单列表
     */
    public function sale_order_list(){

        if($this -> request -> isPost()){
            $where = [
                'indent_type' => 2
            ];
            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'];
            }
            if(!empty($_POST['uid'])){
                $where['uid'] = $_POST['uid'];
            }
            if(!empty($_POST['school'])){
                $where['school'] = $_POST['school'];
            }
            if(!empty($_POST['grade'])){
                $where['grade'] = $_POST['grade'];
            }
            $data = Db::name('indent') -> where($where) -> paginate(12);
            $data_arr = $data -> toArray();
        }else{
            $data = Db::name('indent') -> where('indent_type',2) -> paginate(12);
            $data_arr = $data -> toArray();
        }
        $money = 0;
        foreach($data_arr['data'] as $key => $val){
            $data_arr['data'][$key]['grade_class'] = $val['school'].'-'.$val['grade'].$val['class'].'班';
            $money += $data_arr['data'][$key]['money'];
        }
        $data_school = Db::name('indent') -> group('school') -> where('indent_type',2) -> select() -> toArray();
        foreach($data_school as $key => $val){
            $school[$key] = $val['school'];
        }
        $uid = Db::name('user') -> select();
        foreach($uid as $key => $val){
            $sales[$key]['uid'] = $val['id'];
            $sales[$key]['name'] = $val['user_nickname'];
        }
        $this -> assign('data_arr',$data);
        $this -> assign('school',$school);
        $this -> assign('sales',$sales);
        $this -> assign('money',$money);
        $this -> assign('data',$data_arr['data']);
        return $this -> fetch();

    }

    /**
     * 业务员订单查看
     */
    public function sale_order_show(){

        $id = $this -> request -> param();
        $data = Db::name('indent') -> where('id',$id['id']) -> find();
        $data_content = Db::name('indent_goods') -> where('indent_id',$id['id']) -> select();
        $this -> assign('data',$data);
        $this -> assign('data_content',$data_content);
        return $this -> fetch();

    }

    /**
     * 业务员订单删除
     */
    public function sale_order_del(){

        $id = $_POST['id'];
        $data = Db::name('indent') -> delete($id);
        $goods = Db::name('indent_goods') -> where('indent_id',$id) -> delete();
        if($data){
            return true;
        }else{
            return false;
        }

    }






}