From d28b8d155a70a5417a8ce0af6b4d4019c5efb6fa Mon Sep 17 00:00:00 2001 From: hujiabin <519660157@qq.com> Date: Wed, 31 Jul 2024 17:55:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AE=97=E5=8A=9B=E5=8A=9F=E8=83=BD=E8=A1=A5?= =?UTF-8?q?=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- doc/HashRate.py | 7 ++- doc/_common.py | 1 + sql/gamedb.sql | 19 +++++++- sql/gamedb2006_migrate_240722_01.sql | 28 +++++++++++ webapp/bootstrap/constant.php | 1 + .../controller/HashRateController.class.php | 48 +++++++++++++++++-- webapp/models/ChipPage.php | 1 + webapp/models/HashRate.php | 44 +++++++++++++++-- webapp/models/Hero.php | 2 + webapp/models/User.php | 13 +++++ webapp/mt/AchievementsPower.php | 17 ++++++- webapp/services/HashRateService.php | 46 ++++++++++++++++-- 12 files changed, 213 insertions(+), 14 deletions(-) diff --git a/doc/HashRate.py b/doc/HashRate.py index 6af018d7..dcf757e6 100644 --- a/doc/HashRate.py +++ b/doc/HashRate.py @@ -11,15 +11,18 @@ class HashRate(object): 'url': 'webapp/index.php?c=HashRate&a=info', 'params': [ _common.ReqHead(), + ['type', 0, '1:战斗任务 2:英雄任务 3:行为任务 4:充值消费任务'], ], 'response': [ _common.RspHead(), - ['!list', [HashRateList()], '行为列表'], + ['!task_list1', [HashRateList()], '任务列表1'], + ['!task_list2', [HashRateList()], '任务列表2'], ['obtain_start_time', 0, '获得期开始时间'], ['obtain_end_time', 0, '获得期结束时间'], ['income_end_time', 0, '盈利期结束时间'], ['state', 0, '0:未开始 1:获得期 2:盈利期'], ['myHashRate', 0, '我的算力'], + ['refresh_times', 0, '今日刷新次数'], ] }, ] @@ -32,5 +35,5 @@ class HashRateList(object): ['task_id', 0, '任务id'], ['current', 0, '当前进度'], ['target', 0, '目标进度'], - ['state', 0, '1:完成 0:未完成'], + ['state', 0, '2:完成(已领取) 1:完成(未领取) 0:未完成'], ] \ No newline at end of file diff --git a/doc/_common.py b/doc/_common.py index dfcdcee8..c966ecec 100644 --- a/doc/_common.py +++ b/doc/_common.py @@ -1114,6 +1114,7 @@ class ChipPageSlot(object): ['state', 0, '0:未解锁 1:已解锁'], ['chip_id', '', '芯片唯一id'], ['item_id', '', '芯片itemId'], + ['quality', '', '芯片品阶'], ] class HeroPreset(object): diff --git a/sql/gamedb.sql b/sql/gamedb.sql index 2f143928..b52b1123 100644 --- a/sql/gamedb.sql +++ b/sql/gamedb.sql @@ -1697,13 +1697,30 @@ CREATE TABLE `t_hash_rate` ( `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', `task_id` int(11) NOT NULL COMMENT '配置表id', `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', - `reward` int(64) NOT NULL DEFAULT '0' COMMENT '奖励', `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', PRIMARY KEY (`idx`), UNIQUE KEY `account_period_task_id` (`account_id`,`period`, `task_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +-- +-- Table structure for table `t_hash_rate_reward` +-- + +DROP TABLE IF EXISTS `t_hash_rate_reward`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hash_rate_reward` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', + `reward` int(64) NOT NULL DEFAULT '0' COMMENT '奖励', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_period` (`account_id`,`period`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + -- -- Table structure for table `t_hash_rate_battle_data` -- diff --git a/sql/gamedb2006_migrate_240722_01.sql b/sql/gamedb2006_migrate_240722_01.sql index 14d51d08..45495841 100644 --- a/sql/gamedb2006_migrate_240722_01.sql +++ b/sql/gamedb2006_migrate_240722_01.sql @@ -15,6 +15,34 @@ CREATE TABLE `t_emoji` ( UNIQUE KEY `account_item_id` (`account_id`, `item_id`) ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +DROP TABLE IF EXISTS `t_hash_rate`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hash_rate` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `task_id` int(11) NOT NULL COMMENT '配置表id', + `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_period_task_id` (`account_id`,`period`, `task_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + +DROP TABLE IF EXISTS `t_hash_rate_reward`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_hash_rate_reward` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id(channel + "_" + gameid + "_" + openid)', + `period` int(11) NOT NULL DEFAULT '0' COMMENT '算力期数', + `reward` int(64) NOT NULL DEFAULT '0' COMMENT '奖励', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account_period` (`account_id`,`period`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; + insert into version (version) values(2024052101); commit; diff --git a/webapp/bootstrap/constant.php b/webapp/bootstrap/constant.php index d0ecffc5..6e215811 100644 --- a/webapp/bootstrap/constant.php +++ b/webapp/bootstrap/constant.php @@ -88,6 +88,7 @@ define('TN_HASH_RATE_SYN_CHIP_TIMES', 50004); define('TN_HASH_RATE_SYN_SKIN_TIMES', 50005); define('TN_HASH_RATE_UP_HERO_TIMES', 50006); define('TN_HASH_RATE_UP_CHIP_TIMES', 50007); +define('TN_HASH_DAILY_REFRESH_TIMES', 50008); define('SHOP_BUY_MODE_NORMAL', 0); define('SHOP_BUY_MODE_DAILY_SELECTION', 1); diff --git a/webapp/controller/HashRateController.class.php b/webapp/controller/HashRateController.class.php index 1e3010f9..a7ac613d 100644 --- a/webapp/controller/HashRateController.class.php +++ b/webapp/controller/HashRateController.class.php @@ -1,8 +1,10 @@ hashRateService); foreach ($mateList as $mate) { $taskDb = HashRate::find($mate['id'],$currentPeriod['id']); - $temp = $this->hashRateService->hashRateTaskDto($mate,$taskDb); - array_push($taskDtoList1, $temp); + $taskDto = $this->hashRateService->hashRateTaskDto($mate,$taskDb); + array_push($taskDtoList1, $taskDto); } $mateList2 = \mt\AchievementsPower::getListByType(0); foreach ($mateList2 as $mate) { $taskDb = HashRate::find($mate['id'],$currentPeriod['id']); - $temp = $this->hashRateService->hashRateTaskDto($mate,$taskDb); - array_push($taskDtoList2, $temp); + $taskDto = $this->hashRateService->hashRateTaskDto($mate,$taskDb); + array_push($taskDtoList2, $taskDto); } $obtain_start_time = strtotime($currentPeriod['obtain_start_time']); $obtain_end_time = strtotime($currentPeriod['obtain_end_time']); @@ -94,16 +96,54 @@ class HashRateController extends BaseAuthedController 'income_start_time' => $income_start_time, 'income_end_time' => $income_end_time, 'state' => $state, + 'refresh_times' => myself()->_getDailyV(TN_HASH_DAILY_REFRESH_TIMES,0), + 'myHashRate' => 0, )); } public function commitTask(){ + $currentPeriod= \mt\AchievementsCycle::getCurrentPeriod(); + if (! $currentPeriod){ + $this->_rspErr(1, 'Already ended'); + return; + } $taskId = getReqVal('task_id', 0); $taskMeta = \mt\AchievementsPower::find($taskId); if (!$taskMeta) { $this->_rspErr(1, 'task_id error'); return; } + $taskDb = HashRate::find($taskMeta['id'],$currentPeriod['id']); + $taskDto = $this->hashRateService->hashRateTaskDto($taskMeta,$taskDb); + + if (!$taskDto) { + $this->_rspErr(10, 'server internal error'); + return; + } + if ($taskDto['state'] == \services\HashRateService::RECEIVED_STATE) { + $this->_rspErr(2, "Can't get it again"); + return; + } +// if ($taskDto['state'] == \services\HashRateService::NOT_FINISHED_STATE) { +// $this->_rspErr(3, 'task not achieved'); +// return; +// } + $lootIndex = $taskMeta['Reward_Loot']; + $reward = \services\LootService::dropOutItem($lootIndex); + $rewardNum = $reward[0]['item_num']; + HashRate::add($taskMeta['id'],$currentPeriod['id']); + HashRate::rewardAdd($currentPeriod['id'],$rewardNum); + //刷新任务 + $refreshTimes = myself()->_getDailyV(TN_HASH_DAILY_REFRESH_TIMES,0); + $refreshTimesMax = \mt\Parameter::getVal('economy_account_compute_refresh_max',5); + if ($taskMeta['is_refresh'] == \mt\AchievementsPower::REFRESH_STATE && $refreshTimes < $refreshTimesMax){ + $this->hashRateService->refreshHashRateTask($taskMeta,$currentPeriod['id']); + } + $this->_rspData(array( + 'award' => $reward, + )); } + + } \ No newline at end of file diff --git a/webapp/models/ChipPage.php b/webapp/models/ChipPage.php index fff563f2..c32c65a2 100644 --- a/webapp/models/ChipPage.php +++ b/webapp/models/ChipPage.php @@ -85,6 +85,7 @@ class ChipPage extends BaseModel if ($value['chip_id']){ $chipDb = Chip::find($value['chip_id']); $newData[$key]['item_id'] = $chipDb['item_id']; + $newData[$key]['quality'] = $chipDb['quality']; $rand_attr = emptyReplace(json_decode($chipDb['rand_attr'], true), array()); foreach ($rand_attr as $val){ array_push($attrs,$val); diff --git a/webapp/models/HashRate.php b/webapp/models/HashRate.php index 7d0a9b9e..b7f4d3d1 100644 --- a/webapp/models/HashRate.php +++ b/webapp/models/HashRate.php @@ -47,11 +47,25 @@ class HashRate extends BaseModel } - public static function add($fieldKv){ - SqlHelper::insert( + public static function add($taskId,$period){ + SqlHelper::upsert( myself()->_getSelfMysql(), 't_hash_rate', - $fieldKv + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $period, + 'task_id' => $taskId + ), + array( + 'modifytime' => myself()->_getNowTime() + ), + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $period, + 'task_id' => $taskId, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) ); } @@ -91,4 +105,28 @@ class HashRate extends BaseModel return $totalHashRate; } + public static function rewardAdd($period,$reward){ + SqlHelper::upsert( + myself()->_getSelfMysql(), + 't_hash_rate_reward', + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $period, + ), + array( + 'reward' => function () use($reward) { + return "reward + ${reward}"; + }, + 'modifytime' => myself()->_getNowTime() + ), + array( + 'account_id' => myself()->_getAccountId(), + 'period' => $period, + 'reward' => $reward, + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + } \ No newline at end of file diff --git a/webapp/models/Hero.php b/webapp/models/Hero.php index 8c07f65c..f90dd9be 100644 --- a/webapp/models/Hero.php +++ b/webapp/models/Hero.php @@ -198,6 +198,7 @@ class Hero extends BaseModel { $heroAtteMeta = \mt\EconomyAttribute::findByGrade($heroMeta['relationship'],$row['quality']); $unsealTime = $row['unseal_time'] ? $row['unseal_time'] : $row['createtime']; $validTime = $unsealTime + 86400 * $heroAtteMeta['validTime'] ; + $skinDb = HeroSkin::find($row['skin_id']); $dto = array( 'idx' => $row['idx'], 'token_id' => $row['token_id'], @@ -206,6 +207,7 @@ class Hero extends BaseModel { 'hero_lv' => $row['hero_lv'], 'hero_tili' => $row['hero_tili'], 'state' => $row['state'], + 'skin_id' => $skinDb?$skinDb['skin_id']:0, 'quality' => $row['quality'], 'skill_lv1' => $row['skill_lv1'], 'skill_lv2' => $row['skill_lv2'], diff --git a/webapp/models/User.php b/webapp/models/User.php index 8c7a3fef..8407ae84 100644 --- a/webapp/models/User.php +++ b/webapp/models/User.php @@ -11,6 +11,7 @@ require_once('models/Hero.php'); require_once('models/HeroPreset.php'); require_once('models/SignLog.php'); require_once('models/UserHonor.php'); +require_once('models/HeroSkin.php'); use mt; use phpcommon; @@ -74,6 +75,11 @@ class User extends BaseModel { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); $heroUniid = $heroDb ? $row['hero_id'] : 0; $heroId = $heroDb ? $heroDb['hero_id'] : 0; + $skinId = 0; + if ($heroDb){ + $skinDb = HeroSkin::find($heroDb['skin_id']); + $skinId = $skinDb ? $skinDb['skin_id']:0; + } $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); @@ -98,6 +104,7 @@ class User extends BaseModel { 'diamond' => cecFormat($row['diamond']), 'hero_uniid' => $heroUniid, 'hero_id' => $heroId, + 'skin_id' => $skinId, 'first_fight' => $row['first_fight'], 'already_guide' => $row['already_guide'], 'pve_instance_id' => $row['pve_instance_id'], @@ -125,6 +132,11 @@ class User extends BaseModel { $heroDb = Hero::findByAccountId($row['account_id'],$row['hero_id']); $heroUniid = $heroDb ? $row['hero_id'] : 0; $heroId = $heroDb ? $heroDb['hero_id'] : 0; + $skinId = 0; + if ($heroDb){ + $skinDb = HeroSkin::find($heroDb['skin_id']); + $skinId = $skinDb ? $skinDb['skin_id']:0; + } $honorInfo = array(); if ($row['address']){ $honorInfo = UserHonor::info($row['address']); @@ -149,6 +161,7 @@ class User extends BaseModel { 'diamond' => cecFormat($row['diamond']), 'hero_uniid' => $heroUniid, 'hero_id' => $heroId, + 'skin_id' => $skinId, 'first_fight' => $row['first_fight'], 'already_guide' => $row['already_guide'], 'head_list' => self::getHeadList($row), diff --git a/webapp/mt/AchievementsPower.php b/webapp/mt/AchievementsPower.php index ba50e4f4..ee4d7856 100644 --- a/webapp/mt/AchievementsPower.php +++ b/webapp/mt/AchievementsPower.php @@ -37,6 +37,9 @@ class AchievementsPower { const TYPE3 = 3; const TYPE4 = 4; + const REFRESH_STATE = 1; + const NOT_REFRESH_STATE = 0; + public static function find($id){ return getXVal(self::getMetaList(), $id, null); } @@ -55,13 +58,25 @@ class AchievementsPower { public static function getListByType($type){ $mateList = array(); foreach (self::getMetaList() as $mate){ - if ($mate['scene'] == $type){ + if ($mate['task_type'] == $type){ array_push($mateList,$mate); } } return $mateList; } + public static function getAvailableTasks($type,$excludeMetas){ + $metas = array(); + foreach (self::getListByType($type) as $meta) { + if (!array_find($excludeMetas, function($val) use($meta) { + return $val['task_id'] == $meta['id']; + })) { + array_push($metas, $meta); + } + } + return $metas; + } + public static function getMetaList() diff --git a/webapp/services/HashRateService.php b/webapp/services/HashRateService.php index 455f52be..406aa7db 100644 --- a/webapp/services/HashRateService.php +++ b/webapp/services/HashRateService.php @@ -105,9 +105,17 @@ class HashRateService extends BaseService ); if ($taskDb){ - $taskDto['current'] = $taskDto['target']; - $taskDto['state'] = self::RECEIVED_STATE; - return $taskDto; + if ($taskMate['scene'] > 0){ + if (myself()->_getDaySeconds($taskDb['modifytime']) == myself()->_getNowDaySeconds()) { + $taskDto['current'] = $taskDto['target']; + $taskDto['state'] = self::RECEIVED_STATE; + return $taskDto; + } + }else{ + $taskDto['current'] = $taskDto['target']; + $taskDto['state'] = self::RECEIVED_STATE; + return $taskDto; + } } switch ($taskMate['Completion_type']){ @@ -338,6 +346,38 @@ class HashRateService extends BaseService json_encode($this->hashRateTask)); } + public function refreshHashRateTask($taskMate,$period){ + $taskList = $this->getHashRateTasks($taskMate['task_type']); + $metas = AchievementsPower::getAvailableTasks($taskMate['task_type'],$taskList); + if (count($metas)<1) { + return; + } + $randMetas = array(); + foreach ($metas as $meta){ + $taskDb = HashRate::find($meta['id'],$period); + if (!$taskDb || myself()->_getDaySeconds($taskDb['modifytime']) < myself()->_getNowDaySeconds()){ + array_push($randMetas,$meta); + } + } + if (count($randMetas)<1) { + return; + } + $key = array_rand($randMetas,1); + foreach ($taskList as $k=>$task){ + if ($task['task_id'] == $taskMate['id']){ + $taskList[$k] = array( + 'task_id' => $metas[$key]['id'], + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime(), + ); + } + } + $this->hashRateTask['task'.$taskMate['task_type']] = $taskList; + $this->saveHashRateTask(); + myself()->_incDailyV(TN_HASH_DAILY_REFRESH_TIMES,0,1); + } + + public function serverTaskDto($taskMate){ $taskDto = array(