<?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'];
|
$missionList = $_GET['missionList'];
|
\Logging\LogInfo('_GET=' . print_r($_GET, true));
|
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 (!array_key_exists("missionList", $_GET)) {
|
echo json_encode(ErrorCode::retErr(ErrorCode::$ParamErr, "no missionList"));
|
return;
|
}
|
$missionList = json_decode($missionList, true);
|
|
$gameconfig = parse_ini_file("config/" . $gamename . ".ini", true);
|
$dbOpt = new \MongoDB7\MongoDb("Player", $gameconfig["db"]);
|
$where = ['openid' => $openid];
|
$options = [
|
'projection' => ['_id' => 0, 'missionNum' => 1, 'gold' => 1],
|
];
|
$dbRet = $dbOpt->query($where, $options);
|
if (!$dbRet) {
|
echo json_encode(ErrorCode::retErr(ErrorCode::$NoPlayer, "openid=" . $openid));
|
return;
|
}
|
|
$addGold = 0;
|
$updMissionNum = 0;
|
$playerData = $dbRet[0];
|
$dbMissionNum = (int) $playerData['missionNum'];
|
$dbGold = (int) $playerData['gold'];
|
foreach ($missionList as $missionData) {
|
$missionNum = $missionData["missionNum"];
|
if ($dbMissionNum >= $missionNum) {
|
echo json_encode(ErrorCode::retErr(ErrorCode::$GameServerFail, "missionNum less than or equal to dbMissionNum"));
|
return;
|
}
|
if ($updMissionNum < $missionNum) {
|
$updMissionNum = $missionNum;
|
}
|
// 山寨每关100
|
$mult = 1;
|
if ($missionData["multType"] > 0) {
|
$mult = 2; // 山寨双倍
|
}
|
$addGold += ($missionData["goldEx"] + 100) * $mult;
|
}
|
|
$update = [
|
'missionNum' => $updMissionNum,
|
'gold' => $dbGold + $addGold,
|
];
|
\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);
|