<?php
 /*
 * 74cms 下载简历
 * ============================================================================
 * 版权所有: 骑士网络，并保留所有权利。
 * 网站地址: http://www.74cms.com；
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和
 * 使用；不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
*/
define('IN_QISHI', true);
require_once(dirname(__FILE__).'/../include/common.inc.php');
$act = isset($_REQUEST['act']) ? trim($_REQUEST['act']) : 'download';
require_once(QISHI_ROOT_PATH.'include/mysql.class.php');
require_once(QISHI_ROOT_PATH.'include/fun_user.php');
$db = new mysql($dbhost,$dbuser,$dbpass,$dbname);
if ($_SESSION['uid']=='' || $_SESSION['username']=='')
{
	$captcha=get_cache('captcha');
	$smarty->assign('verify_userlogin',$captcha['verify_userlogin']);
	$smarty->display('plus/ajax_login.htm');
	exit();
}
if ($_SESSION['utype']!='1'&&$_SESSION['utype']!='3')
{
	exit('必须是企业会员/猎头会员才可以下载list！ ');
}
if($_SESSION['utype']=="1")
{
	require_once(QISHI_ROOT_PATH.'include/fun_company.php');
	$user=get_user_info($_SESSION['parentuid']);
}
elseif($_SESSION['utype']=="3")
{
	require_once(QISHI_ROOT_PATH.'include/fun_hunter.php');
	$user=get_user_info($_SESSION['uid']);
}
if ($user['status']=="2") 
{
	exit('您的账号处于暂停状态，请先联系网站管理员设为正常后进行操作！');
}
$id=!empty($_POST['id'])?intval($_POST['id']):exit("出错了，id丢失！");
$list_sql = "SELECT * FROM ".table('list')." WHERE  id=".$id." LIMIT 1";
$list_info = $db->getone($list_sql);
$uid = intval($_SESSION['uid']);
//企业下载list
if($_SESSION['utype']=="1")
{
	//查看是否是自己上传的  或者是下载过的
	if((intval($list_info['uid'])==$uid) || check_down_list($id,$_SESSION['uid']))
	{
		//插入数据
		$searchtab['uid'] = $uid;
		$searchtab['utype'] = $_SESSION['utype'];
		$searchtab['list_id'] = $id;
		$searchtab['down_time'] = time();
		if(inserttable(table('down_list'),$searchtab))
		{ 
			write_memberslog($uid,$_SESSION['utype'],1604,$_SESSION['username'],"/",$_SESSION['parentuid'],"下载通讯录,ID：{$id}",0);
			exit('ok');
		}
		else
		{
			exit("插入数据失败 ! "); 
		}
	}
	else
	{
		//下载人支付的费用 = 平台应收费用 + 上传人应收费用
		$user_account = get_user_account($_SESSION['parentuid']);
		//平台应收费用
		$website_charge = intval($list_info['price'])*round($_CFG['charge_ratio']/100,2);
		//上传人应收费用
		$uplode_charge = intval($list_info['price']) - intval($website_charge);
		if(!empty($user_account))
		{
			//账户中的资金不够
			if(intval($user_account['available_funds']) < intval($list_info['price']))
			{
				exit("资金不够！");
			}
			else
			{
				//插入数据
				$searchtab['uid'] = $uid;
				$searchtab['utype'] = $_SESSION['utype'];
				$searchtab['list_id'] = $id;
				$searchtab['down_time'] = time();
				if(inserttable(table('down_list'),$searchtab))
				{
					//下载人资金操作
					action_user_account($_SESSION['parentuid'],$_SESSION['utype'],$list_info['price'],2);
					$user_info = $db->getone("select * from ".table('members')." where uid=".$uid." limit 1");
					write_account_log($uid,$user_info['parentuid'],$_SESSION['utype'],$user_info['username'],"下载通讯录扣除金额：".$list_info['price']."元","操作成功");
					//上传人资金操作
					$mem_info = $db->getone("select * from ".table('members')." where uid=".$list_info['uid']);
					//假如上传的人是企业会员 则账户需要parentuid
					if(intval($list_info['utype'])==1)
					{
						if(empty($mem_info))
						{
							exit("查找上传人用户信息发生错误 !");
						}
						else
						{
							$acc_uid = intval($mem_info['parentuid']);
						}
					}
					else
					{
						$acc_uid = intval($list_info['uid']);
					}
					action_user_account($acc_uid,$list_info['utype'],$uplode_charge,1);
					write_account_log($list_info['uid'],$mem_info['parentuid'],$mem_info['utype'],$mem_info['username'],"通讯录收入金额：".$uplode_charge."元","充值成功");
					write_memberslog($uid,$_SESSION['utype'],1604,$_SESSION['username'],"/",$_SESSION['parentuid'],"下载通讯录,ID：{$list_id}",0);

					exit("ok");	
				}
				else
				{
					exit("插入数据失败 !");
				}
			}
		}
		else
		{
			exit("账户资金问题！");
		}
	}
}
//猎头下载list
else
{
	//查看是否是自己上传的  或者是下载过的
	if((intval($list_info['uid'])==$uid) || check_down_list($id,$_SESSION['uid']))
	{
		//插入数据
		$searchtab['uid'] = $uid;
		$searchtab['utype'] = $_SESSION['utype'];
		$searchtab['list_id'] = $id;
		$searchtab['down_time'] = time();
		if(inserttable(table('down_list'),$searchtab))
		{ 
			write_memberslog($uid,$_SESSION['utype'],1604,$_SESSION['username'],"/",0,"下载通讯录,ID：{$id}",0);
			exit('ok');
		}
		else
		{
			exit("插入数据失败 ! "); 
		}
	}
	else
	{
		//下载人支付的费用 = 平台应收费用 + 上传人应收费用
		$user_account = get_user_account($uid);
		//平台应收费用
		$website_charge = intval($list_info['price'])*round($_CFG['charge_ratio']/100,2);
		//上传人应收费用
		$uplode_charge = intval($list_info['price']) - intval($website_charge);
		if(!empty($user_account))
		{
			//账户中的资金不够
			if(intval($user_account['available_funds']) < intval($list_info['price']))
			{
				exit("资金不够！");
			}
			else
			{
				//插入数据
				$searchtab['uid'] = $uid;
				$searchtab['utype'] = $_SESSION['utype'];
				$searchtab['list_id'] = $id;
				$searchtab['down_time'] = time();
				if(inserttable(table('down_list'),$searchtab))
				{
					//下载人资金操作
					action_user_account($uid,$_SESSION['utype'],$list_info['price'],2);
					$user_info = $db->getone("select * from ".table('members')." where uid=".$uid." limit 1");
					write_account_log($uid,$user_info['parentuid'],$_SESSION['utype'],$user_info['username'],"下载通讯录扣除金额：".$list_info['price']."元","操作成功");
					//上传人资金操作
					$mem_info = $db->getone("select * from ".table('members')." where uid=".$list_info['uid']);
					//假如上传的人是企业会员 则账户需要parentuid
					if(intval($list_info['utype'])==1)
					{
						if(empty($mem_info))
						{
							exit("查找上传人用户信息发生错误 !");
						}
						else
						{
							$acc_uid = intval($mem_info['parentuid']);
						}
					}
					else
					{
						$acc_uid = intval($list_info['uid']);
					}
					action_user_account($acc_uid,$list_info['utype'],$uplode_charge,1);
					write_account_log($list_info['uid'],$mem_info['parentuid'],$mem_info['utype'],$mem_info['username'],"通讯录收入金额：".$uplode_charge."元","充值成功");
					write_memberslog($uid,$_SESSION['utype'],1604,$_SESSION['username'],"/",0,"下载通讯录,ID：{$list_id}",0);

					exit("ok");	
				}
				else
				{
					exit("插入数据失败 !");
				}
			}
		}
		else
		{
			exit("账户资金问题！");
		}
	}
}
?>