<?php
namespace app\admin\controller;
use app\admin\logic\RecruitLogic;
use think\Db;
class Recruit extends Admin{

    public  function lists(){
        if ($this->request->isAjax()) {
            $get = $this->request->get();
            $lists = RecruitLogic::lists($get);
            $this->_success('',$lists);
        }
        $department=Db::name('staff_group')->select();  //获取招聘部门的信息
        $this->assign('department',$department);
        return $this->fetch();
    }

    //招聘的岗位
    public function type(){
        if ($this->request->isAjax()) {
            $get = $this->request->get();
            $lists = RecruitLogic::type($get);
            $this->_success('',$lists);
        }
        return $this->fetch();

    }
   //招聘
    public function typeadd(){
        if ($this->request->isAjax()) {
            $get = $this->request->post();
            $lists = RecruitLogic::typeadd($get);
            $this->_success('增加招聘成功');
        }
        return $this->fetch();
    }
    public  function typedit($id){
        if ($this->request->isAjax()) {
           $post = $this->request->post();
           $lists = RecruitLogic::typeedit($post);
           $this->_success('修改类别成功');
        }
        $recruitype=Db::name('recruitype')->where('id',$id)->find();
        $this->assign('recruitype',$recruitype);
        return $this->fetch();
     }

     public  function typedel(){
        $id = $this->request->post('id');
        $lists = RecruitLogic::typedel($id);
        $this->_success('删除服务类别成功');  
     }

    public function  suspend(){
      $id = $this->request->post('id'); 
      $data=Db::name('recrui')->where('id',$id)->update(['status'=>1]);
      $this->_success('暂停招聘成功');  
    }

    public function  cancellation(){
        $id = $this->request->post('id'); 
        $data=Db::name('recrui')->where('id',$id)->update(['status'=>0]);
        $this->_success('启动招聘成功');  
      }
      
        //招聘薪资体系
    public function salary(){
        if ($this->request->isAjax()) {
            $get = $this->request->get();
            $lists = RecruitLogic::salary($get);
            $this->_success('',$lists);
        }
        return $this->fetch();

    }
    //增加薪资体系
    public function salary_add(){
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $data=[
                'name'=>$post['name'],
                'status'=>0,
                'createtime'=>time()
            ];
            $insert=Db::name('recrui_salary')->data($data)->insert();
            if($insert){
                $this->_success('添加薪资待遇成功');
            }
        }
        return $this->fetch();

    }
    //编辑薪资范围
    public function salary_edit(){
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $update=Db::name('recrui_salary')->where('id',$post['id'])->update(['name'=>$post['name'],'createtime'=>time()]);
            $this->_success('更新成功');
        }
        $get = $this->request->get();
        $info=DB::name('recrui_salary')->where('id',$get['id'])->find();
        $this->assign('info',$info);
        return $this->fetch();

    }

    //删除员工薪资范围
    public function salary_del(){
        $post = $this->request->post();
        $del=Db::name('recrui_salary')->where('id',$post['id'])->delete();
        $this->_success('删除成功');

    }




    //增加招聘岗位

    public function add(){
        
        if ($this->request->isAjax()) {
            $post = $this->request->post();
            $list=RecruitLogic::add($post);
            $this->_success('增加招聘成功');
        }
        
        $this->assign('tment',RecruitLogic::salary_list());
        $this->assign('type_list',RecruitLogic::type_list());
        $department=Db::name('staff_group')->select();  //获取招聘部门的信息
        $this->assign('department',$department);
        return $this->fetch();
    }

    //前段用户申请列表
    
    public function filed(){
        if ($this->request->isAjax()) {
            $get = $this->request->get();
            $list=RecruitLogic::filed_lists($get);
            $this->_success('获取数据成功',$list);
        }
        $this->assign('tment',RecruitLogic::salary_list());
        $this->assign('type_list',RecruitLogic::type_list());
        $department=Db::name('staff_group')->select();  //获取招聘部门的信息
        $this->assign('department',$department);
        return $this->fetch();
    }
    
    public function edits(){
         if ($this->request->isAjax()) {
            $post = $this->request->post();
            $list=RecruitLogic::edits($post);
            $this->_success('修改招聘内容成功');
        }
        $get = $this->request->get('id');        
        $this->assign('tment',RecruitLogic::salary_list());
        $this->assign('type_list',RecruitLogic::type_list());
        $this->assign('info',RecruitLogic::recruiinfo($get));
        $department=Db::name('staff_group')->select();  //获取招聘部门的信息
        $this->assign('department',$department);
       return $this->fetch();  
    }
    
    //删除招聘的数据
    public function dels(){
      $id = $this->request->post('id'); 
      $data=Db::name('recrui')->where('id',$id)->delete();
      $this->_success('暂停招聘成功'); 
    }
   
      



}

