<?php
require(dirname(__FILE__) .'/check.php');
$skin->CheckIframe();


/* **** 版权所有 ****

 程序开发：网钛科技
 网钛CMS官网：http://otcms.com
 网钛IDC官网：http://idccms.com
 ＱＱ：877873666
 微信：QQ877873666
 邮箱：877873666@qq.com

 **** 版权所有 **** */

//用户检测
$MB->Open('','login',10);



switch ($mudi){
	case 'add':
		$menuFileID = 184;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'rev':
		$menuFileID = 187;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		AddOrRev();
		break;

	case 'export':
		$menuFileID = 185;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		AppUserExport::ParamDeal();
		break;

	case 'exportInfo':
		$menuFileID = 185;
		$MB->IsSecMenuRight('alertClose',$menuFileID,$dataType);
		AppUserExport::InfoDeal();
		break;

	case 'del':
		$menuFileID = 188;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		del();
		break;

	case 'moreDel':
		$menuFileID = 188;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreDel();
		break;

	case 'revInfo':
		$menuFileID = 187;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		RevInfo();
		break;

	case 'updateInfo':
		$menuFileID = 187;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		UpdateInfo();
		break;

	case 'groupMove':
		$menuFileID = 187;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		GroupMoveDeal();
		break;

	case 'moreSet':
		$menuFileID = 187;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		MoreSetDeal();
		break;

	case 'updateCount':
		$menuFileID = 185;
		$MB->IsSecMenuRight('alertBack',$menuFileID,$dataType);
		UpdateCount();
		break;

	case 'setState':
		$menuFileID = 185;
		$MB->IsSecMenuRight('alert',$menuFileID,$dataType);
		SetState();
		break;

	default:
		die('err');
}

$MB->Close();
$DB->Close();





// 新增/修改会员信息
function AddOrRev(){
	global $DB,$mudi,$dataType,$dataTypeCN;

	$backURL	= OT::PostStr('backURL');
	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$dataID		= OT::PostInt('dataID');
	$scoreOld1	= OT::PostInt('scoreOld1');
	$scoreOld2	= OT::PostInt('scoreOld2');
	$scoreOld3	= OT::PostInt('scoreOld3');
	$recomUserOld	= OT::PostStr('recomUserOld');

	$groupID	= OT::PostInt('groupID');
	$isGroupTime= OT::PostInt('isGroupTime');
	$groupTime	= OT::PostStr('groupTime');
	$authStr	= OT::Post('authStr');
		if (is_array($authStr)){ $authStr = implode('',$authStr); }
	$username	= OT::PostRegExpStr('username','sql');
	$userpwd	= OT::PostStr('userpwd');
	$mail		= OT::PostStr('mail');
	$question	= OT::PostStr('question');
	$answer		= OT::PostStr('answer');
	$realname	= OT::PostStr('realname');
	$sex		= OT::PostStr('sex');
	$city		= OT::PostStr('city');
	$address	= OT::PostStr('address');
	$postCode	= OT::PostStr('postCode');
	$phone		= OT::PostStr('phone');
	$fax		= OT::PostStr('fax');
	$qq			= str_replace('，',',',OT::PostStr('qq'));
	$ww			= OT::PostStr('ww');
	$weixin		= OT::PostStr('weixin');
	$alipay		= OT::PostStr('alipay');
	$cardType	= OT::PostStr('cardType');
	$cardUser	= OT::PostStr('cardUser');
	$cardID		= OT::PostStr('cardID');
	$cardImg	= OT::PostStr('cardImg');
	$cardImg2	= OT::PostStr('cardImg2');
	$cardState	= OT::PostInt('cardState');
		if (in_array($cardState, array(1,11,21))){
			$authStr .= '|实名认证|';
		}elseif ($cardState == 2){
			$authStr .= '|实名审核|';
		}
	$web		= OT::PostStr('web');
	$note		= OT::PostStr('note');
	$adminNote	= OT::PostStr('adminNote');
	$pageNum	= OT::PostInt('pageNum');
	$pageWapNum	= OT::PostInt('pageWapNum');
	$event		= OT::Post('event');
		if (is_array($event)){ $event = implode(',',$event); }
	$isAgent	= OT::PostInt('isAgent');
	$apiKey		= OT::PostStr('apiKey');
	$phpUserID	= OT::PostInt('phpUserID');
	$state		= OT::PostInt('state');
	$isRevScore	= OT::PostInt('isRevScore');
	$score1		= OT::PostInt('score1');
	$score2		= OT::PostInt('score2');
	$score3		= OT::PostInt('score3');
	$isRevQiandao	= OT::PostInt('isRevQiandao');
	$qiandaoTime	= OT::PostStr('qiandaoTime');
	$qiandaoNum		= OT::PostInt('qiandaoNum');
	$qiandaoTotal	= OT::PostInt('qiandaoTotal');
	$isRevRecom	= OT::PostInt('isRevRecom');
	$recomUser	= OT::PostStr('recomUser');

	if ($username == ''){
		JS::AlertBackEnd('表单数据接收不全');
	}

	$checkexe=$DB->query('select UE_ID from '. OT_dbPref .'users where UE_username='. $DB->ForStr($username) .' and UE_ID<>'. $dataID .' limit 1');
		if ($checkexe->fetch()){
			JS::AlertBackEnd('该用户名已被占用');
		}
	unset($checkexe);

	$todayTime	= TimeDate::Get();
	$userIP		= Users::GetIp();
	$record=array();
	$record['UE_groupID']		= $groupID;
	$record['UE_isGroupTime']	= $isGroupTime;
	if (strtotime($groupTime)){ $record['UE_groupTime'] = $groupTime; }
	$record['UE_authStr']		= $authStr;
	$record['UE_username']		= $username;
	if ($userpwd != ''){
		$userKey = OT::RndChar(5);
		$record['UE_userpwd']	= md5(md5($userpwd) . $userKey);
		$record['UE_userKey']	= $userKey;
	}
	$record['UE_question']		= $question;
	if ($answer!=''){
		$answerKey = OT::RndChar(5);
		$record['UE_answer']	= md5(md5($answer) . $answerKey);
		$record['UE_answerKey']	= $answerKey;
	}
	$record['UE_mail']			= $mail;
	$record['UE_realname']		= $realname;
	$record['UE_sex']			= $sex;
	$record['UE_city']			= $city;
	$record['UE_address']		= $address;
	$record['UE_postCode']		= $postCode;
	$record['UE_phone']			= $phone;
	$record['UE_fax']			= $fax;
	$record['UE_qq']			= $qq;
	$record['UE_ww']			= $ww;
	$record['UE_weixin']		= $weixin;
	$record['UE_alipay']		= $alipay;
	$record['UE_cardType']		= $cardType;
	$record['UE_cardUser']		= $cardUser;
	$record['UE_cardID']		= $cardID;
	$record['UE_cardImg']		= $cardImg;
	$record['UE_cardImg2']		= $cardImg2;
	$record['UE_cardState']		= $cardState;
	$record['UE_web']			= $web;
	$record['UE_note']			= $note;
	$record['UE_adminNote']		= $adminNote;
	$record['UE_pageNum']		= $pageNum;
	$record['UE_pageWapNum']	= $pageWapNum;
	$record['UE_event']			= $event;
	$record['UE_isAgent']		= $isAgent;
	$record['UE_apiKey']		= Encrypt::SyEnDe('en',$apiKey);
	$record['UE_phpUserID']		= $phpUserID;
	$record['UE_state']			= $state;
	if ($isRevScore == 1){
		$record['UE_score1']	= $score1;
		$record['UE_score2']	= $score2;
		$record['UE_score3']	= $score3;
	}
	if ($isRevQiandao == 1){
		$record['UE_qiandaoTime']	= $qiandaoTime;
		$record['UE_qiandaoNum']	= $qiandaoNum;
		$record['UE_qiandaoTotal']	= $qiandaoTotal;
	}

	// 邀请人
	$addRecomId = 0;
	if ($isRevRecom == 1 && $recomUserOld != $recomUser && AppRecom::Jud()){
		$recomLevel = 1;
		$recomId = 0;
		$recomIdList = ',';
		if (strlen($recomUser) > 0){
			$recomRow = $DB->GetRow('select UE_ID,UE_username,UE_recomLevel,UE_recomIdList from '. OT_dbPref .'users where UE_username='. $DB->ForStr($recomUser));
				if (! $recomRow){
					JS::AlertBackEnd('该邀请人不存在，请检查清楚，如果无邀请人请留空');
				}
			$recomLevel	= $recomRow['UE_recomLevel'] + 1;
			$recomId	= $recomRow['UE_ID'];
			$recomUser	= $recomRow['UE_username'];
			$recomIdList = $recomRow['UE_recomIdList'] . $recomId .',';
			$addRecomId = $recomRow['UE_ID'];
		}
		$record['UE_recomType']		= 'admin';
		$record['UE_recomId']		= $recomId;
		$record['UE_recomUser']		= $recomUser;
		$record['UE_recomIdList']	= $recomIdList;
		$record['UE_recomLevel']	= $recomLevel;
		$record['UE_recomTime']		= $todayTime;
	}

	if ($dataID == 0){
		$record['UE_time']			= $todayTime;
		$record['UE_loginTime']		= '2008-08-08 08:08:08';
		$record['UE_regType']		= 'back';
		$record['UE_regIP']			= $userIP;
		$record['UE_apiStr']		= '|web:::1|';

		$alertMode = '新增';
		$judRes = $DB->InsertParam('users',$record);
			if ($judRes){
				if (AppUserScore::IsAdd($score1, $score2, $score3)){
					$dataID = $DB->GetOne('select max(UE_ID) from '. OT_dbPref .'users');
					$scoreArr = array();
					$scoreArr['UM_userID']		= $dataID;
					$scoreArr['UM_username']	= $username;
					$scoreArr['UM_type']		= 'reg';
					$scoreArr['UM_score1']		= $score1;
					$scoreArr['UM_score2']		= $score2;
					$scoreArr['UM_score3']		= $score3;
					$scoreArr['UM_remScore1']	= $score1;
					$scoreArr['UM_remScore2']	= $score2;
					$scoreArr['UM_remScore3']	= $score3;
					$scoreArr['UM_note']		= '后台注册成功';
					AppUserScore::AddData($scoreArr);
				}
			}
	}else{
		$alertMode = '修改';
		$judRes = $DB->UpdateParam('users',$record,'UE_ID='. $dataID);
			if ($judRes){
				if (AppUserScore::IsAdd($scoreOld1-$score1, $scoreOld2-$score2, $scoreOld3-$score3)){
					$scoreArr = array();
					$scoreArr['UM_userID']		= $dataID;
					$scoreArr['UM_username']	= $username;
					$scoreArr['UM_type']		= 'admin';
					$scoreArr['UM_score1']		= $score1-$scoreOld1;
					$scoreArr['UM_score2']		= $score2-$scoreOld2;
					$scoreArr['UM_score3']		= $score3-$scoreOld3;
					$scoreArr['UM_remScore1']	= $score1;
					$scoreArr['UM_remScore2']	= $score2;
					$scoreArr['UM_remScore3']	= $score3;
					$scoreArr['UM_note']		= '管理员后台对您进行积分调整';
					AppUserScore::AddData($scoreArr);
				}
			}
	}
	
	if ($judRes){
		$alertRes = '成功';
		if (AppRecom::Jud()){
			AppRecom::UpdateFatRecomNum($addRecomId, $state);
			if ($state == 1){
				if ($dataID == 0){ $dataID = $DB->GetOne('select max(UE_ID) from '. OT_dbPref .'users'); }
				AppRecom::AuditScore($dataID);
			}
		}
	}else{
		$alertRes = '失败';
	}

	Adm::AddLog(array(
		'theme'	=> $username,
		'note'	=> '【'. $dataTypeCN .'】'. $alertMode . $alertRes .'！',
		));

	JS::AlertHref(''. $alertMode . $alertRes .'.',$backURL);
}



// 删除
function del(){
	global $DB,$dataType,$dataTypeCN;

	$dataID		= OT::GetInt2( OT::ParaArr('id') );
	$theme		= OT::GetStr('theme');

	if ($dataID <= 0){
		JS::AlertEnd('指定ID错误');
	}

	$row = $DB->GetRow('select UE_ID,UE_money from '. OT_dbPref .'users where UE_ID='. $dataID);
		if ($row['UE_money'] > 0){
			JS::AlertEnd('该会员有余额 '. $row['UE_money'] .' 元，禁止删除');
		}

	// 域名数量
	if (AppDomain::Jud()){
		$domainNum = $DB->GetOne('select count(DD_ID) from '. OT_dbPref .'domainData where DD_userID='. $dataID);
			if ($domainNum > 0){
				JS::AlertEnd('该会员有'. $domainNum .'个域名，禁止删除');
			}
	}

	// 虚拟主机数量
	if (AppHost::Jud()){
		$hostNum = $DB->GetOne('select count(HU_ID) from '. OT_dbPref .'hostUsers where HU_userID='. $dataID);
			if ($hostNum > 0){
				JS::AlertEnd('该会员有'. $hostNum .'台虚拟主机，禁止删除');
			}
	}

	// 云服务器数量
	if (AppVpsApi::Jud()){
		$vpsApiNum = $DB->GetOne('select count(VAU_ID) from '. OT_dbPref .'vpsApiUsers where VAU_userID='. $dataID);
			if ($vpsApiNum > 0){
				JS::AlertEnd('该会员有'. $vpsApiNum .'台云服务器，禁止删除');
			}
	}

	// 拨号VPS数量
	if (AppDialing::Jud()){
		$dialingNum = $DB->GetOne('select count(DU_ID) from '. OT_dbPref .'dialingUsers where DU_userID='. $dataID);
			if ($dialingNum > 0){
				JS::AlertEnd('该会员有'. $dialingNum .'台拨号VPS，禁止删除');
			}
	}

	// PPTP数量
	if (AppPptp::Jud()){
		$pptpNum = $DB->GetOne('select count(PU_ID) from '. OT_dbPref .'pptpUsers where PU_userID='. $dataID);
			if ($pptpNum > 0){
				JS::AlertEnd('该会员有'. $pptpNum .'台PPTP，禁止删除');
			}
	}

	// 服务器租用数量
	if (AppServ::Jud()){
		$servNum = $DB->GetOne('select count(SU_ID) from '. OT_dbPref .'servUsers where SU_userID='. $dataID);
			if ($servNum > 0){
				JS::AlertEnd('该会员有'. $servNum .'台服务器租用，禁止删除');
			}
	}

	$judRes = $DB->query('delete from '. OT_dbPref .'users where UE_ID='. $dataID);
		if ($judRes){
			$alertRes = '成功';

			if (AppUserView::Jud()){	// 会员文章浏览记录
				$DB->query('delete from '. OT_dbPref .'userView where UV_userID='. $dataID .' and UV_type='. $DB->ForStr('user'));
			}
			if (AppUserMark::Jud()){	// 会员文章收藏记录
				$DB->query('delete from '. OT_dbPref .'userMark where UM_userID='. $dataID .' and UM_type='. $DB->ForStr('user'));
			}
			if (AppInfoDown::Jud()){	// 会员文章下载记录
				$DB->query('delete from '. OT_dbPref .'infoDown where ID_userID='. $dataID);
			}
			/*
			if (AppReport::Jud()){		// 举报功能
				$DB->query('delete from '. OT_dbPref .'report where RP_dataID='. $dataID .' and RP_type='. $DB->ForStr('user'));
			}
			if (SiteMessage::Jud()){	// 站内信息
				$DB->query('delete from '. OT_dbPref .'siteMessage where SM_userID='. $dataID);
			}
			*/
		}else{
			$alertRes = '失败';
		}

	Adm::AddLog(array(
		'title'	=> '用户名',
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】删除'. $alertRes .'！',
		));

	JS::ParentHiddenEnd('data'. $dataID);
}



// 批量删除
function MoreDel(){
	global $DB;

	$dataType	= OT::PostStr('dataType');
	$dataTypeCN	= OT::PostStr('dataTypeCN');
	$backURL	= OT::PostStr('backURL');
	$selDataID	= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要删除的记录.');
	}

	$succNum = $failNum = 0;
	$chkexe = $DB->query('select UE_ID,UE_money from '. OT_dbPref .'users where UE_ID in (0'. $whereStr .')');
	while ($row = $chkexe->fetch()){
		$dataID = $row['UE_ID'];

		if ($row['UE_money'] > 0){
			$failNum ++; continue;
		}

		// 域名数量
		if (AppDomain::Jud()){
			$domainNum = $DB->GetOne('select count(DD_ID) from '. OT_dbPref .'domainData where DD_userID='. $dataID);
				if ($domainNum > 0){ $failNum ++; continue; }
		}

		// 虚拟主机数量
		if (AppHost::Jud()){
			$hostNum = $DB->GetOne('select count(HU_ID) from '. OT_dbPref .'hostUsers where HU_userID='. $dataID);
				if ($hostNum > 0){ $failNum ++; continue; }
		}

		// 云服务器数量
		if (AppVpsApi::Jud()){
			$vpsApiNum = $DB->GetOne('select count(VAU_ID) from '. OT_dbPref .'vpsApiUsers where VAU_userID='. $dataID);
				if ($vpsApiNum > 0){ $failNum ++; continue; }
		}

		// 拨号VPS数量
		if (AppDialing::Jud()){
			$dialingNum = $DB->GetOne('select count(DU_ID) from '. OT_dbPref .'dialingUsers where DU_userID='. $dataID);
				if ($dialingNum > 0){ $failNum ++; continue; }
		}

		// PPTP数量
		if (AppPptp::Jud()){
			$pptpNum = $DB->GetOne('select count(PU_ID) from '. OT_dbPref .'pptpUsers where PU_userID='. $dataID);
				if ($pptpNum > 0){ $failNum ++; continue; }
		}

		// 服务器租用数量
		if (AppServ::Jud()){
			$servNum = $DB->GetOne('select count(SU_ID) from '. OT_dbPref .'servUsers where SU_userID='. $dataID);
				if ($servNum > 0){ $failNum ++; continue; }
		}

		$judRes = $DB->query('delete from '. OT_dbPref .'users where UE_ID='. $dataID);
			if ($judRes){
				$succNum ++;
			}else{
				$failNum ++;
			}
	}
	unset($chkexe);

	/* 
	$judRes = $DB->query('delete from '. OT_dbPref .'users where UE_ID in (0'. $whereStr .')');
		if ($judRes){
			$alertRes = '成功';
		}else{
			$alertRes = '失败';
		}
	*/

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量删除完成，成功'. $succNum .'条，失败'. $failNum .'条！',
		));

	JS::AlertHrefEnd('批量删除完成，成功'. $succNum .'条，失败'. $failNum .'条.',$backURL);

}



// 修改信息
function RevInfo(){
	global $DB,$dataType,$dataTypeCN;

	$theme		= OT::GetStr('theme');
	$userID		= OT::GetInt('userID');
	$mode		= OT::GetStr('mode');
	$type		= OT::GetStr('type');

	$record = array();
	switch ($mode){
		case 'state':
			$revName = '状态';
			$state	= OT::GetInt('state');
			$record['UE_state'] = $state;
			if ($state == 0){ $revStr = '未审核'; }else{ $revStr = '已审核'; }
			break;
	
		case 'qiandaoTime':
			$revName = '签到时间';
			$qiandaoTime	= OT::GetStr('qiandaoTime');
			$record['UE_qiandaoTime'] = $qiandaoTime;
			$revStr = $qiandaoTime;
			break;
	
		case 'recomTime':
			$revName = '推荐更新时间';
			$recomTime	= OT::GetStr('recomTime');
			$record['UE_recomTime'] = $recomTime;
			$revStr = $recomTime;
			break;
	
		case 'recomUser':
			$revName = '更换推荐人';
			$recomUser	= OT::GetStr('recomUser');
			// 获取好友邀请注册侧信息
			list($recomType, $recomId, $recomUser, $recomLevel, $recomIdList) = AppRecom::GetRegArr('admin');
			if ($recomId > 0 && strlen($recomUser) > 0){
				$record['UE_recomType']		= $recomType;
				$record['UE_recomId']		= $recomId;
				$record['UE_recomUser']		= $recomUser;
				$record['UE_recomIdList']	= $recomIdList;
				$record['UE_recomLevel']	= $recomLevel;
				$record['UE_recomTime']		= TimeDate::Get();
			}else{
				print_r($_GET);die();
				JS::AlertEnd('找不到该推荐人信息，请检查清楚.'. $recomUser);
			}
			$revStr = $recomUser;
			break;
	
		case 'apiStr':
			$revName = '快捷登录';
			switch ($type){
				case 'qq':		$revStr = '解除QQ绑定';		break;
				case 'weibo':	$revStr = '解除新浪微博绑定';	break;
				case 'weixin':	$revStr = '解除微信绑定';	break;
				default :	JS::AlertEnd('type参数不明（'. $type .'）.');	break;
			}

			$UE_apiStr = $DB->GetOne('select UE_apiStr from '. OT_dbPref .'users where UE_ID='. $userID);

			if (strpos($UE_apiStr,'|web:::') === false){
				JS::AlertEnd('检查到该账户登录密码尚未初始化，请初始化(修改)登录密码才能做解除绑定操作.');
			}

			$signStart = strpos($UE_apiStr,'|'. $type .'::');
			if ($signStart === false){
				JS::AlertEnd('该账号早已解除绑定或者还未绑定过，请刷新页面重新操作下.');
			}
			$apiStr = Str::GetMark($UE_apiStr,'|'. $type .'::','|',true,true);
			$UE_apiStr = str_replace($apiStr, '', $UE_apiStr);
			if ($type == 'weixin'){
				$apiStr = Str::GetMark($UE_apiStr,'|'. $type .'2::','|',true,true);
				if (strlen($apiStr) > 5){ $UE_apiStr = str_replace($apiStr, '', $UE_apiStr); }
			}

			$record['UE_apiStr'] = $UE_apiStr;
			break;
	
		default :
			JS::AlertEnd('类型错误');
			break;
	}

	$judRes = $DB->UpdateParam('users', $record, 'UE_ID='. $userID);
		if ($judRes){
			$alertRes = '成功';
			if ($mode == 'recomUser'){
				AppRecom::UpdateFatRecomNum($recomId, 1);
			}
		}else{
			$alertRes = '失败';
		}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】设置'. $revName .'{'. $revStr .'}'. $alertRes .'！',
		));

	echo('
	<script language="javascript" type="text/javascript">
	alert("设置'. $revName .'（'. $revStr .'）'. $alertRes .'");parent.document.location.reload();
	</script>
	');
}



// 更新信息
function UpdateInfo(){
	global $DB,$dataType,$dataTypeCN;

	$theme		= OT::GetStr('theme');
	$mode		= OT::GetStr('mode');

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	switch ($mode){
		case 'recomLevel':
			$theme = '重新更新推荐级别';
			$runNum = 0;
			// 没有邀请人设为级别1
			$DB->query('update '. OT_dbPref .'users set UE_recomLevel=1 where UE_recomId=0 or UE_recomLevel=0');

			// 更新用户级别、邀请人ID和用户名
			$chkexe = $DB->query('select UE_ID,UE_username,UE_recomId from '. OT_dbPref .'users where UE_recomId>=1 order by UE_ID ASC');
			while ($row = $chkexe->fetch()){
				$recomRow = $DB->GetRow('select UE_ID,UE_recomLevel,UE_username from '. OT_dbPref .'users where UE_ID='. $row['UE_recomId']);
				if ($recomRow['UE_recomLevel'] > 0){
					$runNum ++;
					$DB->query('update '. OT_dbPref .'users set UE_recomLevel='. ($recomRow['UE_recomLevel']+1) .',UE_recomUser='. $DB->ForStr($recomRow['UE_username']) .' where UE_ID='. $row['UE_ID']);
				}
			}
			$chkexe = null;
			break;
	
		case 'recomIdList':
			$theme = '重新更新邀请人ID列表';
			$runNum = 0;
			$chkexe = $DB->query('select UE_ID,UE_recomId from '. OT_dbPref .'users where UE_recomLevel=1');
			while ($row = $chkexe->fetch()){
				$runNum ++;
				$DB->query('update '. OT_dbPref .'users set UE_recomIdList='. $DB->ForStr(',') .' where UE_ID='. $row['UE_ID']);
			}
			$chkexe = null;

			$chkexe = $DB->query('select UE_ID,UE_recomId from '. OT_dbPref .'users where UE_recomLevel=2');
			while ($row = $chkexe->fetch()){
				$runNum ++;
				$DB->query('update '. OT_dbPref .'users set UE_recomIdList='. $DB->ForStr(','. $row['UE_recomId'] .',') .' where UE_ID='. $row['UE_ID']);
			}
			$chkexe = null;

			$chkexe = $DB->query('select UE_ID,UE_recomId from '. OT_dbPref .'users where UE_recomLevel>=3 order by UE_recomLevel ASC');	//  and UE_recomIdList is null
			while ($row = $chkexe->fetch()){
				$recomRow = $DB->GetRow('select UE_recomIdList from '. OT_dbPref .'users where UE_ID='. $row['UE_recomId']);
				if (strlen($recomRow['UE_recomIdList']) > 0){
					$runNum ++;
					$DB->query('update '. OT_dbPref .'users set UE_recomIdList='. $DB->ForStr($recomRow['UE_recomIdList'] . $row['UE_recomId'] .',') .' where UE_ID='. $row['UE_ID']);
				}
			}
			$chkexe = null;
			break;
	
		case 'recomNum':
			$theme = '重新统计团队人数';
			$runNum = 0;
			$todayTime	= TimeDate::Get();
			$chkexe = $DB->query('select UE_ID,UE_recomLevel from '. OT_dbPref .'users where UE_recomTime<='. $DB->ForTime(TimeDate::Add('min',-30,$todayTime)));
			while ($row = $chkexe->fetch()){
				$runNum ++;
				$recomNum1 = intval($DB->GetOne('select count(1) from '. OT_dbPref .'users where UE_recomId='. $row['UE_ID']));
				$recomNum11 = intval($DB->GetOne('select count(1) from '. OT_dbPref .'users where UE_recomId='. $row['UE_ID'] .' and UE_state=1'));
				$recomNum2 = intval($DB->GetOne('select count(1) from '. OT_dbPref .'users where UE_recomLevel='. ($row['UE_recomLevel']+2) .' and UE_recomIdList like "%,'. $row['UE_ID'] .',%"'));
				$recomNum12 = intval($DB->GetOne('select count(1) from '. OT_dbPref .'users where UE_recomLevel='. ($row['UE_recomLevel']+2) .' and UE_state=1 and UE_recomIdList like "%,'. $row['UE_ID'] .',%"'));
				
				$DB->query('update '. OT_dbPref .'users set UE_recomNum1='. $recomNum1 .',UE_recomNum11='. $recomNum11 .',UE_recomNum2='. $recomNum2 .',UE_recomNum12='. $recomNum12 .',UE_recomTime='. $DB->ForTime($todayTime) .' where UE_ID='. $row['UE_ID']);
			}
			$chkexe = null;
			break;
	
		default :
			JS::AlertEnd('类型错误');
			break;
	}

	Adm::AddLog(array(
		'theme'	=> $theme,
		'note'	=> '【'. $dataTypeCN .'】'. $theme .' 影响会员数 '. $runNum .'！',
		));

	JS::Alert(''. $theme .' 影响会员数 '. $runNum .'！');
}



// 会员组批量移动
function GroupMoveDeal(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN,$systemArr;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$groupMoveTo	= OT::PostInt('groupMoveTo');
	$groupMoveToCN	= OT::PostRegExpStr('groupMoveToCN','sql');
	$selDataID		= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要移动的会员.');
	}
	if ($groupMoveTo <= 0){
		JS::AlertBackEnd('请选择批量移动的会员组.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要移动的会员.');
	}

	$judRes = $DB->query('update '. OT_dbPref .'users set UE_groupID='. $groupMoveTo .' where UE_ID in (0'. $whereStr .')');
	if ($judRes){
		$alertRes = '成功';
	}else{
		$alertRes = '失败';
	}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】会员组批量移动到['. $groupMoveToCN .']'. $alertRes .'！',
		));

	JS::AlertHref('会员组批量移动'. $alertRes .'.',$backURL);
}



// 批量设置
function MoreSetDeal(){
	global $DB,$mudi,$menuFileID,$menuTreeID,$dataType,$dataTypeCN,$systemArr;

	$backURL		= OT::PostStr('backURL');
	$dataType		= OT::PostStr('dataType');
	$dataTypeCN		= OT::PostStr('dataTypeCN');
	$moreSetTo		= OT::PostRegExpStr('moreSetTo','sql');
	$moreSetToCN	= OT::PostRegExpStr('moreSetToCN','sql');
	$selDataID		= OT::Post('selDataID');

	$selCount = OT::NewCount($selDataID);
	if ($selCount <= 0){
		JS::AlertBackEnd('请先选择要设置的记录.');
	}
	if ($moreSetTo==''){
		JS::AlertBackEnd('请选择批量设置的操作.');
	}

	$whereStr = '';
	for ($i=0; $i<$selCount; $i++){
		$whereStr .= ','. intval($selDataID[$i]);
	}
	if ($whereStr == ''){
		JS::AlertBackEnd('请先选择要设置的记录.');
	}

	if (in_array($moreSetTo, array('groupTime1','groupTime0','state1','state0','state9','shiming0','shiming1','shiming2','shiming3'))){
		$whereStr2 = '';
		switch ($moreSetTo){
			case 'groupTime1':		$dealStr = 'UE_isGroupTime=1';	break;
			case 'groupTime0':		$dealStr = 'UE_isGroupTime=0';	break;
			case 'state1':			$dealStr = 'UE_state=1';		break;
			case 'state0':			$dealStr = 'UE_state=0';		break;
			case 'state9':			$dealStr = 'UE_state=9';		break;
			case 'shiming0':	// 未提交
				$dealStr = 'UE_cardState=0';
				break;
			case 'shiming1':	// 手动审核通过
				$dealStr = 'UE_cardState=1';
				$whereStr2 = ' and UE_cardState in (1,2)';
				break;
			case 'shiming2':	// 待审核
				$dealStr = 'UE_cardState=2';
				$whereStr2 = ' and UE_cardState in (1,3)';
				break;
			case 'shiming3':	// 审核拒绝
				$dealStr = 'UE_cardState=3';
				$whereStr2 = ' and UE_cardState=2';
				break;
		}

		if (in_array($moreSetTo,array('shiming0','shiming1','shiming2','shiming3'))){
			// 0未提交、1手动审核通过、2待审核、3审核拒绝、11微信实名、21支付宝实名
			$succNum = $failNum = 0;
			$cardexe = $DB->query('select UE_ID,UE_cardState,UE_authStr from '. OT_dbPref .'users where UE_ID in (0'. $whereStr .')'. $whereStr2);
			while ($crs = $cardexe->fetch()){
				$authStr = str_replace(array('|实名认证|','|实名审核|'),'',$crs['UE_authStr']);
				if ($moreSetTo == 'shiming1'){		// 手动审核通过
					$authStr .= '|实名认证|';
				}elseif ($moreSetTo == 'shiming2'){	// 待审核
					$authStr .= '|实名审核|';
				}
				$judRes = $DB->query('update '. OT_dbPref .'users set '. $dealStr .',UE_authStr='. $DB->ForStr($authStr) .' where UE_ID='. $crs['UE_ID']);
				if ($judRes){
					$succNum ++;
				}else{
					$failNum ++;
				}
			}
			unset($cardexe);
			$alertRes = '完成（成功'. $succNum .'条，失败'. $failNum .'条）';
		}else{
			$count = $DB->GetOne('select count(1) from '. OT_dbPref .'users where UE_ID in (0'. $whereStr .')'. $whereStr2);
			$judRes = $DB->query('update '. OT_dbPref .'users set '. $dealStr .' where UE_ID in (0'. $whereStr .')'. $whereStr2);
			if ($judRes){
				$alertRes = '成功（'. $count .'条）';
			}else{
				$alertRes = '失败';
			}
		}

	}else{
		$succNum = $failNum = 0;
		$loadexe = $DB->query('select UE_ID,UE_authStr from '. OT_dbPref .'users where UE_ID in (0'. $whereStr .')');
		while ($row = $loadexe->fetch()){
			$authStr = $row['UE_authStr'];
			switch ($moreSetTo){
				case 'mailAudit1':		$dealIs = 1; $dealStr = '|邮箱|';		break;
				case 'mailAudit0':		$dealIs = 0; $dealStr = '|邮箱|';		break;
				case 'phoneAudit1':		$dealIs = 1; $dealStr = '|手机|';		break;
				case 'phoneAudit0':		$dealIs = 0; $dealStr = '|手机|';		break;
				default :
					JS::AlertBackEnd('目的不明确（'. $moreSetTo .'）.');
					break;
			}
			if ($dealIs == 1){
				if (strpos($authStr,$dealStr) !== false){
					continue;
				}else{
					$authStr .= $dealStr;
				}
			}else{
				if (strpos($authStr,$dealStr) !== false){
					$authStr = str_replace($dealStr,'',$authStr);
				}else{
					continue;
				}
			}
			$jud = $DB->query('update '. OT_dbPref .'users set UE_authStr='. $DB->ForStr($authStr) .' where UE_ID='. $row['UE_ID']);
			if ($jud){ $succNum ++; }else{ $failNum ++; }
		}
		unset($loadexe);

		$alertRes = '完成（成功'. $succNum .'条，失败'. $failNum .'条）';
	}

	Adm::AddLog(array(
		'note'		=> '【'. $dataTypeCN .'】批量设置成['. $moreSetToCN .']'. $alertRes .'！',
		));

	JS::AlertHref('批量设置'. $alertRes .'.',$backURL);
}



// 更新统计
function UpdateCount(){
	global $DB,$dataType,$dataTypeCN;

	@ini_set('max_execution_time', 0);
	@set_time_limit(0); 

	$runNum = 0;
	$chkexe = $DB->query('select UE_ID from '. OT_dbPref .'users');
	while ($row = $chkexe->fetch()){
		$runNum ++;
		$dataArr = array();
		$dataArr['UE_newsCount'] = $DB->GetOne('select count(IF_ID) from '. OT_dbPref .'info where IF_userID='. $row['UE_ID']);
		$dataArr['UE_domainNum'] = $DB->GetOne('select count(DD_ID) from '. OT_dbPref .'domainData where DD_userID='. $row['UE_ID']);
		$dataArr['UE_hostNum'] = $DB->GetOne('select count(HU_ID) from '. OT_dbPref .'hostUsers where HU_userID='. $row['UE_ID']);
		$dataArr['UE_vpsApiNum'] = $DB->GetOne('select count(VAU_ID) from '. OT_dbPref .'vpsApiUsers where VAU_userID='. $row['UE_ID']);
		$dataArr['UE_dialingNum'] = $DB->GetOne('select count(DU_ID) from '. OT_dbPref .'dialingUsers where DU_userID='. $row['UE_ID']);
		$dataArr['UE_pptpNum'] = $DB->GetOne('select count(PU_ID) from '. OT_dbPref .'pptpUsers where PU_userID='. $row['UE_ID']);
		$dataArr['UE_servNum'] = $DB->GetOne('select count(SU_ID) from '. OT_dbPref .'servUsers where SU_userID='. $row['UE_ID']);
		$dataArr['UE_sslNum'] = $DB->GetOne('select count(SU_ID) from '. OT_dbPref .'sslUsers where SU_userID='. $row['UE_ID']);
		$judRes = $DB->UpdateParam('users',$dataArr,'UE_ID='. $row['UE_ID']);
	}
	unset($chkexe);

	Adm::AddLog(array(
		'note'	=> '【'. $dataTypeCN .'】批量更新文章数统计 影响会员数 '. $runNum .'！',
		));

	JS::AlertCloseEnd('批量更新文章数统计 影响会员数 '. $runNum .'！');
}


// 设置状态
function SetState(){
	global $DB,$dataType,$dataTypeCN;

	$dataID		= OT::GetInt('dataID');
	$state		= OT::GetInt('state',-1);
		if (! in_array($state, array(0,1,9))){
			JS::AlertEnd('状态值错误('. $state .')');
		}

	$judRes = $DB->query('update '. OT_dbPref .'users set UE_state='. $state .' where UE_ID='. $dataID);
		if ($judRes){
			$alertRes = '<span style="color:green;">修改成功</span>';
		}else{
			$alertRes = '<span style="color:red;">修改失败</span>';
		}

	JS::DiyEnd('
	$id("state'. $dataID .'").style.color = \''. StateColor($state) .'\';
	$id("state'. $dataID .'Res").innerHTML = \''. $alertRes .'\';
	');
}

function StateColor($num){
	if ($num == 0){
		return 'red';
	}elseif ($num == 1){
		return '#0066CC';
	}elseif ($num == 9){
		return '#707070';
	}
}

?>