审查视图

app/portal/controller/OrderSalesmanController.php 6.5 KB
1 2 3 4 5 6 7 8 9 10 11
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/9
 * Time: 15:34
 */

namespace app\portal\controller;

王晓刚 authored
12
use app\portal\model\AddressModel;
13 14 15 16 17 18 19 20
use app\portal\model\IndentGoodsModel;
use app\portal\model\IndentModel;
use cmf\controller\WeChatBaseController;
use think\Db;

class OrderSalesmanController extends WeChatBaseController
{
    protected $user_id;
王晓刚 authored
21 22 23 24 25
    protected $beforeActionList = [
        'check'             => ['except' => 'getGradeClass'],
    ];

    protected function check() {
26 27 28 29
        $user_id = cmf_get_current_user_id();
        $this->user_id = $user_id;
        $my_user = Db::name('my_user')->where(['uid'=>$user_id])->find();
        if(empty($my_user)){
王晓刚 authored
30 31 32 33
            $this->error('查无此人','','','');
        }
        if($my_user['status'] != 2){
            $this->error('您还不是业务员那','','','');
34 35 36 37 38 39
        }
    }
    public function get_all(){
        $param = $this->request->param();
        if(!empty($param['is_courier'])){
            $where['is_courier'] = ['eq',$param['is_courier']];
40 41
        }else{
            $where['is_courier'] = ['eq',1];
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
        }
        $user_id = $this->user_id;
        $where['salesman_uid'] = ['eq',$user_id];
        $where['indent_type'] = ['eq',2];
        $where['state'] = ['neq',4];
        $indentModel = new IndentModel();
        $data = $indentModel->selectData($where);
        $indentGoodsModel = new IndentGoodsModel();
        foreach($data as $key => $vo){
            $indent_goods = $indentGoodsModel->selectData(['indent_id'=>$vo['id']]);
            $data[$key]['indent_goods'] = $indent_goods;
        }
        $school = Db::name('school')->where('uid',$user_id)->order('create_time desc')->select();
        $this->assign('school',$school);
        $this->assign('data',$data);
        return $this->fetch();
    }
    public function getGradeClass(){
        $school_id = $this->request->param('school_id',0,'intval');
        if(empty($school_id)){
            $this->error('缺少必要参数');
        }
王晓刚 authored
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
        $grade = Db::name('grade_class')->where(['school_id'=>$school_id])->select()->toArray();
        foreach($grade as $key => $g){
            $class = explode('-',$g['class']);
            $grade[$key]['start'] = $class[0];
            $grade[$key]['end'] = $class[1];
        }
        $this->success('SUCCESS','',$grade);
    }
    public function getOrderSalesman(){
        $param = $this->request->param();
        if(!empty($param['school'])){
            $where['school'] = ['eq',$param['school']];
        }
        if(!empty($param['grade'])){
            $where['grade'] = ['eq',$param['grade']];
        }
王晓刚 authored
80 81 82 83 84
        if(!empty($param['state'])){
            $where['state'] = ['eq',$param['state']];
        }else{
            $where['state'] = ['neq',4];
        }
85 86 87 88 89
        if(!empty($param['is_courier'])){
            $where['is_courier'] = ['eq',$param['is_courier']];
        }else{
            $where['is_courier'] = ['eq',1];
        }
王晓刚 authored
90 91 92 93 94 95 96 97 98 99 100
        $user_id = $this->user_id;
        $where['salesman_uid'] = ['eq',$user_id];
        $where['indent_type'] = ['eq',2];
        $indentModel = new IndentModel();
        $data = $indentModel->selectData($where);
        $indentGoodsModel = new IndentGoodsModel();
        foreach($data as $key => $vo){
            $indent_goods = $indentGoodsModel->selectData(['indent_id'=>$vo['id']]);
            $data[$key]['indent_goods'] = $indent_goods;
        }
        $this->success('SUCCESS','',$data);
101
    }
王晓刚 authored
102 103 104 105 106 107 108 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 136 137
    public function send(){
        $param = $this->request->param();
        if(empty($param['is_courier'])){
            $this->error('缺少必要参数1');
        }
        if($param['is_courier'] == 1){
            if(empty($param['start_time'])){
                $this->error('缺少必要参数2');
            }
            if(empty($param['end_time'])){
                $this->error('缺少必要参数3');
            }
        }else if($param['is_courier'] == 2){
            if(empty($param['logistic_name'])){
                $this->error('缺少必要参数4');
            }
            if(empty($param['logistic_code'])){
                $this->error('缺少必要参数5');
            }
        }
        if(empty($param['indent_id'])){
            $this->error('缺少必要参数6');
        }
        $where['id'] = ['eq',$param['indent_id']];
        $indentModel = new IndentModel();
        $indent = $indentModel->findData($where);
        if(empty($indent)){
            $this->error('查询为空');
        }
        if($indent['state'] != 2){
            $this->error('订单不是待支付状态');
        }
        $arr = [];
        if($param['is_courier'] == 1){
            $arr['start_time'] = $param['start_time'];
            $arr['end_time'] = $param['end_time'];
138 139 140
        }else if($param['is_courier'] == 2){
            $arr['logistic_name'] = $param['logistic_name'];
            $arr['logistic_code'] = $param['logistic_code'];
王晓刚 authored
141 142
        }
        $arr['state'] = 5;
王晓刚 authored
143
//        $result = $indentModel->updateData($where,$arr);
王晓刚 authored
144 145
        $this->success('发货成功');
    }
王晓刚 authored
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
    public function send_all(){
        $param = $this->request->param();
        if(empty($param['start_time2']) || empty($param['end_time2']) || empty($param['indent_ids'])){
            $this->error('缺少必要参数');
        }
        $indent_ids = explode(',',$param['indent_ids']);
        $data['start_time'] = $param['start_time2'];
        $data['end_time'] = $param['end_time2'];
        $data['state'] = 5;
        $indentModel = new IndentModel();
        $result = $indentModel->updateData(['id'=>['in',$indent_ids]],$data);
        if(empty($result)){
            $this->error('更新失败');
        }else{
            $this->success('发货成功');
        }
    }
    public function get_one(){
        $id = $this->request->param('id',0,'intval');
        if(empty($id)){
            $this->error('缺少必参数','','','');
        }
        $indentModel = new IndentModel();
        $indent = $indentModel->findData(['id'=>$id]);
        if(empty($indent)){
            $this->error('查询为空');
        }
        $indentGoodsModel = new IndentGoodsModel();
        $indent_goods = $indentGoodsModel->selectData(['indent_id'=>$indent['id']]);
王晓刚 authored
175 176 177 178 179
        if(!empty($indent['indent_address'])){
            $addressModel = new AddressModel();
            $indent_address = $addressModel->findData(['id'=>$indent['indent_address']]);
            $indent['indent_address'] = $indent_address;
        }
王晓刚 authored
180 181 182 183
        $indent['indent_goods'] = $indent_goods;
        $this->assign('data',$indent);
        return $this->fetch();
    }
184
}