<?php
/*
===========================用户控制器
^^^^^^^^^^^^^^^^^^成员
------添加(on_insert)
------修改(on_update)
------删除(on_del)

*/
class cls_tab_hr_job_view extends cls_base_table
{
	private $obj_db;
	//构造函数
	function __construct()
	{
		global $obj_db;
		parent::__construct();
		$this->obj_db=$obj_db;
	}
	/*添加
	arr_fields:关健字数组
	*/
	function on_save($arr_fields,$str_where="")
	{
		$arr_return=array("err"=>"","id"=>0);
		//保存操作
		if(isset($arr_fields["view_id"])) unset($arr_fields["view_id"]);//释放id
		$arr_fields["view_addtime"]=TIME;
		$arr_fields["view_updatetime"]=TIME;
		$arr_return=self::_insert($arr_fields);
		return $arr_return;
	}
	function _insert($arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(!isset($arr_fields["view_user_id"])||intval($arr_fields["view_user_id"])<1){
			$arr_return["err"]="个人会员不存在！";
			return $arr_return;
		}
		if(!isset($arr_fields["view_company_id"])||intval($arr_fields["view_company_id"])<1){
			$arr_return["err"]="被浏览企业不存在！";
			return $arr_return;
		}
		if(!isset($arr_fields["view_job_id"])||intval($arr_fields["view_job_id"])<1){
			$arr_return["err"]="被浏览职位不存在！";
			return $arr_return;
		}
		$obj_result = $this->obj_db->query("SELECT * FROM ".DB_PRE."hr_job_view where view_user_id='".$arr_fields["view_user_id"]."' and view_company_id='".$arr_fields["view_company_id"]."' and view_job_id='".$arr_fields["view_job_id"]."'");
		if($obj_rs = $this->obj_db->fetch_array($obj_result))
		{
			$arr_fields_new=array();
			//一天只记录一次
			$str_date=format_date(TIME,"Y-m-d");
			$lng_time=format_date_int($str_date);
			if($obj_rs["view_updatetime"]<$lng_time){
				$arr_fields_new["view_updatetime"]=TIME;
				$arr_fields_new["view_num"]=$obj_rs["view_num"]+1;
				$arr_return=parent::on_update(DB_PRE."hr_job_view",$arr_fields_new,"view_user_id='".$arr_fields["view_user_id"]."' and view_job_id='".$arr_fields["view_job_id"]."'");
			}else{
				$arr_return["err"]="今天已经浏览过!";
				return $arr_return;
			}
		}else{
			$arr_return=parent::on_insert(DB_PRE."hr_job_view",$arr_fields);
		}
		return $arr_return;
	}
	function on_del($arr_id)
	{
		$arr_return=array("err"=>"");
		$str_id=get_arr_id($arr_id);
		if($str_id==""){
			$arr_return["err"]="没有指定要删除的记录！";
			return $arr_return;
		}
		$arr_return=parent::on_del(DB_PRE."hr_job_view","view_id in(".$str_id.")");

		return $arr_return;
	}
}
?>
