IndexController.php 8.0 KB
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
namespace app\portal\controller;



use app\portal\model\HireModel;
use app\portal\model\OrderModel;
use app\portal\model\ResumeModel;
use app\portal\validate\ResumeValidate;
use cmf\controller\HomeBaseController;
use think\Db;
use think\Loader;
use think\Session;

class IndexController extends CommentController
{
//    我要雇人首页
    public function index()
    {
        $where_member['id'] = Session::get('uid');
        $member = Db::name('Member')->where($where_member)->field('name,tel,card_num')->find();
        if(empty($member['name']) || empty($member['tel']) || empty($member['card_num'])){
            $final['is_check'] = 0;
        }else{
            $final['is_check'] = 1;
        }
        //        轮播图
        $where_banner['status'] = array('neq',9);
        $where_banner['type'] = 1;
        $banner = Db::name('Banner')->where($where_banner)->order('score desc,create_time desc')->limit(3)->select()->toArray();
        $final['banner'] = $banner;
        //        我的位置
        $config = $this->getSignPackage();
        $this->assign('config',$config);
        //        雇佣事项
        $where_select['status'] = array('neq',9);
        $where_select['type'] = 1;
        $select = Db::name('Select')->where($where_select)->order('score desc,create_time desc')->field('id as value, name as label')->select()->toArray();
        $final['select'] = json_encode($select);
//        协议
        $where_art['status'] = array('neq',9);
        $where_art['type'] = 1;
        $art = Db::name('Art')->where($where_art)->find();
        $art['content'] = htmlspecialchars_decode($art['content']);
        $final['art'] = $art;
        $where_cof['status'] = array('neq',9);
        $tel = Db::name('Config')->where($where_cof)->value('tel');
        $final['tel'] = $tel;
        $this->assign('final',$final);
        return $this->fetch();
    }
    //    实名认证
    public function Authentication(){
        $data = $this->request->param();
        if(empty($data['name'])){
            $this->apiResponse('0','姓名不能为空');
        }
        if(empty($data['tel'])){
            $this->apiResponse('0','手机号不能为空');
        }
        if(empty($data['card_num'])){
            $this->apiResponse('0','身份证号不能为空');
        }
        $add = $data;
        $add['status'] = 2;
        $add['update_time'] = time();
        $where_member['id'] = Session::get('uid');
        $validate = Loader::validate('Member');
        if(!$validate->scene('add')->check($data)){
            $mes = $validate->getError();
            $this->apiResponse('0',$mes);
        }
        $res = Db::name('Member')->where($where_member)->update($add);
        if($res){
            $this->apiResponse('1','成功');
        }else{
            $this->apiResponse('0','认证失败');
        }
    }

    //    兼职页面展示
    public function show()
    {
        //        判断是否是首次进入
        $where_member['id'] = Session::get('uid');
        $member = Db::name('Member')->where($where_member)->field('name,tel,card_num')->find();
        if(empty($member['name']) || empty($member['tel']) || empty($member['card_num'])){
            $final['is_check'] = 0;
        }else{
            $final['is_check'] = 1;
        }
//        判断是否填写过
        $where_resume['user_id'] = Session::get('uid');
        $where_resume['status'] = array('neq',9);
        $is_resume = Db::name('Resume')->where($where_resume)->find();
        if($is_resume){
            if($is_resume['status'] == 2){
                    $final['is_resume'] = 2;
            }else{
                if($is_resume['status'] == 4){
                    $final['is_resume'] = 0;
                    $where_refund['elseId'] = $is_resume['id'];
                    $where_refund['type'] = 2;
                    $refund = Db::name('Refund')->where($where_refund)->value('content');
                    $final['refund'] = $refund;
                }else{
                    $final['is_resume'] = 3;
                }
            }
        }else{
            $final['is_resume'] = 0;
        }
        //        轮播图
        $where_banner['status'] = array('neq',9);
        $where_banner['type'] = 2;
        $banner = Db::name('Banner')->where($where_banner)->order('score desc,create_time desc')->limit(3)->select()->toArray();
        $final['banner'] = $banner;
        //        我的位置
        $config = $this->getSignPackage();
        $this->assign('config',$config);
        //        雇佣事项
        $where_select['status'] = array('neq',9);
        $where_select['type'] = 2;
        $select = Db::name('Select')->where($where_select)->order('score desc,create_time desc')->field('id as value, name as label')->select()->toArray();
        $final['select'] = json_encode($select);

        //        协议
        $where_art['status'] = array('neq',9);
        $where_art['type'] = 2;
        $art = Db::name('Art')->where($where_art)->find();
        $art['content'] = htmlspecialchars_decode($art['content']);
        $final['art'] = $art;
        $where_cof['status'] = array('neq',9);
        $tel = Db::name('Config')->where($where_cof)->value('tel');
        $final['tel'] = $tel;
        $this->assign('final',$final);
        return $this->fetch('postjob');
    }

    //    我要雇人表单提交
    public function hire()
    {
        $data = $this->request->param();
        $validate = Loader::validate('Hire');
        $start_time = str_replace("年","-",$data['start_time']);
        $start_time = str_replace("月","-",$start_time);
        $data['start_time'] = str_replace("日","",$start_time);
        $end_time = str_replace("年","-",$data['end_time']);
        $end_time = str_replace("月","-",$end_time);
        $end_time = str_replace("月","-",$end_time);
        $data['end_time'] = str_replace("日","",$end_time);
        if(!$validate->scene('add')->check($data)){
            $mes = $validate->getError();
            $this->apiResponse('0',$mes);
        }
        $model = new HireModel();
        $data['user_id'] = Session::get('uid');
        $res = $model->save($data);
        if($res){
            $this->setOrder($model->id,$data['money'],$data['user_id']);
            $this->apiResponse('1','成功');
        }else{
            $this->apiResponse('0','提交失败');
        }
    }

    public function getPic(){
        $get = new MemberController();
        $this->apiResponse('1','成功',$get->pic($_FILES)) ;
    }


    //    我要兼职表单提交
    public function resume()
    {
        $data = $this->request->param();
//        图片上传
        $validate = Loader::validate('Resume');
        if(!$validate->check($data)){
            $mes = $validate->getError();
            $this->apiResponse('0',$mes);
        }
        $model = new ResumeModel();
        $data['user_id'] = Session::get('uid');
        $data['skill'] = implode(',',$data['skill']);
        $res = $model->save($data);
        if($res){
            $this->apiResponse('1','成功');
        }else{
            $this->apiResponse('0','提交失败');
        }
    }

    //    创建订单
    public function setOrder($hireId,$money,$user_id){
        $orderModel = new OrderModel();
        $add_order['order_sn'] = $this->getSn();
        $add_order['hire_id'] = $hireId;
        $add_order['money'] = $money;
        $add_order['user_id'] = $user_id;
        $res = $orderModel->save($add_order);
        if(!$res){
            $this->apiResponse('0','添加失败');
        }
    }

    //    协议
//    public function art(){
//
//        return $this->fetch();
//    }


}