SalesmanorderController.php 5.0 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(){
        $param = $this->request->param();
        $where = [
            'i.indent_type' => 2
        ];
        if(!empty($param['user_id'])){
            $where['mu.id'] = $param['user_id'];
        }
        if(!empty($param['keyword'])){
            $where['i.order_number|i.name|i.phone'] = ['like','%'.trim($param['keyword']).'%'];
        }
        if(!empty($param['state'])){
            $where['i.state'] = $param['state'];
        }
        if(!empty($param['uid'])){
            $where['i.salesman_uid'] = $param['uid'];
        }
        if(!empty($param['school'])){
            $where['i.school'] = $param['school'];
        }
        if(!empty($param['grade'])){
            $where['i.grade'] = $param['grade'];
        }
        $data = Db::name('indent')->alias('i')
            ->field('i.*,mu.id as muid')
            ->join('__MY_USER__ mu','i.uid = mu.uid')
            ->where($where)
            ->order('i.create_time','DESC')
            ->paginate(12);
        $data->appends($param);
        $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'];
            $nickname = '';
            if($val['salesman_uid']) {
                $nickname = Db::name('user')->where('id',$val['salesman_uid'])->value('user_nickname');
            }
            $data_arr['data'][$key]['nickname'] = $nickname;
            if($val['state'] == 2 || $val['state'] == 3 || $val['state'] == 5){
                $money += $data_arr['data'][$key]['money'];
            }
        }
        // 学校筛选列表
        $data_school = Db::name('school') -> group('school') -> select() -> toArray();
        foreach($data_school as $key => $val){
            $school[$key] = $val['school'];
        }
        // 业务员筛选列表
        $uid = Db::name('my_user') -> alias('a') -> join('user b','a.uid = b.id','LEFT') -> where('a.status = 2') -> select();
        // 年级筛选列表
        $grade_array = [
            '一年级' => '一年级',
            '二年级' => '二年级',
            '三年级' => '三年级',
            '四年级' => '四年级',
            '五年级' => '五年级',
            '六年级' => '六年级',
            '初一'   => '初一',
            '初二'   => '初二',
            '初三'   => '初三',
            '高一'   => '高一',
            '高二'   => '高二',
            '高三'   => '高三'
        ];
        $this->assign('user_id', isset($param['user_id']) ? trim($param['user_id']) : '');
        $this->assign('keyword', isset($param['keyword']) ? trim($param['keyword']) : '');
        $this->assign('state', isset($param['state']) ? $param['state'] : '');
        $this->assign('uid', isset($param['uid']) ? $param['uid'] : '');
        $this->assign('school_val', isset($param['school']) ? $param['school'] : '');
        $this->assign('grade', isset($param['grade']) ? $param['grade'] : '');
        $this->assign('grade_array', $grade_array);
        $this -> assign('data_arr',$data);
        $this -> assign('school',$school);
        $this -> assign('sales',$uid);
        $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();
        //判断订单是业务员订单还是平台订单
        if($data['indent_type'] == 1){
            if(!empty($data['indent_address'])){
                $address = Db::name('address') -> where("id",$data['indent_address']) -> find();
                $address_region = $address['region'].$address['detailed'];
            }else{
                $address_region = '';
            }
        }else{
            $address_region = $data['region'].$data['school'].$data['grade'].$data['class'];
        }
        //判断订单是统一配送还是快递配送
        if($data['is_courier'] == 1){
            $logistics = $data['start_time'];
            $this -> assign('logistics',$logistics);
        }else{
            $bird = new BirdController();
            $logistics = $bird -> getOrder($id['id']);
            if($logistics['code'] == 40000){
                $this -> assign('logistics',4);
            }else{
                $this -> assign('logistics',$logistics['data']['traces']);
            }

        }

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

    }






}