算力功能补充

This commit is contained in:
hujiabin 2024-07-31 17:55:44 +08:00
parent 490cc59960
commit d28b8d155a
12 changed files with 213 additions and 14 deletions

View File

@ -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:未完成'],
]

View File

@ -1114,6 +1114,7 @@ class ChipPageSlot(object):
['state', 0, '0未解锁 1已解锁'],
['chip_id', '', '芯片唯一id'],
['item_id', '', '芯片itemId'],
['quality', '', '芯片品阶'],
]
class HeroPreset(object):

View File

@ -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`
--

View File

@ -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;

View File

@ -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);

View File

@ -1,8 +1,10 @@
<?php
require_once('services/HashRateService.php');
require_once('services/LootService.php');
require_once('mt/AchievementsPower.php');
require_once('mt/AchievementsCycle.php');
require_once('mt/Parameter.php');
require_once('models/HashRate.php');
use models\HashRate;
@ -67,14 +69,14 @@ class HashRateController extends BaseAuthedController
$mateList = \mt\AchievementsPower::getCustomTypeMetaList($type,$this->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,
));
}
}

View File

@ -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);

View File

@ -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()
)
);
}
}

View File

@ -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'],

View File

@ -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),

View File

@ -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()

View File

@ -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(