Compare commits

...

12 Commits

Author SHA1 Message Date
aozhiwei
99de4605a9 1 2022-12-22 18:41:27 +08:00
aozhiwei
81382f07e5 add test Nft 2022-10-16 09:05:38 +08:00
aozhiwei
48ca58070c 1 2022-06-24 16:52:58 +08:00
aozhiwei
a24f19601c 1 2022-06-24 15:53:25 +08:00
aozhiwei
0e37a642f4 1 2022-06-24 15:52:19 +08:00
aozhiwei
f5674ae728 1 2022-06-24 11:22:43 +08:00
aozhiwei
95482b20dc 1 2022-06-23 17:37:14 +08:00
aozhiwei
aa110d2ead 1 2022-06-23 17:19:42 +08:00
aozhiwei
84081ba6bd 1 2022-06-23 16:12:35 +08:00
aozhiwei
15217abd30 1 2022-06-23 16:08:04 +08:00
aozhiwei
531826e12e 1 2022-06-23 15:59:13 +08:00
aozhiwei
344b3ec235 1 2022-06-23 15:58:04 +08:00
6 changed files with 431 additions and 14 deletions

View File

@ -556,4 +556,7 @@ class Phase3Box(object):
def __init__(self):
self.fields = [
['box_id', '', '箱子id'],
['image_box_1', '', '箱子3态图1'],
['image_box_2', '', '箱子3态图2'],
['image_box_3', '', '箱子3态图3'],
]

View File

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

View File

@ -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/Phase3BoxService.php');
require_once('phpcommon/bchelper.php');
@ -25,6 +26,7 @@ use models\BuyRecord;
use services\MarketService;
use services\LuckyBoxService;
use services\ActivateNftService;
use services\Phase3BoxService;
class MarketController extends BaseController {
@ -494,14 +496,13 @@ class MarketController extends BaseController {
$tokenId = getReqVal('token_id', '');
$netId = getReqVal('net_id', '');
$account = strtolower(getReqVal('account', ''));
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
if (SERVER_ENV == _ONLINE) {
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
}
}
$rows = array();
myself()->_rspData(array(
'rows' => $rows
));
Phase3BoxService::getPhase3Box($account);
}
public function openPhase3Box()
@ -512,11 +513,13 @@ class MarketController extends BaseController {
$netId = getReqVal('net_id', '');
$boxId = getReqVal('box_id', '');
$account = strtolower(getReqVal('account', ''));
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
if (SERVER_ENV == _ONLINE) {
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
}
}
myself()->_rspOk();
Phase3BoxService::openPhase3Box($account, $boxId);
}
public function queryPhase3Box()
@ -527,10 +530,45 @@ class MarketController extends BaseController {
$netId = getReqVal('net_id', '');
$boxId = getReqVal('box_id', '');
$account = strtolower(getReqVal('account', ''));
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
if (SERVER_ENV == _ONLINE) {
if (!MarketService::isValidToken($account, $token)) {
myself()->_rspErr(1, 'invalid token');
return;
}
}
Phase3BoxService::queryPhase3Box($account, $boxId);
}
public function genTestData()
{
$gameId = 2006;
$funcId = phpcommon\BC_FUNC_OPEN_BOX;
//if (SERVER_ENV == _TEST) {
$rows = SqlHelper::ormSelect(
myself()->_getMarketMysql(),
't_phase3_box',
array(
)
);
foreach ($rows as $row) {
if (empty($row['token_id'])) {
$orderId = BuyRecord::genOrderId($gameId,
$funcId,
myself()->_getNowTime(),
$row['account']);
SqlHelper::update(
myself()->_getMarketMysql(),
't_phase3_box',
array(
'account' => $row['account']
),
array(
'token_id' => $orderId
)
);
}
}
//}
myself()->_rspOk();
}

View File

@ -58,6 +58,10 @@ class RestApiController extends BaseController {
myself()->_rspRawData($nftView);
return;
}
if ($this->procTestNft($tokenId, $nftView)){
myself()->_rspRawData($nftView);
return;
}
$nftDb = Nft::getNft($tokenId);
if (empty($nftDb)) {
myself()->_rspRawData($nftView);
@ -67,4 +71,30 @@ class RestApiController extends BaseController {
myself()->_rspRawData($nftView);
}
private function procTestNft($tokenId, &$nftView)
{
$heroBoxes = array(
'6022513565100001',
'6022513565100002',
'6022513565100003',
);
$weaponBoxes = array(
'6022513565100004',
'6022513565100005'
);
if (in_array($tokenId, $heroBoxes)) {
$nftView['name'] = 'CEBG Airdrop Hero';
$nftView['image'] = 'https://www.cebg.games/res/nfts/CEBG_Space_Hero.png';
$nftView['description'] = 'CEBG Airdrop Hero';
return true;
}
if (in_array($tokenId, $weaponBoxes)) {
$nftView['name'] = 'CEBG Airdrop Weapon';
$nftView['image'] = 'https://www.cebg.games/res/nfts/CEBG_Space_Weapon.png';
$nftView['description'] = 'CEBG Airdrop Weapon';
return true;
}
return false;
}
}

233
webapp/models/Phase3Box.php Normal file
View File

@ -0,0 +1,233 @@
<?php
namespace models;
require_once('models/Nft.php');
use mt;
use phpcommon;
use phpcommon\SqlHelper;
class Phase3Box extends BaseModel {
const INIT_STATE = 0;
const GIVE_STATE = 1;
public static function find($account)
{
$row = SqlHelper::ormSelectOne(
myself()->_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) {
$space += $randArr[$i];
$randArr[$i] = $space;
}
}
if ($row && $row['state'] == self::INIT_STATE) {
$rnd = rand(0, 99);
$rewardIdx = -1;
error_log(json_encode($randArr));
error_log('rand:' . $rnd);
for ($i = 0; $i < count($randArr); ++$i) {
if ($rnd <= $randArr[$i]) {
$rewardIdx = $i;
break;
}
}
self::internalGive(
$account,
$row['token_id'],
$rewardIdx,
$heros,
$guns,
$chips);
}
}
protected function internalGive($account,
$tokenId,
$rewardIdx,
$heros,
$guns,
$chips)
{
$accountId = phpcommon\createAccountId(6516, 2006, $account);
$itemId = 0;
$tokenType = 0;
$tags = '';
$cec = 0;
switch ($rewardIdx) {
case 0:
{
//特奖 创世 NFT英雄 3% 6
$rnd = rand(0, count($heros) - 1);
$itemId = $heros[$rnd];
$tokenType = Nft::HERO_TYPE;
$tags = Nft::GENESIS_TAG;
}
break;
case 1:
{
//头奖 枪械 NFT 5% 10
$rnd = rand(0, count($guns) - 1);
$itemId = $guns[$rnd];
$tokenType = Nft::EQUIP_TYPE;
}
break;
case 2:
{
//一等奖 芯片 NFT 7% 13
$rnd = rand(0, count($chips) - 1);
$itemId = $chips[$rnd];
$tokenType = Nft::CHIP_TYPE;
}
break;
case 3:
{
//二等奖 25 CEC 20% 38
$cec = 25;
}
break;
case 4:
{
//三等奖 20 CEC 30% 57
$cec = 20;
}
break;
default:
{
//安慰奖 15 CEC 35% 67
$cec = 15;
}
break;
}
if (empty($itemId) && empty($cec)) {
return;
}
if ($itemId) {
$row = SqlHelper::ormSelectOne(
myself()->_getMarketMysql(),
't_mint',
array(
'bc_mint_tokenid' => $tokenId,
)
);
if (!$row) {
$uniKey = 'phase3box_' . $account;
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
)
);
}
}
}

View File

@ -0,0 +1,91 @@
<?php
namespace services;
require_once('phpcommon/bchelper.php');
require_once('models/Nft.php');
require_once('models/ActivateNft.php');
require_once('models/BuyRecord.php');
require_once('models/ActivateNftEvent.php');
require_once('models/Phase3Box.php');
use phpcommon;
use models\Nft;
use models\ActivateNft;
use models\BuyRecord;
use models\ActivateNftEvent;
use models\Phase3Box;
class Phase3BoxService {
public static function getPhase3Box($account)
{
$rows = array();
$boxDb = Phase3Box::find($account);
if ($boxDb && $boxDb['state'] == Phase3Box::INIT_STATE) {
array_push($rows, array(
'box_id' => $boxDb['token_id'],
'image_box_1' => 'https://www.cebg.games/res/nfts/box_1.png',
'image_box_2' => 'https://www.cebg.games/res/nfts/box_2.png',
'image_box_3' => 'https://www.cebg.games/res/nfts/box_3.png',
));
}
myself()->_rspData(array(
'rows' => $rows
));
}
public static function openPhase3Box($account, $boxId)
{
$boxDb = Phase3Box::find($account);
if (!$boxDb) {
myself()->_rspErr(100, 'box not exists');
return;
}
if ($boxDb['state'] == Phase3Box::INIT_STATE) {
Phase3Box::give($account);
}
myself()->_rspOk();
}
public static function queryPhase3Box($account, $boxId)
{
$boxDb = Phase3Box::find($account);
if (!$boxDb) {
myself()->_rspErr(100, 'box not exists');
return;
}
if ($boxDb['state'] == Phase3Box::INIT_STATE) {
myself()->_rspData(array(
'state' => 0
));
return;
}
if ($boxDb['cec'] > 0) {
myself()->_rspData(array(
'state' => 1,
'cec' => $boxDb['cec']
));
return;
} else {
$nftDb = Nft::getNft($boxDb['token_id']);
if ($nftDb) {
myself()->_rspData(array(
'state' => 1,
'cec' => 0,
'nfts' => array(
Nft::toDto($nftDb)
)
));
return;
} else {
myself()->_rspData(array(
'state' => 0
));
return;
}
}
}
}