OrderSalesmanController.php 3.0 KB
<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/9
 * Time: 15:34
 */

namespace app\portal\controller;


use app\portal\model\IndentGoodsModel;
use app\portal\model\IndentModel;
use cmf\controller\WeChatBaseController;
use think\Db;

class OrderSalesmanController extends WeChatBaseController
{
    protected $user_id;
    public function _initialize(){
        $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)){
            $this->error('查无此人','','','');
        }
        if($my_user['status'] != 2){
            $this->error('您还不是业务员那','','','');
        }
    }
    public function get_all(){
        $param = $this->request->param();
        if(!empty($param['is_courier'])){
            $where['is_courier'] = ['eq',$param['is_courier']];
        }
        $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('缺少必要参数');
        }
        $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']];
        }
        $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;
            $dara[$key]['create_time'] = date('Y-m-d H:i:s',$vo['create_time']);
        }
        $this->success('SUCCESS','',$data);
    }
}