ZjOrderController.php 8.8 KB
<?php
/**
 * Created by PhpStorm.
 * User: wz
 * Date: 2018/7/2
 * Time: 9:01
 */

namespace app\admin\controller;


use app\admin\model\ZjOrderModel;
use cmf\controller\AdminBaseController;
use Think\Db;
class ZjOrderController extends AdminBaseController
{
    /**
     * 首页全部订单
     */
    public function index()
    {
        $where=[];
        $id=[];
        if ($this->request->isPost()){
            $in=input('post.');
            if (strlen($in['order_type'])>'0'){
                $where['o.order_type']=$in['order_type'];
            }
            if (strlen($in['aid'])>'0'){
                $where['y.id']=$in['aid'];
            }
            if (strlen($in['ser_type'])>'0'){
                $where['s.ser_type']=$in['ser_type'];
            }
            if (strlen($in['order_num'])>'0'){
                $where['o.order_num']=$in['order_num'];
            }
        }
        $admin=Db::name('role_user')->field('user_id')->where('role_id','3')->select();
        foreach ($admin as $k=>$val){
            $id[]=$val['user_id'];
        }
        $aname=Db::name('user')->field('user_login,id')->where(['id'=>['in',$id]])->select();
        $order=new ZjOrderModel();
        $all=$order->selectAll($where);

        $aa=['0','0','0','0'];
        $zd=['0','0','0'];
        foreach ($all as $k=>$val){
            if ($val['order_type']=='0'){
                $aa['1']+=$val['whole'];
                $zd['0']+='1';
            }elseif ($val['order_type']=='1'){
                $aa['2']+=$val['whole'];
                $zd['1']+='1';
            }else{
                $aa['3']+=$val['whole'];
                $zd['2']+='1';
            }
        }
        $ser=Db::name('zj_service_type')->select();
        $this->assign('aa',$aa);
        $this->assign('zd',$zd);
        $this->assign('ser',$ser);
        $this->assign('allorder',$all);
        $this->assign('admin',$aname);

        return $this->fetch();
    }

    /**
     * 待分配订单
     */
    public function etc()
    {
        $where=[];
        $where['o.order_type']=['eq','2'];
        if ($this->request->isPost()){
            $in=input('post.');
            if (strlen($in['ser_type'])>'0'){
                $where['s.ser_type']=$in['ser_type'];
            }
            if (strlen($in['name'])>'0'){
                $where['s.id']=$in['name'];
            }
            if (strlen($in['date_min'])>'0'){
                $where['o.contact_date']=['egt',$in['date_min']];
            }
            if (strlen($in['date_max'])>'0'){
                $where['o.contact_date']=['elt',$in['date_min']];
            }
            if (strlen($in['contact_time'])>'0'){
                $where['o.contact_time']=$in['contact_time'];
            }

        }

        $service=Db::name('zj_service')->field('id,name,ser_type')->select();//查询服务名称 我的订单联动筛选
        $contact=Db::name('zj_contact')->select();//预约具体时间
        $order=new ZjOrderModel();
        $all=$order->selectAll($where);
        $ser=Db::name('zj_service_type')->select();
        $this->assign('ser',$ser);
        $this->assign('allcon',$contact);
        $this->assign('allorder',$all);
        $this->assign('allservice',$service);
        return $this->fetch();
    }

    /**
     * 批量分配导师
     */
    public function etcten()
    {
        $where=[];
        $oid=input('ids/a');
        if (input('post.admin_id')){
            $where['id']=['in',$oid];
            $aid=input('post.admin_id');
            $ten=Db::name('zj_order')->where($where)->update(array('admin_id'=>$aid,'order_type'=>'3'));
            if ($ten){
                $this->success('导师分配成功',url('ZjOrder/etc'));
            }else{
                $this->error('分配导师出错');
            }
        }else{
            $where['o.id']=['in',$oid];
            $order=new ZjOrderModel();
            $all=$order->selectAll($where);

            $admin=Db::name('role_user')->field('user_id')->where('role_id','3')->select();
            foreach ($admin as $k=>$val){
                $id[]=$val['user_id'];
            }
            $aname=Db::name('user')->field('user_login,id')->where(['id'=>['in',$id]])->select();

            $this->assign('allorder',$all);
            $this->assign('admin',$aname);
            return $this->fetch();
        }
    }

    /**
     * 我的订单
     */
    public function meOrder()
    {
        $where=[];
        $where['o.admin_id']=session('ADMIN_ID');
        $where['o.order_type']=['gt','2'];
        if ($this->request->isPost()){
            $in=input('post.');
            if (strlen($in['ser_type'])>'0'){
                $where['s.ser_type']=$in['ser_type'];
            }
            if (strlen($in['order_type'])>'0'){
                $where['o.order_type']=$in['order_type'];
            }
            if (strlen($in['name'])>'0'){
                $where['s.id']=$in['name'];
            }
            if (strlen($in['date_min'])>'0'){
                $where['o.contact_date']=['egt',$in['date_min']];
            }
            if (strlen($in['date_max'])>'0'){
                $where['o.contact_date']=['elt',$in['date_min']];
            }
            if (strlen($in['contact_time'])>'0'){
                $where['o.contact_time']=$in['contact_time'];
            }
            if (strlen($in['order_num'])>'0'){
                $where['o.order_num']=$in['order_num'];
            }
        }

        $service=Db::name('zj_service')->field('id,name,ser_type')->select();//查询服务名称 我的订单联动筛选
        $contact=Db::name('zj_contact')->select();//预约具体时间
        $order=new ZjOrderModel();
        $all=$order->selectAll($where);
        $ser=Db::name('zj_service_type')->select();
        $this->assign('ser',$ser);
        $this->assign('allcon',$contact);
        $this->assign('allorder',$all);
        $this->assign('allservice',$service);
        return $this->fetch();
    }

    /**
     * 查看详情页面
     */
    public function one()
    {
        $aid=session('ADMIN_ID');
        $where=[];
        if ($this->request->param()){
            $in=input('param.');
            $where['o.id']=$in['id'];
            $order=new ZjOrderModel();
            $oneorder=$order->selectAll($where);
            $oneorder=$oneorder['0'];

            $admin=Db::name('role_user')->field('user_id')->where('role_id','3')->select();
            foreach ($admin as $k=>$val){
                $id[]=$val['user_id'];
            }
            if (in_array($aid,$id)){
                $role='0';
            }else{
                $role='1';
            }
            $aname=Db::name('user')->field('user_login,id')->where(['id'=>['in',$id]])->select();
            $this->assign('admin',$aname);

            $contact=Db::name('zj_contact')->select();
            $this->assign('allcon',$contact);

            $this->assign('role',$role);
            $this->assign('one',$oneorder);
            return $this->fetch();
        }
    }

    /**
     * 订单修改
     */
    public function editPost()
    {
        if ($this->request->isPost()){
            $in=input('post.');
            unset($in['id']);
            $id=input('post.id');
            if ($in['order_type']=='1'&&strlen($in['admin_id'])>0){
                $this->error('订单未支付,不能分配导师。');
            }else{
                unset($in['order_type']);

                $order=Db::name('zj_order')->where('id',$id)->update($in);
                if ($order){
                    $this->success('订单修改成功','');
                }else{
                    $this->error('修改出现错误');
                }
            }
        }
    }

    /**
     * 订单确定完成
     */
    public function complete()
    {
        if ($this->request->isPost()){
            $in=input('post.');
            $order=Db::name('zj_order')->field('admin_id,order_num')->where('id',$in['id'])->find();
                if ($order['admin_id']==session('ADMIN_ID')){
                    if ($order['order_num']==$in['order_num']){
                        $num=Db::name('zj_order')->where('id',$in['id'])->update(array('comm_time'=>time(),'order_type'=>'4'));
                        if ($num){
                            $this->success('订单已完成',url('ZjOrder/complete'));
                        }else{
                            $this->error('修改出现错误');

                        }
                    }else{
                        $this->error('订单编号错误');
                    }
                }else{
                    $this->error('您不是当前订单导师');
                }
        }
        if ($this->request->isGet()){
            $id=input('param.id');
            $this->assign('id',$id);
            return $this->fetch();
        }

        if (!$this->request->isGet()&&!$this->request->isPost()){
            echo '订单修改完成';
        }
    }

}