From 344b3ec2357eede3f48a48d49ac3f50a8ff18ebc Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 23 Jun 2022 15:58:04 +0800 Subject: [PATCH] 1 --- sql/marketdb.sql | 22 ++ webapp/controller/MarketController.class.php | 11 +- webapp/models/Phase3Box.php | 208 +++++++++++++++++++ webapp/services/Phase3BoxService.php | 53 +++++ 4 files changed, 288 insertions(+), 6 deletions(-) create mode 100644 webapp/models/Phase3Box.php create mode 100644 webapp/services/Phase3BoxService.php diff --git a/sql/marketdb.sql b/sql/marketdb.sql index fb5f757c..5e3718e3 100644 --- a/sql/marketdb.sql +++ b/sql/marketdb.sql @@ -380,6 +380,28 @@ CREATE TABLE `t_withdrawal` ( ) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; /*!40101 SET character_set_client = @saved_cs_client */; +-- +-- Table structure for table `t_phase3_box` +-- + +DROP TABLE IF EXISTS `t_phase3_box`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `t_phase3_box` ( + `idx` bigint NOT NULL AUTO_INCREMENT COMMENT '自增id', + `account` varchar(60) NOT NULL DEFAULT '' COMMENT 'account', + `token_id` varchar(60) NOT NULL DEFAULT '' COMMENT 'token_id', + `item_id` int(11) NOT NULL DEFAULT '0' COMMENT 'item_id', + `cec` int(11) NOT NULL DEFAULT '0' COMMENT 'cec', + `state` int(11) NOT NULL DEFAULT '0' COMMENT 'state', + `createtime` int(11) NOT NULL DEFAULT '0' COMMENT '创建时间', + `modifytime` int(11) NOT NULL DEFAULT '0' COMMENT '修改时间', + PRIMARY KEY (`idx`), + UNIQUE KEY `account` (`account`), + UNIQUE KEY `token_id` (`token_id`) +) ENGINE=InnoDB AUTO_INCREMENT=10001 DEFAULT CHARSET=utf8 COLLATE=utf8_bin; +/*!40101 SET character_set_client = @saved_cs_client */; + -- -- Table structure for table `t_transfer` -- diff --git a/webapp/controller/MarketController.class.php b/webapp/controller/MarketController.class.php index 0dc4a71f..ccdec1f3 100644 --- a/webapp/controller/MarketController.class.php +++ b/webapp/controller/MarketController.class.php @@ -15,6 +15,7 @@ require_once('models/BuyRecord.php'); require_once('services/MarketService.php'); require_once('services/LuckyBoxService.php'); require_once('services/ActivateNftService.php'); +require_once('services/Phase3Service.php'); require_once('phpcommon/bchelper.php'); @@ -25,6 +26,7 @@ use models\BuyRecord; use services\MarketService; use services\LuckyBoxService; use services\ActivateNftService; +use services\Phase3Service; class MarketController extends BaseController { @@ -498,10 +500,7 @@ class MarketController extends BaseController { myself()->_rspErr(1, 'invalid token'); return; } - $rows = array(); - myself()->_rspData(array( - 'rows' => $rows - )); + Phase3BoxService::getPhase3Box($account); } public function openPhase3Box() @@ -516,7 +515,7 @@ class MarketController extends BaseController { myself()->_rspErr(1, 'invalid token'); return; } - myself()->_rspOk(); + Phase3BoxService::openPhase3Box($account, $boxId); } public function queryPhase3Box() @@ -531,7 +530,7 @@ class MarketController extends BaseController { myself()->_rspErr(1, 'invalid token'); return; } - myself()->_rspOk(); + Phase3BoxService::queryPhase3Box($account, $boxId); } } diff --git a/webapp/models/Phase3Box.php b/webapp/models/Phase3Box.php new file mode 100644 index 00000000..08f9f37c --- /dev/null +++ b/webapp/models/Phase3Box.php @@ -0,0 +1,208 @@ +_getMarketMysql(), + 't_phase3_box', + array( + 'account' => $account, + ) + ); + return $row; + } + + /* + 抽奖箱规则 + 箱子只能抽中其中一项奖励 + 名称 奖励 百分比 大约中奖人数 + 特奖 创世 NFT英雄 3% 6 + 头奖 枪械 NFT 5% 10 + 一等奖 芯片 NFT 7% 13 + 二等奖 25 CEC 20% 38 + 三等奖 20 CEC 30% 57 + 安慰奖 15 CEC 35% 67 + */ + public static function give($account) + { + $heros = array( + 30100, + 30200, + 30300, + 30400, + 30500, + 30600, + 30700, + 30800, + 31000 + ); + $guns = array( + 70001, + 70002, + 70003, + 70004, + 70005, + 70006, + 70007 + ); + $chips = array( + 100001 + ); + $row = SqlHelper::ormSelectOne( + myself()->_getMarketMysql(), + 't_phase3_box', + array( + 'account' => $account, + ) + ); + $randArr = array( + 3, + 5, + 7, + 20, + 30, + 35 + ); + { + $space = 0; + for ($i = 0; $i < count($randArr); ++$i) { + $randArr[$i] += $space; + $space += $randArr[$i]; + } + } + if ($row && $row['state'] == self::INIT_STATE) { + $rnd = rand(0, 99); + $rewardIdx = -1; + for ($i = 0; $i < count($randArr); ++$i) { + if ($rnd <= $randArr[$i]) { + $rewardIdx = $i; + } + } + self::internalGive($rewardIdx); + } + } + + protected function internalGive($account, + $tokenId, + $rewardIdx, + $heros, + $guns, + $chips) + { + $accountId = ''; + $itemId = 0; + $tokenType = 0; + $tags = ''; + $cec = 0; + switch ($rewardIdx) { + case 0: + { + //特奖 创世 NFT英雄 3% 6 + } + break; + case 1: + { + //头奖 枪械 NFT 5% 10 + } + break; + case 2: + { + //一等奖 芯片 NFT 7% 13 + } + break; + case 3: + { + //二等奖 25 CEC 20% 38 + } + break; + case 4: + { + //三等奖 20 CEC 30% 57 + } + break; + default: + { + //安慰奖 15 CEC 35% 67 + } + break; + } + if (empty($itemId) && empty($cec)) { + return; + } + if ($itemId) { + $row = SqlHelper::ormSelectOne( + myself()->_getMarketMysql(), + 't_mint', + array( + 'bc_mint_tokenid' => $tokenId, + ) + ); + if (!$row) { + $uniKey = ''; + SqlHelper::insert( + myself()->_getMarketMysql(), + 't_mint', + array( + 'bc_mint_tokenid' => $tokenId, + 'unikey' => $uniKey, + 'account' => $account, + 'game_id' => 2006, + + 'bc_mint_itemid' => $itemId, + 'bc_mint_token_type' => $tokenType, + 'bc_mint_tags' => $tags, + + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + } + if ($cec > 0) { + SqlHelper::upsert( + myself()->_getMarketMysql(), + 't_user_wallet_offline_temp', + array( + 'account_id' => $accountId, + ), + array( + 'diamond' => function () use ($cec) { + return 'diamond + ' . $cec; + } + ), + array( + 'account_id' => $accountId, + 'diamond' => $cec, + + 'createtime' => myself()->_getNowTime(), + 'modifytime' => myself()->_getNowTime() + ) + ); + } + { + SqlHelper::update( + myself()->_getMarketMysql(), + 't_phase3_box', + array( + 'account' => $account, + ), + array( + 'item_id' => $itemId, + 'cec' => $cec, + 'state' => self::GIVE_STATE + ) + ); + } + } + +} diff --git a/webapp/services/Phase3BoxService.php b/webapp/services/Phase3BoxService.php new file mode 100644 index 00000000..df9bf71f --- /dev/null +++ b/webapp/services/Phase3BoxService.php @@ -0,0 +1,53 @@ + $boxDb['token_id'] + )); + } + myself()->_rspData(array( + 'rows' => $rows + )); + } + + public static function openPhase3Box($account, $boxId) + { + $boxDb = Phase3Box::all($account); + if (!$boxDb) { + myself()->_rspErr(100, 'box not exists'); + return; + } + if ($boxDb['state'] == Phase3Box::INIT_STATE) { + } + myself()->_rspOk(); + } + + public static function queryPhase3Box($account, $boxId) + { + myself()->_rspOk(); + } + +}