hxp
2025-06-04 f4a514d5ac952110da846636ecbb9de951eaf3d2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
include_once "/Common/CommFunc.php";
include_once "/Common/Logging.php";
include_once "/Account/User.php";
include_once "/language/lang.php";
 
\Logging\CreateLogging("CompensationTempMgr.php");
 
$pack_type = $_POST['pack_type'];
$Permission = $pack_type == "GMT_AddEntireCompensation" ? \User\Permission::P_ServerMailTempMgr : \User\Permission::P_PersonalMailTempMgr;
 
$user = new \User\User($_SESSION['UserAccount']);
if (!$user->HavePermission($Permission)) {
    exit;
}
 
\Logging\LogInfo("Post数据" . print_r($_POST, true));
 
$tempData = array(); // 模板数据
 
// 公共数据
$tempData["Name"] = $_POST["MailTempName"];
 
if ($_POST["LimitDays"] != "") {
    $tempData["LimitDays"] = intval($_POST["LimitDays"]);
} else {
    $tempData["LimitDays"] = 7; // 默认7天有效期
}
 
$tempData["Title"] = $_POST["Title"];
$tempData["Text"] = $_POST["Text"];
 
$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 "<br/>readTempContent:" . $readTempContent . "<br/>";
\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 "<br/>saveTempContent:" . $saveTempContent . "<br/>";
\Logging\LogInfo("saveTempContent: " . $saveTempContent);
 
$opStr = "[" . $opStr . "] ";
if (!$saveTempContent) {
    echo $opStr . \Lang\gettext("数据异常");
    return;
}
 
// 使用 JsonFormat 格式化后存储,方便阅读及手动修改
$ret = file_put_contents($tempJsonFile, \CommFunc\JsonFormat($saveTempContent));
// echo "<br/>file_put_contents ret:" . $ret . "<br/>";
if ($ret == false) {
    echo $opStr . \Lang\gettext("失败") . "<br/>";
} else {
    echo $opStr . \Lang\gettext("成功") . "<br/>";
}
echo "<a href='" . $backUrl;
if ($backIndex >= 0) {
    echo "?tempIndex=" . $backIndex;
}
echo "'>" . \Lang\gettext("返回") . "</a><br/>";