<?php

include './sc.php';



$id = $_POST['id'];

$qq = $user.'@qq.com';

if (!file_get_contents('./products/'.$id.'.json')) {
die("未找到商品");
}

$data = @file_get_contents('./products/'.$id.'.json');

$data = json_decode($data, true);

if ($data['hidden'] == 1) {
die("未找到商品");
}

if ($data['have'] <= 0) {
die("商品已售罄");
}


if ($bi < $data['bi'] or $Star < $data['star']) {
die('余额不足...');
}

$Star -= $data['star'];
$bi -= $data['bi'];



$mod = $data['mod'];

$Main_route = './mods/'.$mod.'/Main.php';

include $Main_route;




$Re = @open_products($data,$_POST);

$username = $Re['mid'];

if ($Re['code'] == 200) {
echo '开通成功啦~<meta http-equiv="refresh" content="1;url=./show_product.fx?id='.$username.'">';

@sendMail($qq, '#Fuxsto Host', "您的产品 ".$data['name']." 开通成功!");


// 定义要检查的文件路径
$filename = './me/' . $user . '/' . $pass . '/Star.txt'; // 目录路径

@file_put_contents($filename,$Star);

// 定义要检查的文件路径
$filename = './me/' . $user . '/' . $pass . '/bi.txt'; // 目录路径

@file_put_contents($filename,$bi);




} else {
print_r($Re['msg']);
exit;
}


// 定义要检查的文件路径
$filename = './me/' . $user . '/' . $pass . '/products/'.$username.'.json'; // 目录路径

// 编码为 JSON 字符串
$Re = json_encode($Re, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

@file_put_contents($filename,$Re);

$data['have'] -= 1;

// 编码为 JSON 字符串
$data = json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

@file_put_contents('./products/'.$id.'.json',$data);

?>