|
@@ -21,16 +21,18 @@ class ActiveProc {
|
|
|
*/
|
|
|
public static function procMain($req) {
|
|
|
switch ($req->cmd) {
|
|
|
- case CmdCode::active_day7_drawreward: # 6502 领取奖励
|
|
|
+ case CmdCode::active_day7_drawreward: # 6502 领取七日签到奖励
|
|
|
return self::Day7_DrawReward($req);
|
|
|
case CmdCode::active_getzonePublicTs: # 6503 查询开服时间戳
|
|
|
return ActiveProc::GetZonePublicTS($req);
|
|
|
+ case CmdCode::active_getTodayOnlineInfos: # 6504 查询当天在线时长
|
|
|
+ return self::getTotayOnlineInfos($req);
|
|
|
case CmdCode::Task_Tili: # 6508 体力变化
|
|
|
return ActiveProc::RecoveryTili($req);
|
|
|
case CmdCode::active_token_drawReward: # 6512 兑换码礼包
|
|
|
return self::drawActivePackageByCode($req);
|
|
|
- case CmdCode::active_draw_onlinegift: # 6513 领取在线礼包
|
|
|
- return self::drawOnlineGift();
|
|
|
+ case CmdCode::active_draw_onlinegift: # 6513 领取在线(时长)礼包
|
|
|
+ return self::drawOnlineGift($req);
|
|
|
case CmdCode::active_draw_reggift: # 6514 领取全服注册礼包
|
|
|
return self::drawRegGift($req);
|
|
|
case CmdCode::active_presentTili: # 6515 领取在线赠送体力
|
|
@@ -134,50 +136,56 @@ class ActiveProc {
|
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc=" 在线礼包 ">
|
|
|
|
|
|
+ /**
|
|
|
+ * 【6504】查询当天在线时长信息
|
|
|
+ * @param req $req
|
|
|
+ */
|
|
|
+ static function getTotayOnlineInfos($req) {
|
|
|
+ return Resp::ok(array(
|
|
|
+ "onlineGiftIDs" => $req->userInfo->game->privateState->onlineGiftIDs,
|
|
|
+ "onlineGiftts" => $req->userInfo->game->privateState->onlineGiftts
|
|
|
+ ));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 6513 领取连续在线礼包
|
|
|
- * @return type
|
|
|
+ * @param req $req
|
|
|
*/
|
|
|
- static function drawOnlineGift() {
|
|
|
- $req = req();
|
|
|
+ static function drawOnlineGift($req) {
|
|
|
$user = $req->userInfo->game;
|
|
|
$privateState = new PrivateStateModel($user->privateState);
|
|
|
$giftid = $req->paras[0]; # 提取参数: 礼包的编号
|
|
|
$giftData = GameConfig::activity_onlinegift_getItem($giftid); # 在线礼包常量数据
|
|
|
- if ($giftData == NULL) {
|
|
|
- return Resp::err(ErrCode::onlinegift_constno_err);
|
|
|
- }
|
|
|
- if ($privateState->onlineGiftts + $giftData->onlineSec > now()) { # 时间未到,不可以领取
|
|
|
- return Resp::err(ErrCode::onlinegift_timenotenough);
|
|
|
- }
|
|
|
- if (!CommUtil::isPropertyExists($privateState, "onlineGiftID")) {#初始化 这个字段
|
|
|
- $privateState->onlineGiftID = 1;
|
|
|
- } else {
|
|
|
- if ($privateState->onlineGiftID == 0) {
|
|
|
- $privateState->onlineGiftID = 1;
|
|
|
- }
|
|
|
- }
|
|
|
+ my_Assert(null != $giftData, ErrCode::onlinegift_constno_err); # 防御找不到配置数据
|
|
|
+ my_Assert($privateState->onlineGiftts >= $giftData->onlineSec, # # 时间未到,不可以领取
|
|
|
+ ErrCode::onlinegift_timenotenough);
|
|
|
|
|
|
- if ($privateState->onlineGiftID != $giftid) { # 判断礼包ID是否正确,可以领取,
|
|
|
- return Resp::err(ErrCode::onlinegift_wrongid, $privateState->onlineGiftID . '--->' . $giftid);
|
|
|
+ if (!CommUtil::isPropertyExists($privateState, "onlineGiftIDs") #
|
|
|
+ || !is_array($privateState->onlineGiftIDs)) {
|
|
|
+ $privateState->onlineGiftIDs = array(); # 初始化 这个字段
|
|
|
}
|
|
|
-
|
|
|
- $privateState->onlineGiftts = now(); # 更新时间戳
|
|
|
- $privateState->onlineGiftID = $giftid + 1; # 已领礼包ID++
|
|
|
+// var_dump($privateState->onlineGiftIDs);
|
|
|
+ my_Assert(!in_array($giftid, $privateState->onlineGiftIDs), # # 判断礼包ID是否已经领取
|
|
|
+ ErrCode::active_hasgetted);
|
|
|
$err = StoreProc::AddMultiItemInStore($req, $giftData->rewardstr); # 发放奖励
|
|
|
if ($err) {
|
|
|
return Resp::err($err, '发放奖励失败');
|
|
|
}
|
|
|
+ $privateState->onlineGiftIDs[] = $giftid; # 记录已领礼包ID
|
|
|
$user->privateState = $privateState;
|
|
|
-// var_dump($privateState);
|
|
|
$req->userInfo->game = $user;
|
|
|
- UserProc::updateUserInfo(); # 回写用户数据
|
|
|
+ UserProc::updateUserInfo(); # 回写用户数据
|
|
|
|
|
|
return Resp::ok(array(
|
|
|
'onlineGiftts' => $privateState->onlineGiftts,
|
|
|
- 'onlineGiftID' => $privateState->onlineGiftID,
|
|
|
- 'store' => $req->userInfo->game->store
|
|
|
- )); # 设置返回值
|
|
|
+ 'onlineGiftIDs' => $privateState->onlineGiftIDs,
|
|
|
+ "reward" => $packageInfo->reward,
|
|
|
+ 'gold' => $req->userInfo->game->baseInfo->gold,
|
|
|
+ 'cash' => $req->userInfo->game->baseInfo->cash,
|
|
|
+ 'tili' => $req->userInfo->game->baseInfo->tili,
|
|
|
+ 'store' => $req->userInfo->game->store,
|
|
|
+ 'hero' => $req->userInfo->game->heros
|
|
|
+ )); # 设置返回值
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -186,70 +194,56 @@ class ActiveProc {
|
|
|
*/
|
|
|
static private function ClearOnlineGiftTs($req) {
|
|
|
$req->userInfo->game->privateState->onlineGiftts = 0;
|
|
|
- $req->userInfo->game->privateState->onlineGiftID = 1;
|
|
|
+ $req->userInfo->game->privateState->onlineGiftIDs = array();
|
|
|
}
|
|
|
|
|
|
// </editor-fold>
|
|
|
// <editor-fold defaultstate="collapsed" desc=" 兑换码 ">
|
|
|
|
|
|
/**
|
|
|
- * 凭兑换码领取礼包
|
|
|
+ * [6512]凭兑换码领取礼包
|
|
|
* @param Req $req
|
|
|
*/
|
|
|
static function drawActivePackageByCode($req) {
|
|
|
$user = new UserGameModel($req->userInfo->game);
|
|
|
- $privateState = new PrivateStateModel($user->privateState);
|
|
|
- $activeId = $req->paras[0]; # 取参数 活动id
|
|
|
+ $privateState = new PrivateStateModel($user->privateState); # 快速访问
|
|
|
+ list( $activeId, $codestring) = $req->paras; # 取参数 活动id, 兑换码
|
|
|
$active = GameConfig::activity_getItem($activeId); # 活动数据
|
|
|
- if (null == $active) {
|
|
|
- return Resp::err(ErrCode::active_const_no_err);
|
|
|
- }
|
|
|
- if ($active->startts > now() or $active->endts < now()) { # 校验开放时间
|
|
|
- return Resp::err(ErrCode::active_time);
|
|
|
- }
|
|
|
- $codestring = $req->paras[1]; # 取参数 激活码
|
|
|
- if (!preg_match("/^[a-kmnp-z2-9]{10}$/", $codestring)) { # 长度校验(10个字符)
|
|
|
- return Resp::err(ErrCode::active_activecode_format);
|
|
|
- }
|
|
|
+ my_Assert(null != $active, ErrCode::active_const_no_err);
|
|
|
+ my_Assert($active->startts <= now() && $active->endts >= now(), ErrCode::active_time); # 校验开放时间
|
|
|
+ my_Assert(preg_match("/^[a-kmnp-z2-9]{10}$/", $codestring), ErrCode::active_activecode_format); # 基础格式校验(10个特定字符)
|
|
|
$activeCode = CipheredBase32::Decode($codestring); # 解码
|
|
|
$codePlatStr = GameConstants::GetPlatStringByActivteCode($activeCode); # platstr
|
|
|
- if (GameConstants::AllPlatStr !== $codePlatStr # 忽略全平台礼包
|
|
|
- && $req->userInfo->getPlatStr() !== $codePlatStr) { # 平台字符串必须相符
|
|
|
- return Resp::err(ErrCode::active_activecode_plat, $codePlatStr); # # 平台错误
|
|
|
- }
|
|
|
- if (!is_int($activeCode->number) # 检查 兑换码的编号范围0~50000
|
|
|
- || $activeCode->number < 1 || $activeCode->number > 50000) {
|
|
|
- return Resp::err(ErrCode::active_activecode_format);
|
|
|
- }
|
|
|
+ my_Assert(GameConstants::AllPlatStr == $codePlatStr # # 忽略全平台礼包
|
|
|
+ || $req->userInfo->getPlatStr() == $codePlatStr, # # 平台字符串必须相符
|
|
|
+ ErrCode::active_activecode_plat); # # 平台错误
|
|
|
+
|
|
|
+ my_Assert(is_int($activeCode->number) # # 编号为int值
|
|
|
+ && $activeCode->number >= 1 && $activeCode->number <= 50000, # # 检查 兑换码的编号范围0~50000
|
|
|
+ ErrCode::active_activecode_format);
|
|
|
+
|
|
|
$packageID = $activeCode->package; # 礼包id
|
|
|
$packageInfo = GameConfig::tokenGift_getItem($packageID); # 礼包常量数据
|
|
|
- if ($packageInfo == null) { # 无效
|
|
|
- return Resp::err(ErrCode::err_const_no);
|
|
|
- }
|
|
|
- if ($packageInfo->expirets < now() || $packageInfo->startTs > now()) { # 激活码已经失效,或者礼包尚未开启
|
|
|
- return Resp::err(ErrCode::active_activecode_outtime);
|
|
|
- }
|
|
|
- if (in_array($packageID, $privateState->usedTokens)) { # 已经领取过该礼包了
|
|
|
- return Resp::err(ErrCode::active_hasgetted);
|
|
|
- }
|
|
|
- if (self::checkActiveCodeIsUsed($activeCode)) { # 检查 该激活码是否已经使用过了
|
|
|
- return Resp::err(ErrCode::active_activecode_used);
|
|
|
- } # 发放礼包,
|
|
|
- $err = StoreProc::AddMultiItemInStore($req, $packageInfo->reward);
|
|
|
- if ($err) {
|
|
|
- return Resp::err($err);
|
|
|
- }
|
|
|
+ my_Assert(null != $packageInfo, ErrCode::err_const_no); # 防御
|
|
|
+ my_Assert($packageInfo->expirets >= now() && $packageInfo->startTs <= now(),
|
|
|
+ ErrCode::active_activecode_outtime); # 激活码已经失效,或者礼包尚未开启
|
|
|
+ my_Assert(!in_array($packageID, $privateState->usedTokens), ErrCode::active_hasgetted); # 已经领取过该礼包了
|
|
|
+ my_Assert(!self::checkActiveCodeIsUsed($activeCode), ErrCode::active_activecode_used); # 检查 该激活码是否已经使用过了
|
|
|
+ $err = StoreProc::AddMultiItemInStore($req, $packageInfo->reward); # 发放礼包
|
|
|
+ my_Assert(ErrCode::ok == $err, $err); # 防御发放礼包过程出错
|
|
|
$req->userInfo->game->privateState->usedTokens[] = $packageID; # 记录领取记录
|
|
|
$ok = self::setActiveCodeUserRecord($activeCode, $req->uid); # 插入数据库
|
|
|
- if (!$ok) {
|
|
|
- return Resp::err(ErrCode::err_db, daoInst()->getError(TRUE)); # # 数据库操作失败- 重试
|
|
|
- }
|
|
|
+ my_Assert($ok, ErrCode::err_db); # 数据库操作失败- 重试
|
|
|
UserProc::updateUserInfo(); # 回存玩家数据
|
|
|
$ret = array(# # 返回值
|
|
|
"plat" => $codePlatStr,
|
|
|
"packageId" => $activeCode->package,
|
|
|
"reward" => $packageInfo->reward,
|
|
|
+ 'gold' => $req->userInfo->game->baseInfo->gold,
|
|
|
+ 'cash' => $req->userInfo->game->baseInfo->cash,
|
|
|
+ 'tili' => $req->userInfo->game->baseInfo->tili,
|
|
|
'store' => $req->userInfo->game->store,
|
|
|
+ 'hero' => $req->userInfo->game->heros
|
|
|
);
|
|
|
return Resp::ok($ret); # 返回成功信息
|
|
|
}
|
|
@@ -370,6 +364,17 @@ class ActiveProc {
|
|
|
*/
|
|
|
static function DailyResetDay7Task($req) {
|
|
|
$req->userInfo->game->gates->Times = 0;
|
|
|
+
|
|
|
+ $typeID = 6; # 7日活动
|
|
|
+ $ac = GameConfig::activity_getItem($typeID);
|
|
|
+ my_Assert(null != $ac, ErrCode::err_const_no);
|
|
|
+ $startDay = tsDay($ac->startts);
|
|
|
+ $newLoginDays = array_filter($req->userInfo->game->privateState->LoginDays, # 剔除不符合时间的登录记录
|
|
|
+ function($tsday)use($startDay) {
|
|
|
+ return $startDay <= $tsday;
|
|
|
+ }
|
|
|
+ );
|
|
|
+ $req->userInfo->game->privateState->LoginDays = $newLoginDays; #
|
|
|
if (count($req->userInfo->game->privateState->LoginDays) < 7) {
|
|
|
$req->userInfo->game->privateState->LoginDays[] = tsDay();
|
|
|
}
|
|
@@ -381,8 +386,23 @@ class ActiveProc {
|
|
|
*/
|
|
|
static function Day7_DrawReward($req) {
|
|
|
// 设计7日数据结构
|
|
|
- // 检查领取条件
|
|
|
- // 结束
|
|
|
+ list($day) = $req->paras; # 参数: 领取第x天的奖励
|
|
|
+ $private = new PrivateStateModel($req->userInfo->game->privateState); # 私有数据
|
|
|
+ my_Assert(count($private->LoginDays) >= $day, ErrCode::active_day7_totaldays);
|
|
|
+ my_Assert(!in_array($day, $private->day7_drawed), ErrCode::active_hasgetted);
|
|
|
+ $day_rwd = GameConfig::activity_day7_getItem($day); # 查询奖励数据
|
|
|
+ my_Assert(null != $day_rwd, ErrCode::err_const_no); # 防御找不到配置
|
|
|
+ StoreProc::AddMultiItemInStore($req, $day_rwd->reward); # 发放奖励
|
|
|
+ $private->day7_drawed[] = $day; # 添加领取记录
|
|
|
+ $req->userInfo->game->privateState = $private; # 更新数据
|
|
|
+ UserProc::updateUserInfo(); # 回存
|
|
|
+ return Resp::ok(array(
|
|
|
+ 'gold' => $req->userInfo->game->baseInfo->gold,
|
|
|
+ 'cash' => $req->userInfo->game->baseInfo->cash,
|
|
|
+ 'tili' => $req->userInfo->game->baseInfo->tili,
|
|
|
+ 'store' => $req->userInfo->game->store,
|
|
|
+ 'hero' => $req->userInfo->game->heros
|
|
|
+ )); # 返回值
|
|
|
}
|
|
|
|
|
|
// </editor-fold>
|