From ae2f4264c170816297de4ea3e025a57dee326a06 Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Tue, 6 Feb 2024 16:53:55 +0800 Subject: [PATCH] 1 --- doc/Emoji.py | 98 ++++++----- doc/Ranking.py | 3 +- sql/gamedb2006_migrate_240129_01.sql | 15 ++ webapp/controller/EmojiController.class.php | 52 ++++-- webapp/controller/RankingController.class.php | 14 +- webapp/models/Emoji.php | 158 ++++++++++-------- webapp/models/RankBattle.php | 140 +++++++++++++++- webapp/services/TameBattleDataService.php | 100 +++++------ 8 files changed, 386 insertions(+), 194 deletions(-) create mode 100644 sql/gamedb2006_migrate_240129_01.sql diff --git a/doc/Emoji.py b/doc/Emoji.py index e18caec1..1d8f0dfe 100644 --- a/doc/Emoji.py +++ b/doc/Emoji.py @@ -1,45 +1,55 @@ -import _common - -class Emoji(object): - - def __init__(self): - self.apis = [ - { - 'name': 'getEmojiList', - 'desc': '表情列表', - 'group': 'Emoji', - 'url': 'webapp/index.php?c=Emoji&a=getEmojiList', - 'params': [ - _common.ReqHead(), - ], - 'response': [ - _common.RspHead(), - ['!data', [_common.Emoji()], '表情列表'], - ['use_emoji', [], '已选择的表情列表'], - ] - },{ - 'name': 'setEmoji', - 'desc': '设置表情', - 'group': 'Emoji', - 'url': 'webapp/index.php?c=Emoji&a=setEmoji', - 'params': [ - _common.ReqHead(), - ['item_id', '0', 'item_id'], - ], - 'response': [ - _common.RspHead(), - ] - },{ - 'name': 'cancel', - 'desc': '取消设置', - 'group': 'Emoji', - 'url': 'webapp/index.php?c=Emoji&a=cancel', - 'params': [ - _common.ReqHead(), - ['item_id', '0', 'item_id'], - ], - 'response': [ - _common.RspHead(), - ] - }, +import _common + +class Emoji(object): + + def __init__(self): + self.apis = [ + { + 'name': 'getEmojiList', + 'desc': '表情列表', + 'group': 'Emoji', + 'url': 'webapp/index.php?c=Emoji&a=getEmojiList', + 'params': [ + _common.ReqHead(), + ], + 'response': [ + _common.RspHead(), + ['!data', [_common.Emoji()], '表情列表'], + ['!use_emoji', [UsedEmoji()], '已选择的表情列表'], + ] + },{ + 'name': 'setEmoji', + 'desc': '设置表情', + 'group': 'Emoji', + 'url': 'webapp/index.php?c=Emoji&a=setEmoji', + 'params': [ + _common.ReqHead(), + ['item_id', '0', '表情itemid'], + ['slot_id', '0', '卡槽id'], + ], + 'response': [ + _common.RspHead(), + ] + },{ + 'name': 'cancel', + 'desc': '取消设置', + 'group': 'Emoji', + 'url': 'webapp/index.php?c=Emoji&a=cancel', + 'params': [ + _common.ReqHead(), + ['slot_id', '0', '卡槽id'], + ], + 'response': [ + _common.RspHead(), + ] + }, + ] + + +class UsedEmoji(object): + + def __init__(self): + self.fields = [ + ['item_id', 0, '表情itemid 0:未选择'], + ['slot_id', 0, '卡槽id'], ] \ No newline at end of file diff --git a/doc/Ranking.py b/doc/Ranking.py index 2e1fd0c1..bc0536ef 100644 --- a/doc/Ranking.py +++ b/doc/Ranking.py @@ -13,7 +13,8 @@ class Ranking(object): 'url': 'webapp/index.php?c=Ranking&a=rankingList', 'params': [ _common.ReqHead(), - ['type', 0, ' 1:场次榜 2:吃鸡榜 3:mvp榜 4:前三名榜 5:击杀榜'] + ['class', 0, ' 1:总榜 2:日榜 3:周榜 '], + ['type', 0, ' 1:场次榜 2:吃鸡榜 3:mvp榜 4:前三名榜 5:击杀榜'], ], 'response': [ _common.RspHead(), diff --git a/sql/gamedb2006_migrate_240129_01.sql b/sql/gamedb2006_migrate_240129_01.sql new file mode 100644 index 00000000..f74f97fd --- /dev/null +++ b/sql/gamedb2006_migrate_240129_01.sql @@ -0,0 +1,15 @@ +begin; + +alter table t_rank_battle add column `mode` int(11) NOT NULL DEFAULT '0' COMMENT '1:4v4 2:pvp '; +alter table t_rank_battle add column `class` int(11) NOT NULL DEFAULT '0' COMMENT '1:总榜 2:日榜 3:周榜'; +alter table t_rank_battle add column `writetime` int(11) NOT NULL DEFAULT '0' COMMENT '记录时间'; +alter table t_rank_battle add UNIQUE KEY `account_mode_class_type_writetime` (`account_id`,`mode`,`class`,`type`,`writetime`); +alter table t_rank_battle drop index account_id_type; + + +alter table t_user_use_emoji add column `used` mediumblob COMMENT '使用的表情'; +alter table t_user_use_emoji drop column value; + +insert into version (version) values(2024012901); + +commit; diff --git a/webapp/controller/EmojiController.class.php b/webapp/controller/EmojiController.class.php index cfa87fed..fa84e5a0 100644 --- a/webapp/controller/EmojiController.class.php +++ b/webapp/controller/EmojiController.class.php @@ -19,9 +19,12 @@ class EmojiController extends BaseAuthedController public function getEmojiList(){ $list = Emoji::emojiList(); $uses = Emoji::getUseEmoji(); + $temp = array_map(function ($val){ + return $val['item_id']; + },$uses); $data = array(); foreach ($list as $val){ - if(in_array($val,$uses)){ + if(in_array($val, $temp)){ array_push($data, array( 'item_id'=>$val, @@ -45,41 +48,54 @@ class EmojiController extends BaseAuthedController public function setEmoji(){ $itemId = getReqVal('item_id', ''); + $slotId = getReqVal('slot_id', 0); if(! in_array($itemId,Emoji::emojiList())){ $this->_rspErr(1, 'item_id parameter error'); return; } + if($slotId < 1 || $slotId > 6){ + $this->_rspErr(1, 'slot_id parameter error'); + return; + } $uses = Emoji::getUseEmoji(); - if(in_array($itemId,$uses)){ + $temp = array_map(function ($val){ + return $val['item_id']; + },$uses); + if(in_array($itemId,$temp)){ $this->_rspErr(1, 'The emoji has been used'); return; } - if(count($uses) >= kMaxEmojiNum){ - $this->_rspErr(1, 'To maximize'); - return; + if ($uses){ + foreach ($uses as &$val){ + if ($val['slot_id'] == $slotId){ + $val['item_id'] = $itemId; + } + } + }else{ + array_push($uses,array( + 'item_id' => $itemId, + "slot_id" => $slotId + )); } - array_push($uses,$itemId); - Emoji::updateEmoji( implode('|',$uses) ); + + Emoji::updateEmoji( json_encode($uses)); $this->_rspOk(); } public function cancel(){ - $itemId = getReqVal('item_id', ''); - if(! in_array($itemId,Emoji::emojiList())){ - $this->_rspErr(1, 'item_id parameter error'); + $slotId = getReqVal('slot_id', 0); + if($slotId < 1 || $slotId > 6){ + $this->_rspErr(1, 'slot_id parameter error'); return; } $uses = Emoji::getUseEmoji(); - if(! in_array($itemId,$uses)){ - $this->_rspErr(1, 'The emoji is not used'); - return; - } - foreach ($uses as $k=>$v){ - if ($itemId == $v){ - unset($uses[$k]); + + foreach ($uses as &$val){ + if ($val['slot_id'] == $slotId){ + $val['item_id'] = 0; } } - Emoji::updateEmoji(implode('|',$uses)); + Emoji::updateEmoji(json_encode($uses)); $this->_rspOk(); } } \ No newline at end of file diff --git a/webapp/controller/RankingController.class.php b/webapp/controller/RankingController.class.php index bc8b58ae..8cb91307 100644 --- a/webapp/controller/RankingController.class.php +++ b/webapp/controller/RankingController.class.php @@ -56,13 +56,23 @@ class RankingController extends BaseAuthedController { public function rankingList() { $userInfo = $this->_getOrmUserInfo(); + $mode = getReqVal('mode', 0); + $class = getReqVal('class', 0); $type = getReqVal('type', 0); + if (! RankBattle::inspectMode($mode)){ + $this->_rspErr(1, 'mode param error'); + return; + } + if (! RankBattle::inspectClass($class)){ + $this->_rspErr(1, 'class param error'); + return; + } if (! RankBattle::inspectType($type)){ $this->_rspErr(1, 'type param error'); return; } - $list = RankBattle::getTopLimit($type,100); + $list = RankBattle::getTopLimit($mode,$class,$type,100); $rankingList = array(); $ranked = 1; @@ -90,7 +100,7 @@ class RankingController extends BaseAuthedController { $myRanked['modifytime'] = $row['modifytime']; } - $lists = RankBattle::getTopLimit($type,10000,array('account_id')); + $lists = RankBattle::getTopLimit($mode,$class,$type,10000,array('account_id')); if (count($lists) > 0){ foreach ($lists as $k=>$row){ if ($userInfo['account_id'] == $row['account_id']){ diff --git a/webapp/models/Emoji.php b/webapp/models/Emoji.php index 9d5ffa98..c49c1dde 100644 --- a/webapp/models/Emoji.php +++ b/webapp/models/Emoji.php @@ -1,68 +1,92 @@ -_getSelfMysql(), - 't_user_use_emoji', - array( - 'account_id'=> myself()->_getAccountId() - ) - ); - $value = array(); - if ($row){ - $value = $row['value'] ? explode('|',$row['value']) : array() ; - }else{ - $value= self::defaultUseEmoji(); - self::updateEmoji(implode('|',$value)); - } - return $value; - } - - public static function updateEmoji($fields){ - SqlHelper::upsert - (myself()->_getSelfMysql(), - 't_user_use_emoji', - array( - 'account_id' => myself()->_getAccountId(), - ), - array( - 'value' => $fields, - 'modifytime' => myself()->_getNowTime(), - ), - array( - 'account_id' => myself()->_getAccountId(), - 'value' => $fields, - 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime(), - ) - ); - } - + 200001, + "slot_id" => 1 + ), + array( + 'item_id' => 200002, + "slot_id" => 2 + ), + array( + 'item_id' => 200003, + "slot_id" => 3 + ), + array( + 'item_id' => 200004, + "slot_id" => 4 + ), + array( + 'item_id' => 200005, + "slot_id" => 5 + ), + array( + 'item_id' => 200006, + "slot_id" => 6 + ), + ); + } + + private static function defaultEmoji(){ + $default = array(); + $meta = mt\Parameter::getByName('emoji_default'); + if ($meta){ + $default = explode('|',$meta['param_value']) ; + } + return $default; + } + + public static function emojiList(){ + $data = self::DefaultEmoji(); + //查询用户新获得的表情(t_emoji 表) + + return $data; + } + + public static function getUseEmoji(){ + $row = SqlHelper::ormSelectOne( + myself()->_getSelfMysql(), + 't_user_use_emoji', + array( + 'account_id'=> myself()->_getAccountId() + ) + ); + if ($row){ + $useEmojiList = emptyReplace(json_decode($row['used'], true), array()); + }else{ + $useEmojiList= self::defaultUseEmoji(); + self::updateEmoji(json_encode($useEmojiList)); + } + return $useEmojiList; + } + + public static function updateEmoji($fields){ + SqlHelper::upsert + (myself()->_getSelfMysql(), + 't_user_use_emoji', + array( + 'account_id' => myself()->_getAccountId(), + ), + array( + 'used' => $fields, + 'modifytime' => myself()->_getNowTime(), + ), + array( + 'account_id' => myself()->_getAccountId(), + 'used' => $fields, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ) + ); + } + } \ No newline at end of file diff --git a/webapp/models/RankBattle.php b/webapp/models/RankBattle.php index 82333057..62be7ecf 100644 --- a/webapp/models/RankBattle.php +++ b/webapp/models/RankBattle.php @@ -14,6 +14,23 @@ class RankBattle extends BaseModel const TOP_THREE_TIMES = 4; const KILL_TIMES = 5; + const OVERALL_CHARTS = 1; + const DAILY_CHARTS = 2; + const WEEKLY_CHARTS = 3; + + const MOBA_DATA = 1; + const PVP_DATA = 2; + + public static function inspectMode($mode){ + if (!in_array($mode,array( + self::MOBA_DATA, + self::PVP_DATA, + ))){ + return false; + } + return true; + } + public static function inspectType($type){ if (!in_array($type,array( self::GAME_TIMES, @@ -27,9 +44,20 @@ class RankBattle extends BaseModel return true; } + public static function inspectClass($class){ + if (!in_array($class,array( + self::OVERALL_CHARTS, + self::DAILY_CHARTS, + self::WEEKLY_CHARTS, + ))){ + return false; + } + return true; + } - public static function getTopLimit($type,$limit,$fieldKv=null){ - if (!self::inspectType($type)){ + + public static function getTopLimit($mode, $class, $type, $limit, $fieldKv=null){ + if (!self::inspectType($type) || self::inspectClass($class)){ return array(); } if (!$fieldKv){ @@ -37,11 +65,43 @@ class RankBattle extends BaseModel }else{ $field = implode(',',$fieldKv); } + $sql = ''; + $whereKv = array(); + switch ($class) { + case self::OVERALL_CHARTS : { + $sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type order by value desc,modifytime asc limit {$limit} "; + $whereKv = array( + "mode" => $mode, + "class" => self::OVERALL_CHARTS, + "type" => $type, + ); + } + break; + case self::DAILY_CHARTS : { + $sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type and writetime=:writetime order by value desc,modifytime asc limit {$limit} "; + $whereKv = array( + "mode" => $mode, + "class" => self::DAILY_CHARTS, + "type" => $type, + "writetime" => myself()->_getNowDaySeconds(), + ); + } + break; + case self::WEEKLY_CHARTS : { + $sql = "select {$field} from t_rank_battle where mode=:mode and class =:class and type=:type and writetime=:writetime order by value desc,modifytime asc limit {$limit} "; + $whereKv = array( + "mode" => $mode, + "class" => self::DAILY_CHARTS, + "type" => $type, + "writetime" => myself()->_getMondaySeconds(), + ); + } + } - $sql = "select {$field} from t_rank_battle where type=:type order by value desc,modifytime asc limit {$limit} "; - $whereKv = array( - "type" => $type, - ); +// $sql = "select {$field} from t_rank_battle where type=:type order by value desc,modifytime asc limit {$limit} "; +// $whereKv = array( +// "type" => $type, +// ); $rows = myself()->_getSelfMysql()->execQuery($sql,$whereKv); if (!$rows){ @@ -65,7 +125,7 @@ class RankBattle extends BaseModel return $row ? $row : null; } - public static function upsert($account,$type,$val){ + public static function upsert($account,$mode,$type,$val){ if (!$account){ return; } @@ -74,7 +134,39 @@ class RankBattle extends BaseModel 't_rank_battle', array( 'account_id' => $account, + 'mode' => $mode, 'type' => $type, + 'class' => self::OVERALL_CHARTS, + ), + array( + 'value' => function () use($val) { + return "value + ${val}"; + }, + 'modifytime' => myself()->_getNowTime(), + 'writetime' => myself()->_getNowTime(), + ), + array( + 'account_id' => $account, + 'channel' => phpcommon\extractChannel($account), + 'class' => self::OVERALL_CHARTS, + 'mode' => $mode, + 'type' => $type, + 'value' => $val, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + 'writetime' => myself()->_getNowTime(), + ) + ); + + SqlHelper::upsert + (myself()->_getSelfMysql(), + 't_rank_battle', + array( + 'account_id' => $account, + 'mode' => $mode, + 'type' => $type, + 'class' => self::DAILY_CHARTS, + 'writetime' => myself()->_getNowDaySeconds(), ), array( 'value' => function () use($val) { @@ -85,10 +177,42 @@ class RankBattle extends BaseModel array( 'account_id' => $account, 'channel' => phpcommon\extractChannel($account), + 'class' => self::DAILY_CHARTS, + 'mode' => $mode, 'type' => $type, 'value' => $val, 'createtime' => myself()->_getNowTime(), - 'modifytime' => myself()->_getNowTime() + 'modifytime' => myself()->_getNowTime(), + 'writetime' => myself()->_getNowDaySeconds(), + ) + ); + + SqlHelper::upsert + (myself()->_getSelfMysql(), + 't_rank_battle', + array( + 'account_id' => $account, + 'mode' => $mode, + 'type' => $type, + 'class' => self::WEEKLY_CHARTS, + 'writetime' => myself()->_getMondaySeconds(), + ), + array( + 'value' => function () use($val) { + return "value + ${val}"; + }, + 'modifytime' => myself()->_getNowTime(), + ), + array( + 'account_id' => $account, + 'channel' => phpcommon\extractChannel($account), + 'class' => self::WEEKLY_CHARTS, + 'mode' => $mode, + 'type' => $type, + 'value' => $val, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + 'writetime' => myself()->_getMondaySeconds(), ) ); } diff --git a/webapp/services/TameBattleDataService.php b/webapp/services/TameBattleDataService.php index 21fb7a59..40afd27e 100644 --- a/webapp/services/TameBattleDataService.php +++ b/webapp/services/TameBattleDataService.php @@ -99,7 +99,8 @@ class TameBattleDataService extends BaseService { //记录战斗有效行为 $this->_updateBattleData(); - + //记录战斗数据的排行榜 + $this->recordBattleRanking(); switch ($matchMode) { //PVP模式 case self::ROOM_MODE_PVP: @@ -127,11 +128,6 @@ class TameBattleDataService extends BaseService { default:{} break; } - - //记录战斗数据的排行榜 - $this->recordBattleRanking(); -// //结算用户star数量 -// $this->rewardStarNum(); } break; //PVE模式 @@ -159,61 +155,57 @@ class TameBattleDataService extends BaseService { } -// //每局战斗结算star数量 -// private function rewardStarNum(){ -// $paramMeta = mt\Parameter::getByName('star_get_num'); -// if ($paramMeta){ -// $star_get_num = getXVal($paramMeta,'param_value', 0); -// $num_arr = explode('|',$star_get_num); -// $rank = getXVal($this->battleInfo,'pvp_personal_rank', 0); -// if ($rank>count($num_arr) || $rank<1){ -// $finalNum = 0; -// }else{ -// $finalNum = $this->calFinalStarNum($num_arr[$rank-1]); -// } -// $items = array( -// array( -// 'item_id'=>V_ITEM_STAR, -// 'item_num'=>$finalNum -// ) -// );print_r($items); -// $propertyChgService = new services\PropertyChgService(); -// $awardService = new services\AwardService(); -//// myself()->_addItems($items, $awardService,$propertyChgService); -// myself()->_incDailyV(TN_DAILY_GET_STAR_NUM, 0,$finalNum); -// } -// } - //记录战斗数据的排行榜 private function recordBattleRanking(){ $account = getXVal($this->battleInfo,'account_id', 0); - //游戏场次 (存活30S算有效场次) - if (getXVal($this->battleInfo,'pvp_survia_time', 0)/1000 > 30 && - getXVal($this->battleInfo,'abandon_battle', 0) == 0){ - RankBattle::upsert($account,RankBattle::GAME_TIMES,1); - } - //吃鸡数 //pvp_team_rank - if (getXVal($this->allInfo,'pvp_team_rank', 0) == 1){ - RankBattle::upsert($account,RankBattle::WIN_TIMES,1); + $room_mode = getXVal($this->allInfo,'room_mode', 0); + switch ($room_mode){ + case self::ROOM_MODE_PVP : { + //游戏场次 (存活30S算有效场次) + if (getXVal($this->battleInfo,'pvp_survia_time', 0)/1000 > 30 && + getXVal($this->battleInfo,'abandon_battle', 0) == 0){ + RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::GAME_TIMES,1); + } + //吃鸡数 //pvp_team_rank +// print_r(getXVal($this->battleInfo,'pvp_kill', 0));die; + if (getXVal($this->allInfo,'pvp_team_rank', 0) == 1){ + RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::WIN_TIMES,1); + } + + //mvp + if (getXVal($this->battleInfo,'is_mvp', 0) == 1){ + RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::MVP_TIMES,1); + } + + //前三 + if (getXVal($this->allInfo,'pvp_team_rank', 0) <= 3){ + RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::TOP_THREE_TIMES,1); + } + + //击杀 + if (getXVal($this->battleInfo,'pvp_kill', 0) > 0){ + RankBattle::upsert($account,RankBattle::PVP_DATA,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'pvp_kill', 0)); + } + } + break; + case self::ROOM_MODE_MOBA : { + //游戏场次 (存活30S算有效场次) + if (! getXVal($this->battleInfo,'is_run_away', 0)){ + RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::GAME_TIMES,1); + } + //胜利数 + if (getXVal($this->allInfo,'victory', 0)){ + RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::WIN_TIMES,1); + } + //击杀 + if (getXVal($this->battleInfo,'kills', 0) > 0){ + RankBattle::upsert($account,RankBattle::MOBA_DATA,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'kills', 0)); + } + } } - //mvp - if (getXVal($this->battleInfo,'is_mvp', 0) == 1){ - RankBattle::upsert($account,RankBattle::MVP_TIMES,1); - } - - //前三 - if (getXVal($this->allInfo,'pvp_team_rank', 0) <= 3){ - RankBattle::upsert($account,RankBattle::TOP_THREE_TIMES,1); - } - - //击杀 - if (getXVal($this->battleInfo,'pvp_kill', 0) > 0){ - myself()->_incV(TN_TOTAL_KILLS_NUM, 0, getXVal($this->battleInfo,'pvp_kill', 0)); - RankBattle::upsert($account,RankBattle::KILL_TIMES,getXVal($this->battleInfo,'pvp_kill', 0)); - } } private function updatePveData()