审查视图

app/admin/controller/SalesmanorderController.php 4.4 KB
anyv authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
<?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'])){
anyv authored
32
                $where['salesman_uid'] = $_POST['uid'];
anyv authored
33 34 35 36 37 38 39
            }
            if(!empty($_POST['school'])){
                $where['school'] = $_POST['school'];
            }
            if(!empty($_POST['grade'])){
                $where['grade'] = $_POST['grade'];
            }
5  
anyv authored
40
            $data = Db::name('indent') -> where($where)  -> paginate(1000000);
anyv authored
41 42
            $data_arr = $data -> toArray();
        }else{
4  
anyv authored
43
            $data = Db::name('indent') -> where('indent_type',2) -> paginate(12);
anyv authored
44 45 46 47
            $data_arr = $data -> toArray();
        }
        $money = 0;
        foreach($data_arr['data'] as $key => $val){
4  
anyv authored
48 49 50
            $data_arr['data'][$key]['grade_class'] = $val['school'].'-'.$val['grade'].$val['class'];
        }
        foreach ($data_arr['data'] as $key => $val){
anyv authored
51
            if($val['state'] == 2 || $val['state'] == 3 || $val['state'] == 5){
4  
anyv authored
52 53
                $money += $data_arr['data'][$key]['money'];
            }
anyv authored
54
        }
anyv authored
55
        $data_school = Db::name('school') -> group('school') -> select() -> toArray();
anyv authored
56
        foreach($data_school as $key => $val){
anyv authored
57
            $school[$key] = $val['school'];
anyv authored
58
        }
5  
anyv authored
59 60
        $uid = Db::name('my_user') -> alias('a') -> join('user b','a.uid = b.id','LEFT') -> where('a.status = 2') -> select();
       /* foreach($uid as $key => $val){
anyv authored
61 62
            $sales[$key]['uid'] = $val['id'];
            $sales[$key]['name'] = $val['user_nickname'];
5  
anyv authored
63
        }*/
anyv authored
64 65
        $this -> assign('data_arr',$data);
        $this -> assign('school',$school);
5  
anyv authored
66
        $this -> assign('sales',$uid);
anyv authored
67 68 69 70 71 72 73 74 75 76 77 78 79
        $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();
anyv authored
80 81 82 83 84 85 86 87
        //判断订单是业务员订单还是平台订单
        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 = '';
            }
5  
anyv authored
88
        }else{
4  
anyv authored
89
            $address_region = $data['region'].$data['school'].$data['grade'].$data['class'];
5  
anyv authored
90
        }
4  
anyv authored
91
        //判断订单是统一配送还是快递配送
anyv authored
92 93 94 95 96 97 98 99 100 101 102 103 104 105
        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']);
            }

        }
anyv authored
106 107
        $data_content = Db::name('indent_goods') -> where('indent_id',$id['id']) -> select();
        $this -> assign('data',$data);
5  
anyv authored
108
        $this -> assign('address_region',$address_region);
anyv authored
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
        $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;
        }

    }






}