<?php
switch ($act) {
	//#####################@ 检查二级域名是否重复sql @#####################//
	case 'subdomainsql':
		$sqlwhere = " and `user_subdomain` = '{$_g_user_subdomain}' and `user_name` != '{$_s_user_name}'";
		if ($db->pe_num('user', $sqlwhere)) {
			$result = false;
		}
		else {
			$result = true;
		}
		echo json_encode(array('result'=>$result));
	break;
	//#####################@ 基本信息 @#####################//
	case 'base':
		$menumark = 'setting_base';
		$info = $db->pe_select('user', array('user_id'=>$_s_user_id));
		$info_list = $db->pe_selectall('notice', " and `notice_id` in(4,5,6)");
		$seo = pe_seo('个人资料');
		$action = "user.php?mod=setting&act=basesql";
		include(pe_tpl('setting_base.html'));
		
	break;
	//#####################@ 基本信息sql @#####################//
	case 'basesql':
		$user_name=empty($_POST['txtLoginName'])?'':addslashes(trim($_POST['txtLoginName']));
		$user_email=empty($_POST['txtEmail'])?'':addslashes(trim($_POST['txtEmail']));
		$user_qq=empty($_POST['txtQQMsn'])?'':addslashes(trim($_POST['txtQQMsn']));
		$user_phone=empty($_POST['txtMobile'])?'':addslashes(trim($_POST['txtMobile']));
		$user_gdphone=empty($_POST['txtTel'])?'':addslashes(trim($_POST['txtTel']));
		$user_province=empty($_POST['sel_province'])?'':addslashes(trim($_POST['sel_province']));
		$user_city=empty($_POST['sel_city'])?'':addslashes(trim($_POST['sel_city']));
		$user_area=empty($_POST['sel_area'])?'':addslashes(trim($_POST['sel_area']));
		$user_address=empty($_POST['txtAddress'])?'':addslashes(trim($_POST['txtAddress']));
		$user_webname=empty($_POST['txtSiteName'])?'':addslashes(trim($_POST['txtSiteName']));
		$user_weburl=empty($_POST['txtSiteURL'])?'':addslashes(trim($_POST['txtSiteURL']));
		
		$info['user_email']=$user_email;
		$info['user_qq']=$user_qq;
		$info['user_phone']=$user_phone;
		$info['user_gdphone']=$user_gdphone;
		$info['user_province']=$user_province;
		$info['user_area']=$user_area;
		$info['user_city']=$user_city;
		$info['user_address']=$user_address;
		$info['user_webname']=$user_webname;
		$info['user_weburl']=$user_weburl;
		if ($db->pe_update('user', array('user_id'=>$_s_user_id),$info)
		) {
			pe_success('个人资料修改成功！');
		}
		else {
			pe_error('个人资料修改失败...');
		}
		
	break;
		case 'cashsql':
		$user_tname=empty($_POST['txtPayeeName'])?'':addslashes(trim($_POST['txtPayeeName']));
		$user_card=empty($_POST['txtPayeeIDCode'])?'':addslashes(trim($_POST['txtPayeeIDCode']));
		$user_mode=empty($_POST['sel_SettleMethod'])?'':addslashes(trim($_POST['sel_SettleMethod']));
		$user_alipay=empty($_POST['txtSettleAccount'])?'':addslashes(trim($_POST['txtSettleAccount']));
		
		$info['user_tname']=$user_tname;
		$info['user_card']=$user_card;
		$info['user_mode']=$user_mode;
		$info['user_alipay']=$user_alipay;
		
        if ($db->pe_update('user', array('user_id'=>$_s_user_id),$info)
		) {
			pe_success('收款信息修改成功！');
		}
		else {
			pe_error('收款信息修改失败...');
		}
	break;
	case 'openvip':
		$r = $db->pe_select('setting', array('setting_key'=>'vip_point'));
		$vip=unserialize(base64_decode($r['setting_value']));
		$r = $db->pe_select('setting',array('setting_key'=>'huilv'));
		$i=unserialize(base64_decode($r['setting_value']));
		$vipneed=$vip['vip_point'];
		if($_p_dosubmit){
			if($_p_vip){
				if($user['user_level']==9)pe_alert('您已经是vip会员，无需重复开通！','user.php?mod=lesson&act=list');
				if($vipneed>$user['user_tjnum'])pe_alert('积分不够，无法开通vip会员！','user.php');
				$r = $db->pe_select('editsetting', array('name'=>'tip_buy_tj'));
				$tip=$r['content'];
				$viptj=(int)($vipneed*$i['tb']/$i['ta']);
				if($user['tj_user_num']<$viptj)pe_alert($tip,'user.php');
				$info['user_level']=9;
				if($db->pe_update('user',array('user_id'=>$_s_user_id),$info)){
					$point=0-$vipneed;
					$tjnum=0-$viptj;
					$remark='在线开通vip';
					point($_s_user_id,$point,$remark,$tjnum);
					//以下是vip提成
					if($user['user_name_tj']){
						$tj=$db->pe_select('user', array('user_name'=>$user['user_name_tj']));
					}
					if($tj['user_level']==9){
						$point=ceil($vip['vip_point']*$vip['vip_tc']);
						$tjnum=(int)($point*$i['tb']/$i['ta']);
						$remark='vip提成';
						point($tj['user_name'],$point,$remark,$tjnum);
					}
					pe_success('成功开通vip会员！','user.php?mod=setting&act=base');
				}
				else pe_error('开通vip会员失败','user.php?mod=setting&act=openvip');
			}
			else{
				pe_error('你未勾选开通vip','user.php?mod=setting&act=openvip');
			}
		}
		else{
			$menumark = 'setting_openvip';
			$vipcost=$vipneed*$i['pa']/$i['pb'];
			$seo = pe_seo('开通vip会员');
			include(pe_tpl('setting_vip.html'));
		}
	break;
	case 'vipcash':
		pe_lead('include/class/alipay.class.php');
		$pay= new alipay();
		$pay->url_r=PAY_SITE.'user.php?mod=setting&act=vipgeturl';
		$pay->url_n=PAY_SITE.'user.php?mod=setting&act=vipposturl';
		if(!$pay)pe_error('支付方式错误！');
		$_fj=round($_p_cash*$pay->payment['alipay_rate']/100,2);//手续费
		$order['username']=$_s_user_name;
		$order['email']=$_p_email?$_p_email:$user['user_email'];
		$order['order_sn']=date('YmdHis',TIME).random(4);
		$order['price']=$_p_cash+$_fj;
		$code = $pay->get_code($order);
		//添加充值记录
		$seo = pe_seo($info['page_name']);
		include(pe_tpl('pay_cash_alipay.html'));
	break;
	case 'vipgeturl':
		$r=$pay->respond();
		if($r){
			$info['brokerage_money']=$_g_total_fee;
			$info['brokerage_atime']=TIME;
			$info['user_id']=$_s_user_id;
			$info['user_name']=$_s_user_name;
			$info['user_tjlevel']='在线开通vip';
			$db->insert('brokerage',$info);
			pe_success('在线充值成功','user.php?mod=setting&act=base');
		}
		else pe_alert('在线充值失败','user.php?mod=pay&act=cash');
	break;
	//#####################@ 密码修改  @#####################//
	case 'pw':
		$menumark = 'setting_pw';
		$info = $db->pe_select('user', array('user_id'=>$_s_user_id));

		$seo = pe_seo('修改密码');
		$action = "user.php?mod=setting&act=pwsql";
		include(pe_tpl('setting_pw.html'));
	break;
	//#####################@ 密码修改sql @#####################//
	case 'pwsql':
		$old_pw=empty($_POST['txtOldPwd'])?'':addslashes(trim($_POST['txtOldPwd']));
		$new_pw=empty($_POST['txtNewPwd'])?'':addslashes(trim($_POST['txtNewPwd']));
		$new_pw2=empty($_POST['txtNewPwd2'])?'':addslashes(trim($_POST['txtNewPwd2']));
		if($old_pw=='' && $new_pw=='' ){
			pe_success('请输入原密码和新密码！');
		}
		if($new_pw!=$new_pw2){
			pe_error('确认密码不一至！');
		}
		$user_pw=md5($old_pw);
		$count=$db->pe_select('user', array('user_id'=>$_s_user_id,'user_pw'=>$user_pw));
		if($count==0){
			pe_error('原密码输入错误！');
		}
		elseif($db->pe_update('user', array('user_id'=>$_s_user_id),array('user_pw'=>md5($new_pw)))){
			pe_success('密码修改成功！');
		}else{
			pe_success('密码修改成功！');
		}
	break;
	//#####################@ 推广联盟  @#####################//
	case 'tg':
		$menumark = 'setting_tg';
		
		$info = $db->pe_select('user', array('user_id'=>$_s_user_id));
	
		$info_list = $db->pe_selectall('package');

		/*$maindomain_arr = explode('.', $pe['host_root']);
		//http://www.phpshe.com.cn
		if (count($maindomain_arr)==4 && stristr($maindomain_arr[0], 'www') !== false) {
			$maindomain = str_ireplace('http://www', "http://{$info['user_subdomain']}", $maindomain_arr[0]).".{$maindomain_arr[1]}.{$maindomain_arr[2]}.{$maindomain_arr[3]}";
		}
		//http://www.phpshe.com
		elseif (count($maindomain_arr)==3 && stristr($maindomain_arr[0], 'www') !== false) {
			$maindomain = str_ireplace('http://www', "http://{$info['user_subdomain']}", $maindomain_arr[0]).".{$maindomain_arr[1]}.{$maindomain_arr[2]}";
		}
		//http://phpshe.com.cn
		elseif (count($maindomain_arr)==3 && stristr($maindomain_arr[0], 'www') === false) {
			$maindomain = str_ireplace('http://', "http://{$info['user_subdomain']}.", $maindomain_arr[0]).".{$maindomain_arr[1]}.{$maindomain_arr[2]}";
		}
		//http://phpshe.com
		else {
			$maindomain = str_ireplace('http://', "http://{$info['user_subdomain']}.", $maindomain_arr[0]).".{$maindomain_arr[1]}";		
		}*/
		//只有一个套餐的时候
		$maindomain = "http://{$info['user_subdomain']}.{$pe['domain_mark']}/";
		//有多个套餐的时候
		$maindomain_many = $pe['url_model']=='pathinfo_safe' ? "{$maindomain}index.php/" : $maindomain;

		$seo = pe_seo('推广联盟');
		$action = "user.php?mod=setting&act=tg";
		include(pe_tpl('setting_tg.html'));
	break;
}
pe_result();
?>