<?php
# Name: PHP版程氏音乐CMS管理系统 v3.0
# Author: 程氏<web@chshcms.com> [QQ:848769359]
# Homepage:http://www.chshcms.cn/
include_once("../lib/cs_conn.php");
include_once("../lib/cs_common.php");
if(isset($_COOKIE["cs_name"])){
	$cscms_name=$_COOKIE["cs_name"];
}else{
	exit(Msg_Error('你还没有登入或者登入已经超时!','login.php'));
}
$ac=CS_Request("rdbpay");
$CS_RMB=CS_Request("CS_RMB");
$vip=CS_Request("vip");
$pay=CS_Request("pay");
$type=$ac;

 if($pay==1){  //金币支付VIP
     if($CS_RMB==30){
         $VipDs=CS_VipDs1;
     }elseif($CS_RMB==180){
         $VipDs=CS_VipDs2;
     }elseif($CS_RMB==365){
         $VipDs=CS_VipDs3;
     }
     $row=$db->getrow("select * from ".Getdbname('user')." where cs_name='".$cscms_name."'");
     if($row['CS_Cion']<$VipDs){
	exit(Msg_Error('抱歉您的金币不够，请选择在线网银升级!',$_SERVER['HTTP_REFERER']));
     }else{
                $newds=$row["CS_Cion"]-$VipDs;
		$time1=$row["CS_VipTime"];
		$time2=date('Y-m-d');
		$diff=strtotime($time1)-strtotime($time2);
		if($diff<0){
			$mydate=mktime(0,0,0,date("m"),date("d")+$CS_RMB,date("Y"));
			$NewUseDate= date("Y-m-d H:i:s",$mydate);
			$sqlv="update ".Getdbname('user')." set cs_cion=".$newds.",cs_vip=1,cs_viptime='".date('Y-m-d H:i:s')."',cs_endtime='".$NewUseDate."' where CS_Name='".$cscms_name."'";
			$db->query($sqlv);
		}else{
			$strtimes = explode(" ",$row["CS_EndTime"]);
			$timearray = explode("-",$strtimes[0]);
			$year = $timearray[0];
			$month = $timearray[1];
			$day = $timearray[2]+$CS_RMB;
			$mydate2=mktime(0,0,0,$month,$day,$year);
			$NewUseDate=date("Y-m-d H:i:s",$mydate2);
			$sqlv="update ".Getdbname('user')." set cs_cion=".$newds.",cs_vip=1,cs_endtime='".$NewUseDate."' where CS_Name='".$cscms_name."'";
			$db->query($sqlv);
		}
		//产生消息
		$content="恭喜您，成功升级了VIP会员".$CS_RMB."天，VIP到期时间:".$NewUseDate."，若出现问题请尽快联系客服。";
		$s_addtime=date('Y-m-d H:i:s');
		$sqlx="insert into ".Getdbname('xiaoxi')." (cs_usera,cs_userb,cs_name,cs_neir,cs_addtime) values ('".$row["CS_Name"]."','系统消息','升级VIP - 系统消息','".$content."','".date('Y-m-d H:i:s')."')";
		$db->query($sqlx);

	        exit(Msg_Error('恭喜您，成功升级了VIP会员'.$CS_RMB.'天，VIP到期时间:'.$NewUseDate.'，若出现问题请尽快联系客服!',$_SERVER['HTTP_REFERER']));
     }
 }


 ##############################################下面为网银在线支付###########################################################
 if($vip==1){  //升级VIP
     $type='vip';
 }
 $randNum = rand(1000, 9999);
 $dingdan = date('Ymd',time()).$randNum.date('His',time());//订单号，建议构成格式 年月日-商户号-小时分钟秒
 $remark = $cscms_name."在线金币充值";                    //备注字段2
 global $db;
	if(!empty($_SERVER["HTTP_CLIENT_IP"]))
	   $UIP = $_SERVER["HTTP_CLIENT_IP"];
	else if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
	   $UIP = $_SERVER["HTTP_X_FORWARDED_FOR"];
	else if(!empty($_SERVER["REMOTE_ADDR"]))
	   $UIP = $_SERVER["REMOTE_ADDR"];
	else
 	  $UIP = "未知";
 $sqlx="insert into ".Getdbname('pay')." (cs_type,cs_user,cs_dingdan,cs_rmb,cs_pid,cs_ip,cs_addtime) values ('".$type."','".$cscms_name."','".$dingdan."',".$CS_RMB.",0,'".$UIP."','".date('Y-m-d H:i:s')."')";
 if(!$db->query($sqlx)){
	exit(Msg_Error('抱歉，记录定单错误!',$_SERVER['HTTP_REFERER']));
 }
 if($ac=='alipay'){
    $golink="alipay/alipayto.php";
 }elseif($ac=='tenpay'){
    $golink="tenpay/index.php";
 }elseif($ac=='yeepay'){
    $golink="yeepay/req.php";
 }
?>
<form method="post" name="form1" action="pay/<?php echo $golink?>">
 <input type="hidden" name="dingdan" value="<?php echo $dingdan?>">
 <input type="hidden" name="remark" value="<?php echo $remark?>">
 <input type="hidden" name="user" value="<?php echo $cscms_name?>">
 <input type="hidden" name="rmb" value="<?php echo $CS_RMB?>">
</form>
<script language="javascript">
document.form1.submit();
</script>
