<?php
ini_set("error_reporting","E_ALL & ~E_NOTICE");

include_once "../configuration/config.inc.php";
if(!$_SESSION['accountName']) exit("<script> alert('请登陆后使用！');location.href='/UserCenter/Login.php';</script>");
//$area_url = array($chongzhi);
$sqlr="SELECT name,dj FROM web_2.account WHERE name='".$_SESSION['accountName']."' "; 
$result=mysql_query($sqlr,$conn);
$row8=mysql_fetch_array($result);

$dj1  = intval($row8['dj']);
if($row8['dj']<=0){
	echo "<script> alert('没有可兑换点数！');location.href='/UserCenter/index.php';</script>";
	exit;
} 

$exec1 = "select `id`,`player_id`,`name`,`server_id`,`account_name` from aionx_gs_2.`players` where `account_name`='{$_SESSION['accountName']}'";
$result1 = mysql_query($exec1,$conn);
$rowabcde = mysql_fetch_array($result1);
if ($rowabcde['id']!="") {
$sqlw="UPDATE web_2.account SET dj=0 WHERE name='".$row8['name']."'"; 
@mysql_query($sqlw,$conn);
	
  $execb = "select `mailUniqueId` from aionx_gs_2.`mail` order by `mailUniqueId` desc limit 0,1";
  $resultb = mysql_query($execb,$conn);
  $rsb = mysql_fetch_array($resultb);
  $temp_id=(int)$rsb['mailUniqueId']+1;
  $sorabc =date("Y-m-d H:i:s");
  $sodj2=$dj1; //floor($dj1/500);
$sql="insert into aionx_gs_2.`charge` (`oid`,`sid`,`player_id`,`player_name`,`account_name`,`currency`,`addcoin`,`money`,`gold`,`time`,`createtime`)values(1,1,'".$rowabcde['player_id']."','".$rowabcde['name']."','".$rowabcde['account_name']."',1,1,".$dj1.",".$sodj2.",1,'".$sorabc."')";
$resultabc = mysql_query($sql);

@mysql_query("insert into aionx_gs_2.`mail` (`mailUniqueId`,`mailRecipientId`,`senderName`,`senderLv`,`mailTitle`,`mailMessage`,`unread`,`attachedItemID`,`copperNum`,`copperNum2`,`goldNum`,`goldNum2`,`express`,`type`,`lock`,`recievedTime`)values(".$temp_id.",".$rowabcde['player_id'].",'系统',0,'元宝充值','元宝兑换成功!',1,0,0,0,".$dj1.",0,1,1,0,'".date("Y-m-d H:i:s")."')");

@mysql_query("insert into aionx_gs_2.`player_quests` (`player_id`,`quest_id`,`status`,`quest_vars1`,`quest_vars2`,`quest_vars3`,`complete_count`) values (".$rowabcde['player_id'].",'1074','COMPLETE',1,0,0,1)");

@mysql_query("insert into aionx_gs_2.`player_quests` (`player_id`,`quest_id`,`status`,`quest_vars1`,`quest_vars2`,`quest_vars3`,`complete_count`) values (".$rowabcde['player_id'].",'1076','COMPLETE',1,0,0,1)");
//充值
//$sqlabc =  "insert into `csjz`.`ORDERLIST` (ACCOUNT,REGZONEID,CHARNAME,TRANSID,MONEY,TIME,DONE) values('".$_SESSION['accountName']."',13172744,(select NAME from csjz.CHARDATA where ACCOUNT = '".$_SESSION['accountName']."'),0,'{$dj1}',now(),0)";
//$sqlabc = "insert into `charge` (`oid`,`sid`,`account_name`,`money`,`gold`,`time`,`sign`,`createtime`)values(".$temp_id.",".$rs1['server_id'].",'".$_SESSION['valid_user']."',1,1,1,1,'".date("Y-m-d H:i:s")."'".")";

//mysql_query($sqlabc,$conn);
//@mysql_query();


//扣代金券

echo "<script> alert('兑换元宝成功,游戏中邮件收取！');location.href=/UserCenter/;</script>";
//echo "<script> location.href=/UserCenter/;</script>";
}else{ echo "<script> alert('请先创建角色后再进行兑换操作！');location.href=/UserCenter/;</script>";}
?>
