From db24966e898b9fd9bc597c55180c57784b41498f Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 6 Jun 2022 21:16:45 +0800 Subject: [PATCH] 1 --- webapp/controller/MissionController.class.php | 4 +- webapp/services/MissionService.php | 75 +++++++++++-------- 2 files changed, 47 insertions(+), 32 deletions(-) diff --git a/webapp/controller/MissionController.class.php b/webapp/controller/MissionController.class.php index 047f7350..f3746f26 100644 --- a/webapp/controller/MissionController.class.php +++ b/webapp/controller/MissionController.class.php @@ -252,8 +252,8 @@ class MissionController extends BaseAuthedController { { $missionId = getReqVal('mission_id', 0); $this->missionService->offerRewardMissionPreview( - $missionId, - $this->propertyChgService); + $missionId + ); } public function cancelOfferRewardMission() diff --git a/webapp/services/MissionService.php b/webapp/services/MissionService.php index 90bc1c87..c9dfec48 100644 --- a/webapp/services/MissionService.php +++ b/webapp/services/MissionService.php @@ -634,6 +634,7 @@ class MissionService extends BaseService { $missionDto['state'] = 2; } $missionDto['objects'] = $mission['objects']; + $missionDto['ceg_num'] = $this->calcCegPreview($mission['objects']); } } } @@ -753,46 +754,27 @@ class MissionService extends BaseService { myself()->_rspOk(); } - public function offerRewardMissionPreview($missionId, $propertyChgService) + public function offerRewardMissionPreview($missionId) { $missionMeta = mt\Task::get($missionId); if (!$missionMeta) { myself()->_rspErr(1, 'mission_id parameter error'); return; } - $count = $this->getOfferRewardMissionCount(); - $cegNum = 0; - $objects = explode('|', getReqVal('objects', 0)); - foreach ($objects as $val) { - $strings = explode(':', $val); + $strings = explode('|', getReqVal('objects', 0)); + $objects = array(); + foreach ($strings as $str){ + $strings2 = explode(':', $str); if (count($strings) < 2) { continue; } - $type = $strings[0]; - $id = $strings[1]; - switch ($type) { - case 0: - { - //武器 - $gunDb = Gun::find($id); - if ($gunDb) { - $gunDto = Gun::toDto($gunDb); - $cegNum += Gun::calcPveGainGold($gunDto, $count); - } - } - break; - case 1: - { - //英雄 - $heroDb = Hero::find($id); - if ($heroDb) { - $heroDto = Hero::toDto($heroDb); - $cegNum += Hero::calcPveGainGold($heroDto, $count); - } - } - break; - } + array_push($objects, + array( + 'type' => $strings2[0], + 'id' => $strings2[1], + )); } + $cegNum = $this->calcCegPreview($objects); myself()->_rspData(array( 'ceg_num' => $cegNum )); @@ -986,4 +968,37 @@ class MissionService extends BaseService { return false; } + private function calcCegPreview($objects) + { + $count = $this->getOfferRewardMissionCount(); + $cegNum = 0; + foreach ($objects as $obj) { + $type = $obj['type']; + $id = $obj['id']; + switch ($type) { + case 0: + { + //武器 + $gunDb = Gun::find($id); + if ($gunDb) { + $gunDto = Gun::toDto($gunDb); + $cegNum += Gun::calcPveGainGold($gunDto, $count); + } + } + break; + case 1: + { + //英雄 + $heroDb = Hero::find($id); + if ($heroDb) { + $heroDto = Hero::toDto($heroDb); + $cegNum += Hero::calcPveGainGold($heroDto, $count); + } + } + break; + } + } + return $cegNum; + } + }