BookingController.php 6.1 KB
<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2018 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 小夏 < 449134904@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;

use cmf\controller\AdminBaseController;
use think\Db;

/**
 * Class UserController
 * @package app\admin\controller
 * @adminMenuRoot(
 *     'name'   => '管理组',
 *     'action' => 'default',
 *     'parent' => 'user/AdminIndex/default',
 *     'display'=> true,
 *     'order'  => 10000,
 *     'icon'   => '',
 *     'remark' => '管理组'
 * )
 */
class BookingController extends AdminBaseController
{

    public function seting(){
        $id = $this->request->param('id');
        $pcdata = [];
        if($id){
            $pcdata  = DB::name('user')->where(['id'=>$id])->find();

        }
        if(!$pcdata){
            $pcdata['id'] = '';
            $pcdata['user_nickname'] = '请选择';
        }
        $this->assign('pcdata',$pcdata);

        $cdata  = DB::name('user')->where(['user_type'=>'3'])->select()->toArray();
        $this->assign('cdata',$cdata);

        $day = [];

        for($i = 0;$i<21;$i++){
            $day[] = date('Y-m-d',strtotime("+$i day"));
        }
        $this->assign('day',$day);

        return $this->fetch();
    }
    public function seting_do(){
        $param = $this->request->param();
        if(!$param){
            return json(['code'=>'0','msg'=>'数据错误']);
        }
        $datain['teach_id'] = $param['teach_id'];
        $datain['yuyue_begin'] = $param['begin'];
        $datain['yuyue_end'] = $param['end'];
        $datain['yuyue_day'] = $param['day'];
        $cdata  = DB::name('yuyue')->where($datain)->find();
        if($cdata){
            if($cdata['uid'] == '0'){
                $res  = DB::name('yuyue')->where($datain)->delete();

                if ($res) {
                    return json(['code'=>'1','msg'=>'取消成功']);
                }else{
                    return json(['code'=>'0','msg'=>'取消失败']);

                }
            }else{
                return json(['code'=>'0','msg'=>'已被学员预约,无法取消']);
            }

        }else{
            $res  = DB::name('yuyue')->insert($datain);
            if ($res) {
                return json(['code'=>'1','msg'=>'保存成功']);
            }else{
                return json(['code'=>'0','msg'=>'保存失败']);
            }
        }
    }


    public function  find_seting(){
        $day   = $this->request->param('day');
        $uid   = $this->request->param('uid');
        if(!$day){
            $day = date('Y-m-d');
        }

        $res = Db::name('yuyue')->where(['yuyue_day'=>$day,'teach_id'=>$uid])->select()->toArray();

        $all_arr = [];
        for($t = 7;$t<=18;$t++){
            $all_arr[]=$t;
        }

        $arr = [];
        for($i = 0;$i<count($res);$i++){
            $begin = $res[$i]["yuyue_begin"];
            $end = $res[$i]["yuyue_end"];
            for($j= $begin;$j<$end;$j++){
                $arr[]=$j;
            }
        }
        $ok_arr = [];
        for($q = 0;$q< count($all_arr);$q++){
            if(in_array($all_arr[$q],$arr)){
                $ok_arr[] = "no";
            }else{
                $ok_arr[] = "yes";
            }
        }

        $res1 = Db::name('yuyue')->where(['yuyue_day'=>$day,'teach_id'=>$uid,'uid'=>['gt','0']])->select()->toArray();

        $all_arr1 = [];
        for($t = 6;$t<=18;$t++){
            $all_arr1[]=$t;
        }

        $arr1 = [];
        for($i = 0;$i<count($res1);$i++){
            $begin = $res1[$i]["yuyue_begin"];
            $end = $res1[$i]["yuyue_end"];
            for($j= $begin;$j<$end;$j++){
                $arr1[]=$j;
            }
        }
        $ok_arr1 = [];
        for($q = 0;$q< count($all_arr1);$q++){
            if(in_array($all_arr1[$q],$arr1)){
                $ok_arr1[] = "no";
            }else{
                $ok_arr1[] = "yes";
            }
        }
$dataa[0] = $ok_arr;
$dataa[1] = $ok_arr1;

        if ($ok_arr){
            return json(['code'=>'1','msg'=>'获取成功','data'=>json_encode($dataa,true)]);
        }else{
            return json(['code'=>'0','msg'=>'获取失败']);
        }
    }
//    public function find_seting(){
//        $param = $this->request->param();
//        if(!$param){
//            return json(['code'=>'0','msg'=>'数据错误']);
//        }
//        $datain['teach_id'] = $param['teach_id'];
//        $datain['day'] = $param['day'];
//
//        $data = array();
//        for($i=0;$i<11;$i++){
//            $data[$i] = 'ok';
//        }
//        $res = Db::name('yuyue')
//            ->where(['yuyue_day'=>$datain['day'],'teach_id'=>$datain['teach_id']])
//            ->field('yuyue_hour')
//            ->select()
//            ->toArray();
//        if($res){
//            foreach($res as $v){
//                $data[$v['yuyue_hour']] = 'no';
//            }
//        }
//
//        if ($data){
//            return json(['code'=>'1','msg'=>'获取成功','data'=>json_encode($data,true)]);
//        }else{
//            return json(['code'=>'0','msg'=>'获取失败']);
//        }
//    }



    public function listing(){
        $param = $this->request->param();
        $name = empty($param['name']) ? '' : $param['name'];
        if (!empty($name)) {
            $where['u.user_nickname'] = $name;
        }

        $where['yy.create_time'] = array('gt',0);
        $list = DB::name('yuyue')
            ->alias('yy')
            ->join('qnb_user u','u.id=yy.teach_id')
            ->field('yy.*,u.user_nickname')
            ->where($where)
            ->order('id','desc')
            ->paginate(15);
        $this->assign("list", $list->items());
        $this->assign('page', $list->render());
        return $this->fetch();
    }
}