<?php
require '../conn/conn.php';
require '../conn/function.php';

$json_string=file_get_contents("php://input");
$obj=json_decode($json_string);

if($C_pid=="" || $C_pkey==""){
	die();
}

$title = $obj->title;
$money = $obj->money;
$no = t($obj->no);
$tradeno = $obj->tradeno;
$paytype = $obj->paytype;
$remark = $obj->remark;
$time = $obj->time;
$sign = $obj->sign;

if(strtolower(md5("money=".$money."&no=".$no."&paytype=".$paytype."&remark=".$remark."&time=".$time."&title=".$title."&tradeno=".$tradeno."&key=".$C_pkey))==strtolower($sign)){ 
	$sql="select * from sl_orders where O_id=".intval($remark)." and O_state=0";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if(mysqli_num_rows($result) > 0) {
		mysqli_query($conn,"update sl_orders set O_state=1 where O_id=".$row["O_id"]);
		if($money==$row["O_money"]){//金额一致
			if($row["O_title"]=="广告申请"){
				$ad=explode("|",$row["O_attach"]);
				$A_pic=$ad[3];
				$A_text=$ad[2];
				$A_order=0;
				$A_url=$ad[4];
				$A_type=$ad[0];
				$A_time=date('Y-m-d H:i:s');
				$A_long=$ad[1];
				$A_red=0;
				$A_bold=0;
				mysqli_query($conn,"insert into sl_ad(A_pic,A_text,A_order,A_url,A_type,A_time,A_long,A_red,A_bold) values('$A_pic','$A_text',$A_order,'$A_url',$A_type,'$A_time',$A_long,$A_red,$A_bold)");
			}
			if($row["O_title"]=="短网址升级永久"){
				mysqli_query($conn,"update sl_short set S_vip=1 where S_id=".$row["O_attach"]);
			}
		}
	}
	echo "success";
}else{
	echo "fail";
}
?>