hxp
2025-06-09 6c3f6335c70859ded94a1ad8d218acb0ac34239c
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
<?php
include_once '/Common/CommFunc.php';
include_once '/Common/Logging.php';
include_once "/db/DBOper.php";
 
header("Content-type: text/html; charset=utf-8");
 
\Logging\CreateLogging("eventreport.eventreport.php");
 
// 2022-05-09T19:17:47    DEBUG           Version=
// 2022-05-09T19:17:47    DEBUG           DeviceFlag=
// 2022-05-09T19:17:47    DEBUG           SessionID=c8b996d5ffdc71139b1d4bc22874b2f8
// 2022-05-09T19:17:47    DEBUG           EventID=1100
// 2022-05-09T19:17:47    DEBUG           ProductID=xbqy
// 2022-05-09T19:17:47    DEBUG           OperatorID=test
// 2022-05-09T19:17:47    DEBUG           RegionName=s86
// 2022-05-09T19:17:47    DEBUG           Time=2022-05-09 19:17:47
// 2022-05-09T19:17:47    DEBUG           AccountID=yn1233
// 2022-05-09T19:17:47    DEBUG           PlayerID=280104
// 2022-05-09T19:17:47    DEBUG           RoleID=ĐạmDiệuHải
// 2022-05-09T19:17:47    DEBUG           Level=400
// 2022-05-09T19:17:47    DEBUG           Job=1
// 2022-05-09T19:17:47    DEBUG           IP=192.168.1.1
 
$EventID = $_GET["EventID"];
$GameName = $_GET["ProductID"];
$Channel = $_GET["OperatorID"];
$RegionName = $_GET["RegionName"];
$Time = $_GET["Time"];
 
\Logging\LogInfo(" _GET:" . print_r($_GET, true));
 
if (
    !$EventID || !$Channel || !$RegionName || !$Time || !$GameName || $GameName != \CommFunc\GetGameName()
) {
    Response(1000, "param error");
    exit;
}
 
$ok = false;
switch ($EventID) {
    case 1100:
        $ok = EventReport_UpdateRole("Login");
        break;
 
    case 1101:
        $ok = EventReport_UpdateRole("Logoff");
        break;
 
    case 9001:
        $Flag = $_GET["Flag"];
        // 流失模型中,Flag 1000 为首登成功
        if ($Flag == 1000) {
            $ok = EventReport_CreateRole();
        }
        break;
 
    case "CouponCode":
        $ok = RecordCoupontypeGroup();
        break;
 
    default:
        Response(1001, "unknown eventID -> " . $EventID);
        exit;
}
if ($ok) {
    Response();
}
exit;
 
function Response($errorcode = 0, $errormsg = "ok")
{
    $ret = array("errorcode" => $errorcode, "errormsg" => $errormsg);
    if ($errorcode != 0) {
        \Logging\LogError($errormsg . " _GET:" . print_r($_GET, true) . " ret:" . print_r($ret, true));
    }
    echo \CommFunc\MyJson_encode($ret);
}
 
function EventReport_UpdateRole($eventType)
{
    global $Channel, $RegionName, $Time;
 
    $AccountID = $_GET["AccountID"];
    $PlayerID = intval($_GET["PlayerID"]);
    $PlayerName = $_GET["RoleID"];
    $LV = intval($_GET["Level"]);
    $Job = intval($_GET["Job"]);
    $IP = $_GET["IP"];
    $FamilyName = array_key_exists("FamilyName", $_GET) ? $_GET["FamilyName"] : "";
    $FightPower = $_GET["FightPower"];
    settype($FightPower, "float");
    $AllCoinTotal = intval($_GET["AllCoinTotal"]);
 
    if (!$AccountID || !$PlayerID || !$PlayerName || !$LV || !$Job || !$IP) {
        Response(1003, "role param error");
        return;
    }
 
    $find = array("Channel" => $Channel, "AccountID" => $AccountID);
    // 只找对应服的数据更新即可
    if (!\DBOper\FindOne("GameRoles", $find, $findData, array($RegionName => 1))) {
        Response(2000, "db find error");
        return;
    }
    $newAccount = false;
    if (!isset($findData)) {
        $newAccount = true;
    }
    \Logging\LogInfo("newAccount:" . $newAccount . " findData:" . print_r($findData, true));
 
    $roleInfo = array();
    if (isset($findData) && array_key_exists($RegionName, $findData)) {
        $regionRole = $findData[$RegionName];
        // 如果是redis取出来的是json字符串
        if (is_string($regionRole)) {
            $regionRole = json_decode($regionRole, true);
            // \Logging\LogInfo("json_decode regionRole:" . print_r($regionRole, true));
        }
        foreach ($regionRole as $key => $value) {
            $roleInfo[$key] = $value;
        }
    }
 
    $roleInfo["PlayerID"] = $PlayerID;
    $roleInfo["PlayerName"] = $PlayerName;
    $roleInfo["LV"] = $LV;
    $roleInfo["Job"] = $Job;
    $roleInfo["IP"] = $IP;
    $roleInfo["FamilyName"] = $FamilyName;
    $roleInfo["FightPower"] = $FightPower;
    $roleInfo["AllCoinTotal"] = $AllCoinTotal;
    if (array_key_exists("CreateRoleTime", $_GET)) {
        $roleInfo["CreateRoleTime"] = $_GET["CreateRoleTime"];
    }
    if ($eventType == "Login") {
        $roleInfo["LoginTime"] = $Time;
    } elseif ($eventType == "Logoff") {
        $roleInfo["LogoffTime"] = $Time;
    }
 
    if ($newAccount) {
        $insArray = array(
            "Channel" => $Channel,
            "AccountID" => $AccountID,
            "CreateTime" => date("Y-m-d H:i:s"),
            $RegionName => $roleInfo
        );
        if (!\DBOper\Insert("GameRoles", $insArray, $find)) {
            Response(2001, "db Insert error");
            return;
        }
    } else {
        $setRole = array($RegionName => $roleInfo);
        if (!\DBOper\Update("GameRoles", $find, $setRole, true)) {
            Response(2002, "db Update error");
            return;
        }
    }
    $ServerID = \CommFunc\GetServerIDBySid($RegionName);
    AddAccountFirstLogin($ServerID, $roleInfo);
    AddAccountDayActive($ServerID, $roleInfo);
 
    // 附带更新服务器角色表,之后会替换 GameRoles 表
    $find = array("Channel" => $Channel, "AccountID" => $AccountID, "ServerID" => $ServerID);
    if (\DBOper\Count("ServerRoles", $find) <= 0) {
        $insArray = array(
            "Channel" => $Channel,
            "AccountID" => $AccountID,
            "ServerID" => $ServerID,
            "CreateYMD" => date("Y-m-d"),
        );
        if ($roleInfo["CreateRoleTime"]) {
            $insArray["CreateYMD"] = substr($roleInfo["CreateRoleTime"], 0, 10);
        }
        $insArray["RollCount"] = \DBOper\Count("ServerRoles", array("Channel" => $Channel, "AccountID" => $AccountID));
        $insArray = array_merge($insArray, $roleInfo);
        \DBOper\Insert("ServerRoles", $insArray, $find);
    } else {
        \DBOper\Update("ServerRoles", $find, $roleInfo, true);
    }
    return true;
}
 
function EventReport_CreateRole()
{
    global $Channel, $RegionName;
 
    $ServerID = \CommFunc\GetServerIDBySid($RegionName);
    if (!$ServerID) {
        return;
    }
    $find = array("Channel" => $Channel, "ServerID" => $ServerID);
    if (!\DBOper\FindOne("GameServerInfo", $find, $findData, null, false)) {
        Response(2000, "db find error");
        return;
    }
    \Logging\LogInfo(" findData:" . print_r($findData, true));
 
    if (!isset($findData)) {
        $insArray = array(
            "Channel" => $Channel,
            "ServerID" => $ServerID,
            "CreateRoleCount" => 1,
        );
        if (!\DBOper\Insert("GameServerInfo", $insArray, $find)) {
            Response(2001, "db Insert error");
            return;
        }
        \Logging\LogInfo(" insert ServerID:" . $ServerID . " CreateRoleCount:" . 1);
    } else {
        $CreateRoleCount = $findData["CreateRoleCount"] + 1;
        $setArray = array("CreateRoleCount" => $CreateRoleCount);
        if (!\DBOper\Update("GameServerInfo", $find, $setArray)) {
            Response(2002, "db Update error");
            return;
        }
        \Logging\LogInfo(" update ServerID:" . $ServerID . " CreateRoleCount:" . $CreateRoleCount);
    }
    return true;
}
 
/**添加平台账号首登 */
function AddAccountFirstLogin($ServerID, $roleInfo)
{
    global $Channel, $Time;
    $AccountID = $_GET["AccountID"];
 
    $find = array("Channel" => $Channel, "AccountID" => $AccountID);
    if (!\DBOper\FindOne("AccountFirstLogin", $find, $findData, null, false)) {
        return;
    }
    if (isset($findData)) {
        // 已存在,不再重复添加
        return;
    }
    $CreateRoleTime = $Time;
    if (array_key_exists("CreateRoleTime", $roleInfo)) {
        $CreateRoleTime = $roleInfo["CreateRoleTime"];
    }
    $insArray = array(
        "Channel" => $Channel,
        "AccountID" => $AccountID,
        "CreateYMD" => substr($CreateRoleTime, 0, 10),
        "CreateTime" => $CreateRoleTime,
        "ServerID" => $ServerID,
        "PlayerID" => $roleInfo["PlayerID"],
        "PlayerName" => $roleInfo["PlayerName"],
        "Job" => $roleInfo["Job"],
        "IP" => $roleInfo["IP"],
    );
    \DBOper\Insert("AccountFirstLogin", $insArray);
}
 
/**添加平台账号日活 */
function AddAccountDayActive($ServerID, $roleInfo)
{
    global $Channel, $Time;
    $AccountID = $_GET["AccountID"];
    $curYMD = substr($Time, 0, 10);
    $find = array("Channel" => $Channel, "AccountID" => $AccountID, "ActiveYMD" => $curYMD);
    $roleInfo["ServerID"] = $ServerID;
    // 直接更新
    $actInfo = array(
        "Channel" => $Channel,
        "AccountID" => $AccountID,
        "ActiveYMD" => $curYMD,
        "ServerID" => $ServerID,
        "IP" => $roleInfo["IP"],
    );
    if (array_key_exists("LoginTime", $roleInfo)) {
        $actInfo["LoginTime"] = $roleInfo["LoginTime"];
    }
    if (array_key_exists("LogoffTime", $roleInfo)) {
        $actInfo["LogoffTime"] = $roleInfo["LogoffTime"];
    }
    \DBOper\Update("AccountDayActive", $find, $actInfo, false, true);
}
 
/**记录媒体卡账号分组 */
function RecordCoupontypeGroup()
{
    global $Channel, $RegionName;
 
    $ServerID = \CommFunc\GetServerIDBySid($RegionName);
    if (!$ServerID) {
        return;
    }
 
    CommFunc\GetConfig("ServerInfo", "CoupontypeGroup", $CoupontypeGroup);
    if (!$CoupontypeGroup) {
        // \Logging\LogInfo("CoupontypeGroup 不需要");
        return;
    }
 
    $AccountID = $_GET["accid"];
    $code = $_GET["code"];
    $coupontype = $_GET["coupontype"];
    $CoupontypeGroup = json_decode($CoupontypeGroup);
    if (!array_key_exists($coupontype, $CoupontypeGroup)) {
        // \Logging\LogInfo("CoupontypeGroup 不需要记录的组:" . $coupontype);
        return;
    }
 
    $find = array("Channel" => $Channel, "AccountID" => $AccountID, "ServerID" => $ServerID);
    if (!\DBOper\FindOne("CoupontypeGroup", $find, $findData)) {
        return;
    }
    if (isset($findData)) {
        // \Logging\LogInfo("已存在,不再重复添加: " . print_r($findData, true));
        return true;
    }
 
    $insArray = array(
        "Channel" => $Channel,
        "AccountID" => $AccountID,
        "ServerID" => $ServerID,
        "CreateTime" => date("Y-m-d H:i:s"),
        "Coupontype" => $coupontype,
        "Code" => $code,
    );
    if (\DBOper\Insert("CoupontypeGroup", $insArray, $find)) {
        \Logging\LogInfo("记录使用媒体卡首次分组: " . print_r($insArray, true));
        return true;
    }
}