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
<?php
 
/**
 * 更新关卡,并发放奖励
 */
 
include_once "../../../Common/CommFunc.php";
include_once "../../../Common/Logging.php";
include_once '../../../Common/MongoDB7.php';
include_once "errorCode.php";
 
\Logging\CreateLogging("updateMissionNum.php");
 
$openid = $_GET['openid'];
$gamename = $_GET['gamename'];
$missionNum = (int) $_GET['missionNum'];
if ($openid == "") {
    echo json_encode(ErrorCode::retErr(ErrorCode::$ParamErr, "no openid"));
    return;
}
if ($gamename == "") {
    echo json_encode(ErrorCode::retErr(ErrorCode::$ParamErr, "no gamename"));
    return;
}
if ($missionNum <= 0) {
    echo json_encode(ErrorCode::retErr(ErrorCode::$ParamErr, "no missionNum"));
    return;
}
 
$gameconfig = parse_ini_file("config/" . $gamename . ".ini", true);
$dbOpt = new \MongoDB7\MongoDb("Player", $gameconfig["db"]);
$where = ['openid' => $openid];
$options = [
    'projection' => ['_id' => 0, 'missionNum' => 1],
];
$dbRet = $dbOpt->query($where, $options);
if (!$dbRet) {
    echo json_encode(ErrorCode::retErr(ErrorCode::$NoPlayer, "openid=" . $openid));
    return;
}
 
$playerData = $dbRet[0];
$dbMissionNum = (int) $playerData['missionNum'];
if ($dbMissionNum >= $missionNum) {
    echo json_encode(ErrorCode::retErr(ErrorCode::$GameServerFail, "missionNum less than or equal to dbMissionNum"));
    return;
}
 
$update = [
    'missionNum' => $missionNum,
];
\Logging\LogInfo('更新玩家关卡 openid=' . $openid . '  update=' . print_r($update, true));
$modCount = $dbOpt->update($where, $update);
\Logging\LogInfo('更新条数: ' . $modCount);
 
$ret;
if ($modCount > 0) {
    $ret = ErrorCode::retOK($update);
    // 给奖励未结算的关卡奖励
    // 待处理 ...
 
} else {
    $ret = ErrorCode::retOK();
}
echo json_encode($ret);