From 16b8525f5f3897be289c49c344bdc0334a0f3a7f Mon Sep 17 00:00:00 2001 From: hujiabin Date: Sun, 9 Oct 2022 11:47:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8E=86=E5=8F=B2=E6=88=98=E7=BB=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Battle.py | 14 ++++++ doc/_common.py | 26 +++++++++++ webapp/controller/BattleController.class.php | 18 +++++++- webapp/models/BattleHistory.php | 47 ++++++++++++++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/doc/Battle.py b/doc/Battle.py index 962a709b..3b80df66 100644 --- a/doc/Battle.py +++ b/doc/Battle.py @@ -91,4 +91,18 @@ class Battle(object): _common.RspHead(), ] }, + { + 'desc': '历史战绩', + 'group': 'Battle', + 'url': 'webapp/index.php?c=Battle&a=getBattleHistory', + 'params': [ + _common.ReqHead(), + + ['mode', _common.BattleMember(), '0:pvp 1:排位 2:pve'] + ], + 'response': [ + _common.RspHead(), + ['!data', _common.BattleHistory(), '战绩数据'], + ] + }, ] diff --git a/doc/_common.py b/doc/_common.py index dc78e3b8..5b437a44 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -820,3 +820,29 @@ class BattleReward(object): ['weapon2', BattleCegReward(), '武器2奖励'], ['!items', [BattleItemReward()], '碎片奖励'], ] + +class BattleHistory(object): + + def __init__(self): + self.fields = [ + ['idx', 0, '唯一id'], + ['battle_uniid', 0, '战斗记录唯一id'], + ['account_id', '', '用户 account_id'], + ['match_mode', 0, '0: 匹配 pvp 1: 排位赛 2: pve'], + ['team_mode',0, '0:单人 1:组队'], + ['battle_rank', 0, '战斗排名'], + ['team_rank',0, '团队排名'], + ['is_win', 0, 'pve冒险是否胜利'], + ['kills',0, '击杀数'], + ['hero_id',0, '英雄 id'], + ['weapon1', 0, '枪械1 id'], + ['weapon2', 0, '枪械2 id'], + ['damage', 0, '伤害'], + ['battle_end_time', 0, '战斗结束时间'], + ['current_level_class', '', '当前用户段位'], + ['current_level_class_score', 0, '当前用户排位分'], + ['level_class_score_chg', 0, '排位分改变'], + ['pve_rank_score', 0, 'pve冒险积分'], + ['pve_kill_boss', 0, 'pve冒险是否击杀BOSS'], + ['battle_foreign_key', 0, '结算外键'], + ] \ No newline at end of file diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index af22e6d1..94ab3e4c 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -3,12 +3,13 @@ require_once('models/Hero.php'); require_once('models/Gun.php'); require_once('models/Chip.php'); +require_once('models/BattleHistory.php'); require_once('services/BattleDataService.php'); use phpcommon\SqlHelper; use models\Hero; use models\Gun; -use models\Chip; +use models\BattleHistory; class BattleController extends BaseAuthedController { @@ -159,4 +160,19 @@ class BattleController extends BaseAuthedController { myself()->_rspData($data); } + public function getBattleHistory(){ + $mode = getReqVal('mode', 0); + $historyList = BattleHistory::getMyBattleHistory(); + $data = array(); + foreach ($historyList as $history){ + if ($history['match_mode'] == $mode){ + array_push($data,BattleHistory::toDto($history)); + } + } + $list = BattleHistory::orderBy($data,'desc'); + $this->_rspData(array( + 'data' => $list + )); + } + } diff --git a/webapp/models/BattleHistory.php b/webapp/models/BattleHistory.php index a009fc65..5e9a50f1 100644 --- a/webapp/models/BattleHistory.php +++ b/webapp/models/BattleHistory.php @@ -3,6 +3,11 @@ namespace models; +require_once('models/Hero.php'); +require_once('models/Gun.php'); + +require_once('mt/Hero.php'); + use mt; use phpcommon\SqlHelper; class BattleHistory extends BaseModel @@ -28,4 +33,46 @@ class BattleHistory extends BaseModel return $row; } + public static function toDto($row){ + if ($row['hero_id']){ + $row['hero_id'] = Hero::find($row['hero_id'])['hero_id']; + } + if ($row['weapon1']){ + $row['weapon1'] = Gun::find($row['weapon1'])['gun_id']; + } + if ($row['weapon2']){ + $row['weapon2'] = Gun::find($row['weapon2'])['gun_id']; + } + return $row; + } + + public static function orderBy($data,$order){ + $len = count($data); + if ($len<=1){ + return $data; + } + if ($order == 'desc'){ + for ($i = 0; $i < $len - 1; $i++) { + for ($j = $i + 1; $j < $len; $j++) { + if ($data[$i]['idx'] < $data[$j]['idx']) { + $tmp = $data[$i]; + $data[$i] = $data[$j]; + $data[$j] = $tmp; + } + } + } + }else{ + for ($i = 0; $i < $len - 1; $i++) { + for ($j = $i + 1; $j < $len; $j++) { + if ($data[$i]['idx'] > $data[$j]['idx']) { + $tmp = $data[$i]; + $data[$i] = $data[$j]; + $data[$j] = $tmp; + } + } + } + } + return $data; + } + } \ No newline at end of file