HavePermission($Permission)) {
exit;
}
\Logging\LogInfo("Post数据" . print_r($_POST, true));
$tempData = array(); // 模板数据
// 公共数据
$tempData["Name"] = $_POST["MailTempName"];
if ($_POST["EndDate"] != "") {
$d1 = strtotime(date("Y-m-d"));
$d2 = strtotime($_POST["EndDate"]);
$Days = round(($d2 - $d1) / 3600 / 24);
$tempData["EndDays"] = max(1, $Days); // 至少1天,因为时间默认是0点,所以+1天即当天
} else {
$tempData["EndDays"] = 2; // 默认2天有效期
}
$tempData["Title"] = $_POST["Title"];
$tempData["Text"] = $_POST["Text"];
$tempData["Gold"] = intval($_POST["Gold"]);
$tempData["GoldPaper"] = intval($_POST["GoldPaper"]);
$tempData["Silver"] = intval($_POST["Silver"]);
$items = array(); // 物品数据
$itemNums = explode(",", $_POST["itemNums"]);
for ($i = 0; $i < count($itemNums); $i++) {
$num = $itemNums[$i];
$itemID = intval($_POST["ItemID" . $num]);
$ItemCnt = intval($_POST["ItemCnt" . $num]);
$IsBind = intval($_POST["IsBind" . $num]);
if ($itemID <= 0 || $ItemCnt <= 0) {
continue;
}
array_push($items, array($itemID, $ItemCnt, $IsBind));
}
$tempData["Items"] = $items;
$spID = $user->GetSPID();
$backUrl = "AddPersonalCompensation.php";
$tempJsonFile = "MailTemp/" . $spID . "_Person.json";
// 全服邮件独有数据
if ($pack_type == "GMT_AddEntireCompensation") {
$backUrl = "AddEntireCompensation.php";
$tempJsonFile = "MailTemp/" . $spID . "_Entire.json";
$tempData["PlayerLV"] = intval($_POST["PlayerLV"]);
$tempData["LimitLVType"] = intval($_POST["LimitLVType"]);
$tempData["CheckState"] = intval($_POST["CheckState"]);
}
$readTempContent = \CommFunc\GetFileContents($tempJsonFile, "[]");
// echo "
readTempContent:" . $readTempContent . "
";
\Logging\LogInfo("readTempContent: " . $readTempContent);
$mailTempArray = json_decode($readTempContent, true);
if (!$mailTempArray) {
$mailTempArray = array();
}
$backIndex = -1;
$MailTempIndex = intval($_POST["MailTemp"]); // 模板索引
$opStr = "";
if ($_POST["saveTemp"] != "") {
$opStr = \Lang\gettext("修改");
$mailTempArray[$MailTempIndex] = $tempData;
$backIndex = $MailTempIndex;
} elseif ($_POST["delTemp"] != "") {
$opStr = \Lang\gettext("删除");
array_splice($mailTempArray, $MailTempIndex, 1);
} elseif ($_POST["saveNewTemp"] != "") {
$opStr = \Lang\gettext("新增");
array_push($mailTempArray, $tempData);
$backIndex = count($mailTempArray) - 1;
}
$saveTempContent = \CommFunc\MyJson_encode($mailTempArray);
// echo "
saveTempContent:" . $saveTempContent . "
";
\Logging\LogInfo("saveTempContent: " . $saveTempContent);
$opStr = "[" . $opStr . "] ";
if (!$saveTempContent) {
echo $opStr . \Lang\gettext("数据异常");
return;
}
// 使用 JsonFormat 格式化后存储,方便阅读及手动修改
$ret = file_put_contents($tempJsonFile, \CommFunc\JsonFormat($saveTempContent));
// echo "
file_put_contents ret:" . $ret . "
";
if ($ret == false) {
echo $opStr . \Lang\gettext("失败") . "
";
} else {
echo $opStr . \Lang\gettext("成功") . "
";
}
echo "" . \Lang\gettext("返回") . "
";