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

$money=$_GET["money"];
$name=$_GET["name"];
$pid=$_GET["pid"];
$out_trade_no=$_GET["out_trade_no"];
$trade_no=$_GET["trade_no"];
$trade_status=$_GET["trade_status"];
$type=$_GET["type"];
$sign_type=$_GET["sign_type"];
$sign=$_GET["sign"];

$arr=array(
	"pid" => $pid,
	"type" => $type,
	"out_trade_no" => $out_trade_no,
	"trade_no" => $trade_no,
	"name" => $name,
	"money"	=> $money,
	"trade_status"	=> $trade_status,
	"sign_type"	=> $sign_type
);

if($sign==get_sign($arr,$C_pkey)){
	echo "success"; //返回success说明通知成功，不要删除本行
	$sql="select * from sl_orders where O_id=".intval($out_trade_no)." and O_state=0";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if(mysqli_num_rows($result) > 0) {
		if($money==$row["O_money"]){//金额一致
			mysqli_query($conn,"update sl_orders set O_state=1 where O_id=".$row["O_id"]);
			mysqli_query($conn,"update sl_member set M_money=M_money+$money where M_id=".$row["O_attach"]);
		}
	}

}else{
	echo "fail";
}
?>