<?php
/*
 * $Author ：PHPYUN开发团队
 *
 * 官网: http://www.phpyun.com
 *
 * 版权所有 2009-2019 宿迁鑫潮信息技术有限公司，并保留所有权利。
 *
 * 软件声明：未经授权前提下，不得用于商业运营、二次开发以及任何形式的再次发布。
 */
class talent_model extends model{
	/**
     *  @desc   获取缓存数据
     */
    private function getClass($options){
        
        if (!empty($options)){
            
            include_once ('cache.model.php');
            
            $cacheM     =   new cache_model($this->db, $this->def);
            
            $cache      =   $cacheM -> GetCache($options);
            
            return $cache;
        }
    }

	
	

	
	function addTalent($data){
		if($data['id']){
			$info = $this->getInfo(array('id'=>intval($data['id']),'uid'=>$data['uid']),array('field'=>'`id`,`telstatus`'));
		}
		include_once ('cache.model.php');
        
        $cacheM     =   new cache_model($this->db, $this->def);
        
        $cache      =   $cacheM -> GetCache('city');
        $citymsg 	= 	false;
        if(!empty($cache['city_type'])){
        	if(empty($data['cityid'])){
        		$citymsg = true;
        	}
        }else{
        	if(empty($data['provinceid'])){
        		$citymsg = true;
        	}
        }
		$error['error'] = '0';
		//判断参数是否齐全
		if($data['id'] && empty($info)){
			$error['msg'] = '参数错误';
		}elseif(empty($data['name'])){
			$error['msg'] = '请填写姓名';
		}elseif(empty($data['sex'])){
			$error['msg'] = '请选择性别';
		}elseif(empty($data['age'])){
			$error['msg'] = '请填写年龄';
		}elseif(empty($data['edu'])){
			$error['msg'] = '请选择最高学历';
		}elseif(empty($data['exp'])){
			$error['msg'] = '请选择工作经验';
		}elseif(empty($data['minsalary'])){
			$error['msg'] = '请填写最低薪资需求';
		}elseif(!empty($data['maxsalary']) && $data['maxsalary']<=$data['minsalary']){
			$error['msg'] = '最高薪资必须大于最低薪资';
		}elseif($citymsg){
		    $error['msg'] = '请选择期望城市';
		}
		elseif(empty($data['living'])){
			$error['msg'] = '请填写现居住地';
		}elseif(empty($data['jobname'])){
			$error['msg'] = '请填写意向岗位';
		}elseif(empty($data['hy'])){
			$error['msg'] = '请选择所属行业';
		}elseif(empty($data['jobstatus'])){
			$error['msg'] = '请选择当前求职状态';
		}elseif(empty($data['expinfo'])){
			$error['msg'] = '请填写相关工作经历';
		}elseif(empty($data['eduinfo'])){
			$error['msg'] = '请填写相关教育经历';
		}elseif(empty($data['jobstatus'])){
			$error['msg'] = '请选择当前求职状态';
		}else{
			if($info['telstatus']!='1'){
				if(empty($data['telphone'])){
					$error['msg'] = '请输入求职者手机号';
				}elseif(!CheckMobile($data['telphone'])){
					$error['msg'] = '手机号格式错误';
				}else{
					//检查手机号是否重复
					if($data['id']){
						$where['id']	=	array('<>',intval($data['id']));
					}
					$where['linktel']	=	$data['telphone'];
					$num 				=	$this->select_num('lt_talent',$where);
					if($num>0){
						$error['msg'] 	=	'相同简历已存在，手机号已被使用';
					}
				}
			}
		}
		if(empty($error['msg'])){
			$fieldData['name']			= trim($data['name']);
			$fieldData['sex']			= intval($data['sex']);
			$fieldData['age']			= intval($data['age']);
			$fieldData['exp'] 			= intval($data['exp']);
			$fieldData['edu'] 			= intval($data['edu']);
			$fieldData['living'] 		= $data['living'];
			$fieldData['jobname']		= $data['jobname'];
			$fieldData['hy'] 			= intval($data['hy']);
			$fieldData['minsalary'] 	= intval($data['minsalary']);
			$fieldData['maxsalary'] 	= intval($data['maxsalary']);
			//多选城市
			$fieldData['provinceid']	= intval($data['provinceid']);
			$fieldData['cityid'] 		= intval($data['cityid']);
			$fieldData['three_cityid']	= intval($data['three_cityid']);

			$fieldData['jobstatus']		= $data['jobstatus'];
			if($info['telstatus']!='1'){
				$fieldData['linktel']	= $data['telphone'];
			}
			$fieldData['expinfo'] 		= $data['expinfo'];
			$fieldData['eduinfo'] 		= $data['eduinfo'];
			$fieldData['projectinfo'] 	= $data['projectinfo'];
			$fieldData['skillinfo'] 	= $data['skillinfo'];
			
			if($data['id']){
				$nid = $this->update_once('lt_talent',$fieldData,array('id'=>intval($data['id']),'uid'=>$data['uid']));
				$error['msg'] = $nid?'更新简历成功':'更新简历失败';
			}else{
				
				$fieldData['did']	=	$data['did'];
				$fieldData['uid']	=	$data['uid'];
				
				$nid = $this->insert_into('lt_talent',$fieldData);
				$error['msg'] = $nid?'添加简历成功':'添加简历失败';
			}
			if($nid){
				$error['error']='1';
			}
		}
		return $error;
	}
	
	function getTalentNum($whereData = array()){
        return $this -> select_num('lt_talent', $whereData);
	}
}
?>