This commit is contained in:
aozhiwei 2022-05-13 08:06:55 +08:00
parent 4318a5fc0e
commit 1bcc251ec0
5 changed files with 177 additions and 0 deletions

View File

@ -5,6 +5,21 @@ const log = require('j7/log');
const BaseService = require('./baseservice');
const metaFactory = require('../metadata/factory');
const ALIVE_RANK = 100;
class CommonRank {
constructor(rankType) {
this.rankType = rankType;
this.lastIdx = 0;
}
async start() {
}
}
class Rank extends BaseService {
async init() {

View File

@ -463,6 +463,29 @@ CREATE TABLE `t_drop_log` (
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_rank_activity`
--
DROP TABLE IF EXISTS `t_rank_activity`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t_rank_activity` (
`idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id',
`account_id` varchar(60) NOT NULL DEFAULT '' COMMENT '账号id',
`channel` int(11) NOT NULL DEFAULT '0' COMMENT 'channel',
`type` int(11) NOT NULL DEFAULT '0' COMMENT 'type',
`value` bigint NOT NULL DEFAULT '0' COMMENT 'value',
`createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间',
`modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间',
PRIMARY KEY (`idx`),
UNIQUE KEY `account_id_type` (`account_id`, `type`),
KEY `channel` (`channel`),
KEY `type` (`type`),
KEY `value` (`value`)
) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `t_game_log`
--

View File

@ -11,6 +11,7 @@ require_once('models/HeroSkin.php');
require_once('services/NftService.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
use services\NftService;

View File

@ -0,0 +1,31 @@
<?php
namespace mt;
use phpcommon;
class RankActivity {
public static function get($id)
{
return array_key_exists($id, self::getMetaList()) ? self::getMetaList()[$id] : null;
}
public static function isActivityPeriod($meta)
{
return $meta['opentime'] >= myself()->_getNowTime() &&
$meta['closetime'] < myself()->_getNowTime();
}
protected static function getMetaList()
{
if (!self::$metaList) {
self::$metaList = getMetaTable('rankActivity@rankActivity.php');
}
return self::$metaList;
}
protected static $metaList;
}

View File

@ -0,0 +1,107 @@
<?php
namespace services;
require_once('mt/Item.php');
require_once('mt/Equip.php');
require_once('mt/Season.php');
require_once('mt/Rank.php');
require_once('mt/RankReward.php');
require_once('mt/KillReward.php');
require_once('mt/Parameter.php');
require_once('mt/HeroQuality.php');
require_once('mt/AttrHelper.php');
require_once('mt/RankActivity.php');
require_once('models/Season.php');
require_once('models/Battle.php');
require_once('models/Bag.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
use models\Season;
use models\Battle;
use models\Bag;
use models\Hero;
use models\Gun;
class RankActivityService extends BaseService {
const ALIVE_TYPE = 1;
const KILLS_TYPE = 2;
const HERO_UPGRADE_LEVEL_TYPE = 3;
const HERO_UPGRADE_QUALITY_TYPE = 4;
const OP_SUM = 1;
const OP_GREATEST = 2;
public function updateBattleData()
{
$this->internalUpdateRankActivity(
self::ALIVE_TYPE,
getReqVal('alive_time', 0),
self::OP_SUM);
$this->internalUpdateRankActivity(
self::KILLS_TYPE,
getReqVal('kills_time', 0),
self::OP_SUM);
}
public function heroUpgradeQuality()
{
$this->internalUpdateRankActivity(
self::HERO_UPGRADE_QUALITY_TYPE,
getReqVal('kills_time', 0),
self::OP_GREATEST);
}
public function heroUpgradeLevel()
{
$this->internalUpdateRankActivity(
self::HERO_UPGRADE_LEVEL_TYPE,
getReqVal('kills_time', 0),
self::OP_GREATEST);
}
private function internalUpdateRankActivity($type, $val, $opt)
{
$meta = mt\RankActivity::get(type);
if (!$meta || !mt\RankActivity::isActivityPeriod($meta)) {
return;
}
SqlHelper::upsert
(myself()->_getSelfMysql(),
't_rank_activity',
array(
'account_id' => myself()->_getAccountId(),
'type' => $type
),
array(
'value' => function () use($val, $opt) {
if ($opt == self::OP_SUM) {
return "value + ${val})";
} else if ($opt == self::OP_GREATEST) {
return "GREATEST(0, ${val})";
} else {
return $val;
}
},
'modifytime' => myself()->_getNowTime(),
),
array(
'account_id' => myself()->_getAccountId(),
'channel' => myself()->_getChannel(),
'type' => $type,
'value' => $val,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime()
)
);
}
}