From c2c83eb65a1ad8c03eac0cab0194cfa3ce7ca5b3 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Mon, 22 Nov 2021 15:54:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90roleInfo=E6=94=B9=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/Role.py | 1 + doc/_common.py | 8 + .../controller/BaseAuthedController.class.php | 116 ++++++ webapp/controller/RoleController.class.php | 333 ++++-------------- webapp/mt/Season.php | 13 + 5 files changed, 214 insertions(+), 257 deletions(-) diff --git a/doc/Role.py b/doc/Role.py index 968c89ac..77241fe9 100644 --- a/doc/Role.py +++ b/doc/Role.py @@ -15,6 +15,7 @@ class Role(object): ], 'response': [ _common.RspHead(), + _common.RoleInfo(), ] }, { diff --git a/doc/_common.py b/doc/_common.py index a1fa2073..86c49242 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -32,3 +32,11 @@ class GunSkinInfo(object): ['gun_id', 0, '枪支id'], ['skin_id', 0, '皮肤id'], ] + +class RoleInfo(object): + + def __init__(self): + self.fields = [ + ['gun_id', 0, '枪支id'], + ['skin_id', 0, '皮肤id'], + ] diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index af6a3029..79cae32c 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -101,6 +101,47 @@ class BaseAuthedController extends BaseController { return $row; } + protected function getOrmUserInfo() + { + $row = phpcommon\SqlHelper::ormSelectOne + ($this->getSelfMysql(), + 'user', + array( + 'accountid' => $this->getAccountId() + ) + ); + if (empty($row)) { + phpcommon\sendError(500, '服务器内部错误'); + error_log('getUserInfo error '. $this->getAccountId()); + die(); + } + return $row; + } + + protected function safeGetOrmUserInfo() + { + $row = phpcommon\SqlHelper::ormSelectOne + ($this->getSelfMysql(), + 'user', + array( + 'accountid' => $this->getAccountId() + ) + ); + return $row ? $row : null; + } + + protected function updateUserInfo($fieldsKv) + { + phpcommon\SqlHelper::update + ($this->getSelfMysql(), + 'user', + array( + 'accountid' => $this->getAccountId() + ), + $fieldsKv + ); + } + protected function sendDataToClient($_code,$_msg,$_data) { echo json_encode(array( @@ -413,4 +454,79 @@ class BaseAuthedController extends BaseController { return true; } + protected function getDtoUserInfo($userInfo) + { + return array( + 'game_times' => $userInfo['game_times'], + 'win_times' => $userInfo['win_times'], + 'high_kill' => $userInfo['kill_his'], + 'kills' => $userInfo['kills'], + 'high_harm' => $userInfo['harm_his'], + 'harm' => $userInfo['harm'], + 'add_HP' => $userInfo['add_HP'], + 'alive_time' => $userInfo['alive_time'], + 'coin_num' => $userInfo['coin_num'], + 'first_fight' => $userInfo['first_fight'], + 'collect_status' => $userInfo['collect_status'], + 'keys_num' => $userInfo['keys_num'], + 'kefu_status' => $userInfo['kefu_status'], + 'box_num' => $userInfo['box_num'], + 'diamond_num' => $userInfo['diamond_num'], + 'pass_status' => $userInfo['pass_status'], + 'season_status' => $userInfo['season_status'], + 'first_gift' => $userInfo['first_gift'], + 'sum_coin' => $userInfo['sum_coin'], + 'recharge_times_total' => $userInfo['recharge_times_total'], + 'first_login' => $userInfo['first_login'], + 'daily_first_login' =>$userInfo['daily_first_login'], + 'vip_score' => $userInfo['vip_score'], + 'coin_nums' => $userInfo['coin_num'], + 'diamond_nums' => $userInfo['diamond_num'], + 'free_box' => $userInfo['free_box'], + 'season_games' => $userInfo['season_games'], + 'season_win' => $userInfo['season_win'], + 'sea_max_kill' => $userInfo['sea_max_kill'], + 'sea_max_hart' => $userInfo['sea_max_hart'], + 'sea_avg_kill' => $userInfo['sea_avg_kill'], + 'free_dou_lot_ticket' => $userInfo['free_dou_lot_ticket'], + 'free_lot_ticket' => $userInfo['free_lot_ticket'], + 'time' => phpcommon\getNowTime(), + 'newhand' => $userInfo['newhand'], + 'coin_times' => $userInfo['coin_times'], + 'newInfo' => $userInfo['newInfo'], + 'first_day_ad' => $userInfo['first_day_ad'], + 'integral' => $userInfo['integral'], + 'share_video_times' => $userInfo['share_video_times'], + 'share_video_sums' => $userInfo['share_video_sums'], + 'act_video_status' => $userInfo['act_video_status'], + 'act_ad_status' => $userInfo['act_ad_status'], + 'biogame_times' => $userInfo['biogame_times'], + 'shop_view_times' => $userInfo['shop_view_times'], + 'new_first_equip' => $userInfo['new_first_equip'], + 'newhand2' =>$userInfo['newhand2'], + 'game_times2'=>$userInfo['game_times2'], + 'view_times2'=>$userInfo['view_times2'], + 'guildcoin_num'=> $userInfo['guildcoin_num'], + 'new_second_equip' => $userInfo['new_second_equip'], + 'rmb_num' => $userInfo['rmb_num'], + 'max_single_recharge' => $userInfo['max_single_recharge'], + 'passcard' => $userInfo['passcard'], + 'rmb_lot_ticket' => $userInfo['rmb_lot_ticket'], + 'daily_max_single' => $userInfo['daily_max_single'], + 'head_kuang_id' => $userInfo['head_kuang_id'], + 'daily_score' => $userInfo['daily_score'], + 'score' => $userInfo['score'], + 'daily_offline' => $userInfo['daily_offline'], + 'user_name' => $userInfo['user_name'], + 'avatar_url' => $userInfo['avatar_url'], + 'create_user' => $userInfo['create_user'], + 'sex' => $userInfo['sex'], + 'lv' => $userInfo['lv'], + 'lv_exp'=> $userInfo['lv_exp'], + 'hiid' => $userInfo['hi_id'], + 'hero_id' => $userInfo['hero_id'], + 'max_seasonScore' => $userInfo['max_integral'] + ); + } + } diff --git a/webapp/controller/RoleController.class.php b/webapp/controller/RoleController.class.php index b6cbdaf5..51031018 100644 --- a/webapp/controller/RoleController.class.php +++ b/webapp/controller/RoleController.class.php @@ -24,269 +24,88 @@ class RoleController extends BaseAuthedController { $switch_id = 1; $switch_id = isset($_REQUEST['switch_id']); //new classes\Quest(); - //创建任务对象开始-- $testTask = new NTaskController(); $testTask->updateTaskToDB(QUEST_DAY_LOGIN,1); - //创建任务对象结束-- - - $conn = $this->getSelfMysql(); $this->updateSwitch($account_id, $switch_id); - $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - if (!$row) { - $season_time = 0; - $season_meta_table = require('../res/season@season.php'); - for ($i = 1; $i <= count($season_meta_table); $i++) { - $season = mt\Season::getOldSeason($i); - if (phpcommon\getNowTime() >= strtotime($season['open_time']) && phpcommon\getNowTime() <= strtotime($season['end_time'])) { - $season_time = strtotime($season['end_time']); - break; - } - } - $ret = $conn->execScript('INSERT INTO user(accountid, user_name, avatar_url, game_times, win_times, kills, harm, add_HP, alive_time, coin_num, integral, kill_his, alive_time_his, harm_his, add_HP_his, act_share_time, act_share_status, create_time, modify_time, first_fight, collect_status, keys_num, battle_re_times, shop_flush_times, kefu_status, sign_sum, box_num, diamond_num, sum_coin, pass_status, score, season_status, recharge_times_total, first_gift, season_time, free_coin, free_diamond, season_end_score, kill_modifytime, win_modifytime, rank_modifytime, vip_score, first_login, daily_first_login, daily_time, free_box, update_time, season_games, season_win, sea_max_kill, sea_max_hart, sea_avg_kill, free_lot_ticket, free_dou_lot_ticket, daily_order1, daily_order2, daily_order3, first_bee, newhand, coin_times, newInfo, first_day_ad, share_video_times, share_video_sums, act_video_status, act_ad_status, biogame_times, shop_view_times, new_first_equip, newhand2,game_times2, view_times2, guildcoin_num, new_second_equip, rmb_num, max_single_recharge, passcard, rmb_lot_ticket, daily_max_single, head_kuang_id, daily_score, daily_offline, create_user, sex, sumlot_coin, max_integral,lv,lv_exp,money_of_week,team_name,hi_id,hero_id) ' . - ' VALUES(:accountid, :user_name, :avatar_url, 0, 0, 0, 0, 0, 0, 10000, 0, 0, 0, 0, 0, 0, 0, :create_time, :modify_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, :season_time, 0, 0, 0, 0, 0, 0, 0, 0, 0, :daily_time, 0,:update_time,0,0,0,0,0,0,0,0,0,0,0,0,0,:newInfo,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0, 0, 0, 19003, 0, 0, 0, 2, 0, 0,0,0,0,"",18001,30100) ' . - ' ON DUPLICATE KEY UPDATE accountid=:accountid, user_name=:user_name, avatar_url=:avatar_url, game_times=0, win_times=0, kills=0, harm=0, add_HP=0, alive_time=0, coin_num=0, integral=0, kill_his=0, alive_time_his=0, harm_his=0, add_HP_his=0, act_share_time=0, act_share_status=0, modify_time=:modify_time, first_fight=0, collect_status=0, keys_num=0, battle_re_times=0, shop_flush_times=0, kefu_status=0, sign_sum=0, box_num=0, diamond_num=0, sum_coin=0, pass_status=0, score=0, season_status=1, recharge_times_total=0, first_gift=0, season_time=:season_time, free_coin=0, free_diamond=0, season_end_score=0, kill_modifytime=0, win_modifytime=0, rank_modifytime=0, vip_score=0, first_login=0, daily_first_login=0, daily_time=:daily_time, free_box=0, update_time=:update_time, season_games=0, season_win=0, sea_max_kill=0, sea_max_hart=0, sea_avg_kill=0, free_lot_ticket=0, free_dou_lot_ticket=0, daily_order1=0, daily_order2=0, daily_order3=0, first_bee=0, newhand=0, coin_times=0, newInfo=:newInfo, first_day_ad=0, share_video_times=0, share_video_sums=0, act_video_status=0, act_ad_status=0, biogame_times=0, shop_view_times=0, new_first_equip=0, newhand2=0, game_times2=0,view_times2=0, guildcoin_num=0, new_second_equip=2, rmb_num=0, max_single_recharge=0, passcard=0, rmb_lot_ticket=0, daily_max_single=0, head_kuang_id=0, daily_score=0, daily_offline=0, create_user=0, sex=2, sumlot_coin=0, max_integral=0,lv_exp = 0,money_of_week = 0 ,team_name = "",hi_id = 18001,hero_id = 30100;', - array( - ':accountid' => $account_id, - ':user_name' => $user_name, - ':avatar_url' => $avatar_url, - ':create_time' => phpcommon\getNowTime(), - ':modify_time' => phpcommon\getNowTime(), - ':daily_time' => 0, - ':update_time' => phpcommon\getNowTime(), - ':newInfo' => '', - ':season_time' => $season_time - )); - if (!$ret) { - die(); - return; - } - //赠送玩家英雄开始-- - $this->addHeroToDB(); - //赠送玩家英雄结束-- - //新玩家赠送材料,表情 - $this->newPlayerReward($account_id); - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'game_times' => 0, - 'win_times' => 0, - 'high_kill' => 0, - 'kills' => 0, - 'high_harm' => 0, - 'harm' => 0, - 'add_HP' => 0, - 'alive_time' => 0, - 'coin_num' => 10000, - 'first_fight' => 0, - 'collect_status' => 0, - 'keys_num' => 0, - 'kefu_status' => 0, - 'box_num' => 0, - 'diamond_num' => 0, - 'pass_status' => 0, - 'season_status' => 1, - 'first_gift' => 0, - 'sum_coin' => 0, - 'recharge_times_total' => 0, - 'first_login' => 0, - 'daily_first_login' => 0, - 'free_box' => 0, - 'season_games' => 0, - 'season_win' => 0, - 'sea_max_kill' => 0, - 'sea_max_hart' => 0, - 'sea_avg_kill' => 0, - 'free_lot_ticket' => 0, - 'free_dou_lot_ticket' => 0, - 'time' => phpcommon\getNowTime(), - 'newhand' => 0, - 'vip_score' => 0, - 'coin_times' => 0, - 'newInfo' => '', - 'first_day_ad' => 0, - 'integral' => 0, - 'share_video_times' => 0, - 'share_video_sums' => 0, - 'act_video_status' => 0, - 'act_ad_status' => 0, - 'biogame_times' => 0, - 'coin_nums' => 10000, - 'diamond_times' => 0, - 'shop_view_times' => 0, - 'new_first_equip' => 0, - 'newhand2' =>0, - 'game_times2'=>0, - 'view_times2'=>0, - 'guildcoin_num' => 0, - 'new_second_equip' => 2, - 'rmb_num' => 0, - 'max_single_recharge' => 0, - 'passcard' => 0, - 'rmb_lot_ticket' => 0, - 'daily_max_single' => 0, - 'head_kuang_id' => 0, - 'daily_score' => 0, - 'score' => 0, - 'daily_offline' => 0, - 'user_name' => $user_name, - 'avatar_url' => $avatar_url, - 'create_user' => 0, - 'sex' => 2, - 'lv' => 0, - 'lv_exp'=> 0, - 'hiid' => 18001, - 'hero_id' => 30100, - 'max_seasonScore' => 0 - )); - } else { - // if ($avatar_url != '') { - // if ($user_name != $row['user_name']) { - // $ret = $conn->execScript('UPDATE user SET user_name=:user_name, modify_time=:modify_time ' . - // ' WHERE accountid=:accountid;', - // array( - // ':accountid' => $account_id, - // ':user_name' => $user_name, - // ':modify_time' => phpcommon\getNowTime() - // )); - // } - // if ($avatar_url != $row['avatar_url']) { - // $ret = $conn->execScript('UPDATE user SET avatar_url=:avatar_url, modify_time=:modify_time ' . - // ' WHERE accountid=:accountid;', - // array( - // ':accountid' => $account_id, - // ':avatar_url' => $avatar_url, - // ':modify_time' => phpcommon\getNowTime() - // )); - // } - // } - $nowTime = phpcommon\getdayseconds(phpcommon\getNowTime()); - $daily_first_login = $row['daily_first_login']; - $coin_times = $row['coin_times']; - $kefu_status = $row['kefu_status']; - $first_day_ad = $row['first_day_ad']; - $share_video_times = $row['share_video_times']; - $act_ad_status = $row['act_ad_status']; - $new_second_equip = $row['new_second_equip']; - $passcard = $row['passcard']; - if ($row['vip_score'] >= 5 && $act_ad_status != 2) { - $act_ad_status = 1; - $ret = $conn->execScript('UPDATE user SET act_ad_status=:act_ad_status WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':act_ad_status' => $act_ad_status - )); - if (!$ret) { - die(); - return; - } - } - if ($row['update_time'] == 0 || ($nowTime - phpcommon\getdayseconds($row['update_time']) > 0)) { - if ($new_second_equip == 2 && $row['new_first_equip'] == 1) { - $new_second_equip = 0; - } - $ret = $conn->execScript('UPDATE user SET daily_first_login=0, free_box=0, kefu_status=0, coin_times=0, ' . - 'modify_time=:modify_time, first_day_ad=0, share_video_times=0, new_second_equip=:new_second_equip, daily_max_single=0, daily_score=0, daily_offline=0 WHERE accountid=:accountid;', - array( - ':accountid' => $account_id, - ':modify_time' => phpcommon\getNowTime(), - ':new_second_equip' => $new_second_equip, - )); - if (!$ret) { - die(); - return; - } - $daily_first_login = 0; - $kefu_status = 0; - $coin_times = 0; - $first_day_ad = 0; - $share_video_times = 0; - if (phpcommon\getNowTime() > $row['season_time'] && $row['season_time'] != 0) { - $this->updateSeasonStatus($account_id); - } - } - $row = $conn->execQueryOne('SELECT * FROM user WHERE accountid=:accountid;', - array( - ':accountid' => $account_id - )); - echo json_encode(array( - 'errcode' => 0, - 'errmsg' => '', - 'game_times' => $row['game_times'], - 'win_times' => $row['win_times'], - 'high_kill' => $row['kill_his'], - 'kills' => $row['kills'], - 'high_harm' => $row['harm_his'], - 'harm' => $row['harm'], - 'add_HP' => $row['add_HP'], - 'alive_time' => $row['alive_time'], - 'coin_num' => $row['coin_num'], - 'first_fight' => $row['first_fight'], - 'collect_status' => $row['collect_status'], - 'keys_num' => $row['keys_num'], - 'kefu_status' => $kefu_status, - 'box_num' => $row['box_num'], - 'diamond_num' => $row['diamond_num'], - 'pass_status' => $row['pass_status'], - 'season_status' => $row['season_status'], - 'first_gift' => $row['first_gift'], - 'sum_coin' => $row['sum_coin'], - 'recharge_times_total' => $row['recharge_times_total'], - 'first_login' => $row['first_login'], - 'daily_first_login' =>$daily_first_login, - 'vip_score' => $row['vip_score'], - 'coin_nums' => $row['coin_num'], - 'diamond_nums' => $row['diamond_num'], - 'free_box' => $row['free_box'], - 'season_games' => $row['season_games'], - 'season_win' => $row['season_win'], - 'sea_max_kill' => $row['sea_max_kill'], - 'sea_max_hart' => $row['sea_max_hart'], - 'sea_avg_kill' => $row['sea_avg_kill'], - 'free_dou_lot_ticket' => $row['free_dou_lot_ticket'], - 'free_lot_ticket' => $row['free_lot_ticket'], - 'time' => phpcommon\getNowTime(), - 'newhand' => $row['newhand'], - 'coin_times' => $coin_times, - 'newInfo' => $row['newInfo'], - 'first_day_ad' => $first_day_ad, - 'integral' => $row['integral'], - 'share_video_times' => $share_video_times, - 'share_video_sums' => $row['share_video_sums'], - 'act_video_status' => $row['act_video_status'], - 'act_ad_status' => $act_ad_status, - 'biogame_times' => $row['biogame_times'], - 'shop_view_times' => $row['shop_view_times'], - 'new_first_equip' => $row['new_first_equip'], - 'newhand2' =>$row['newhand2'], - 'game_times2'=>$row['game_times2'], - 'view_times2'=>$row['view_times2'], - 'guildcoin_num'=> $row['guildcoin_num'], - 'new_second_equip' => $new_second_equip, - 'rmb_num' => $row['rmb_num'], - 'max_single_recharge' => $row['max_single_recharge'], - 'passcard' => $row['passcard'], - 'rmb_lot_ticket' => $row['rmb_lot_ticket'], - 'daily_max_single' => $row['daily_max_single'], - 'head_kuang_id' => $row['head_kuang_id'], - 'daily_score' => $row['daily_score'], - 'score' => $row['score'], - 'daily_offline' => $row['daily_offline'], - 'user_name' => $row['user_name'], - 'avatar_url' => $row['avatar_url'], - 'create_user' => $row['create_user'], - 'sex' => $row['sex'], - 'lv' => $row['lv'], - 'lv_exp'=> $row['lv_exp'], - 'hiid' => $row['hi_id'], - 'hero_id' => $row['hero_id'], - 'max_seasonScore' => $row['max_integral'] - )); + $userInfo = $this->safeGetOrmUserInfo(); + if (!$userInfo) { + $this->createNewUser(); + $userInfo = $this->getOrmUserInfo(); } + if ($this->loginCheck($userInfo)) { + $userInfo = $this->getOrmUserInfo(); + } + $dtoUser = $this->getDtoUserInfo($userInfo); + $dtoUser['errcode'] = 0; + $dtoUser['errmsg'] = ''; + $this->rspRawData($dtoUser); } + + private function loginCheck($userInfo) + { + $fieldsKv = array(); + if ($userInfo['vip_score'] >= 5 && $userInfo['act_ad_status'] != 2) { + $fieldsKv['act_ad_status'] = 1; + } + if (($this->getNowDaySeconds() - phpcommon\getDaySeconds($userInfo['update_time']) > 0)) { + if ($userInfo['new_second_equip'] == 2 && $userInfo['new_first_equip'] == 1) { + $fieldsKv['new_second_equip'] = 1; + } + $fieldsKv['daily_first_login'] = 0; + $fieldsKv['free_box'] = 0; + $fieldsKv['kefu_status'] = 0; + $fieldsKv['coin_times'] = 0; + $fieldsKv['first_day_ad'] = 0; + $fieldsKv['share_video_times'] = 0; + $fieldsKv['daily_max_single'] = 0; + $fieldsKv['daily_score'] = 0; + $fieldsKv['daily_offline'] = 0; + if ($this->getNowTime() > $userInfo['season_time'] && $userInfo['season_time'] != 0) { + $this->updateSeasonStatus($this->getAccountId()); + } + } + if (count($fieldsKV) > 0) { + $fieldsKv['modify_time'] = $this->getNowTime(); + $this->updateUserInf($fieldsKv); + } + return count($fieldsKV) > 0; + } + + private function createNewUser() + { + phpcommon\SqlHelper::upsert + ($this->getSelfMysql(), + 'user', + array( + 'accountid' => $this->getAccountId() + ), + array( + ), + array( + 'accountid' => $this->getAccountId(), + 'user_name' => $user_name, + 'avatar_url' => $avatar_url, + 'coin_num' => 10000, + 'season_status' => 1, + 'newInfo' => '', + 'new_second_equip' => 2, + 'head_kuang_id' => 19003, + 'sex' => 2, + 'hi_id' => 18001, + 'hero_id' => 30100, + 'integral' => 0, + 'season_time' => mt\Season::getCurrSeasonTime(), + 'team_name' => '', + 'create_time' => phpcommon\getNowTime(), + 'modify_time' => phpcommon\getNowTime(), + 'update_time' => phpcommon\getNowTime(), + ) + ); + $this->addHeroToDB(); + $this->newPlayerReward($account_id); + } + public function addHeroToDB() { // $itemArr = [10101,10102,10103,10104,10105,10106,10200,10201, diff --git a/webapp/mt/Season.php b/webapp/mt/Season.php index cd892416..0d0a0818 100644 --- a/webapp/mt/Season.php +++ b/webapp/mt/Season.php @@ -64,6 +64,19 @@ class Season { ); } + public static function getCurrSeasonTime() + { + $seasonTime = 0; + foreach (self::getMetaList() as $meta) { + if (phpcommon\getNowTime() >= strtotime($meta['open_time']) && + phpcommon\getNowTime() <= strtotime($meta['end_time'])) { + $seasonTime = strtotime($season['end_time']); + break; + } + } + return $seasonTime; + } + protected static $itemArr; protected static $metaList;