973 lines
33 KiB
PHP
973 lines
33 KiB
PHP
<?php
|
|
|
|
require_once('mt/Parameter.php');
|
|
require_once('mt/Item.php');
|
|
require_once('mt/Drop.php');
|
|
require_once('mt/Hero.php');
|
|
|
|
require_once('models/Bag.php');
|
|
require_once('models/Hero.php');
|
|
require_once('models/Gun.php');
|
|
require_once('models/Nft.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/Transaction.php');
|
|
require_once('models/BuyRecord.php');
|
|
require_once('models/Chip.php');
|
|
require_once('models/TransactionPrefee.php');
|
|
|
|
require_once('services/AwardService.php');
|
|
require_once('services/PropertyChgService.php');
|
|
|
|
require_once('services/NameService.php');
|
|
|
|
use phpcommon\SqlHelper;
|
|
use models\Bag;
|
|
use models\Hero;
|
|
use models\Gun;
|
|
use models\Nft;
|
|
use models\Transaction;
|
|
use models\BuyRecord;
|
|
use models\Chip;
|
|
use models\TransactionPrefee;
|
|
|
|
class BlockChainController extends BaseAuthedController {
|
|
|
|
const TEST_ITEM_ID = 666;
|
|
public function _handlePre()
|
|
{
|
|
parent::_handlePre();
|
|
if (getReqVal('a', '') != 'getTransactionList' &&
|
|
myself()->_getChannel() != BC_CHANNEL) {
|
|
die(json_encode(array(
|
|
'errcode' => 501,
|
|
'errmsg' => 'you are not a wallet user'
|
|
)));
|
|
return;
|
|
}
|
|
error_log(json_encode($_REQUEST));
|
|
}
|
|
|
|
public function getTransactionList()
|
|
{
|
|
$trans = array();
|
|
foreach (Transaction::all() as $tran) {
|
|
array_push(
|
|
$trans,
|
|
array(
|
|
'trans_id' => $tran['trans_id'],
|
|
'item_id' => $tran['item_id'],
|
|
'action' => Transaction::getActionDesc($tran),
|
|
'status' => Transaction::getStatusDesc($tran),
|
|
'time' => $tran['createtime'],
|
|
)
|
|
);
|
|
}
|
|
$this->_rspData(array(
|
|
'transactions' => $trans
|
|
));
|
|
}
|
|
|
|
public function active721Nft()
|
|
{
|
|
$type = getReqVal('type', 0);
|
|
$uniid = getReqVal('uniid', 0);
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
$heroDb = Hero::find($uniid);
|
|
if (!$heroDb) {
|
|
myself()->_rspErr(1, 'hero not found');
|
|
return;
|
|
}
|
|
if ($heroDb['token_id']) {
|
|
myself()->_rspErr(1, 'already activated');
|
|
return;
|
|
}
|
|
$tokenId = $heroDb['active_token_id'];
|
|
if (!$tokenId) {
|
|
$tokenId = BuyRecord::genOrderId
|
|
(
|
|
2006,
|
|
phpcommon\BC_FUNC_CREATION,
|
|
myself()->_getNowTime(),
|
|
myself()->_getOpenId()
|
|
);
|
|
Hero::Update($heroDb['hero_uniid'],
|
|
array(
|
|
'active_token_id' => $tokenId,
|
|
'active_count' => function () {
|
|
return 'active_count + 1';
|
|
}
|
|
));
|
|
}
|
|
$this->internalActivate721Nft($tokenId, Nft::HERO_TYPE, $heroDb['hero_uniid'], $heroDb['hero_id']);
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$gunDb = Gun::find($uniid);
|
|
if (!$gunDb) {
|
|
myself()->_rspErr(1, 'gun not found');
|
|
return;
|
|
}
|
|
if ($gunDb['token_id']) {
|
|
myself()->_rspErr(1, 'already activated');
|
|
return;
|
|
}
|
|
$tokenId = $gunDb['active_token_id'];
|
|
if (!$tokenId) {
|
|
$tokenId = BuyRecord::genOrderId
|
|
(
|
|
2006,
|
|
phpcommon\BC_FUNC_CREATION,
|
|
myself()->_getNowTime(),
|
|
myself()->_getOpenId()
|
|
);
|
|
Gun::Update($gunDb['gun_uniid'],
|
|
array(
|
|
'active_token_id' => $tokenId,
|
|
'active_count' => function () {
|
|
return 'active_count + 1';
|
|
}
|
|
));
|
|
}
|
|
$this->internalActivate721Nft($tokenId, Nft::EQUIP_TYPE, $gunDb['gun_uniid'], $gunDb['gun_id']);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
myself()->_rspErr(1, 'type param error');
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function reportResult()
|
|
{
|
|
$transId = getReqVal('trans_id', '');
|
|
$result = getReqVal('result', '');
|
|
error_log($result);
|
|
Transaction::reportResult($transId, $result);
|
|
myself()->_rspOk();
|
|
}
|
|
|
|
public function evolve721Nft()
|
|
{
|
|
error_log(json_encode($_REQUEST));
|
|
$type = getReqVal('type', '');
|
|
$tokenId1 = getReqVal('token_id1', '');
|
|
$tokenId2 = getReqVal('token_id2', '');
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
$nft1 = Hero::findByTokenId($tokenId1);
|
|
$nft2 = Hero::findByTokenId($tokenId2);
|
|
if (!$nft1 || !$nft2) {
|
|
myself()->_rspErr(1, 'token paramater error');
|
|
return;
|
|
}
|
|
//CEG扣除
|
|
{
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => \services\FormulaService::Hero_Advanced_CEG_Expend($nft1['quality']+1)
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Hero_Advanced_CEC_Expend($nft1['quality']+1)
|
|
)
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$decFeeCb = function ($transId) use ($costItems){
|
|
myself()->_decItems($costItems);
|
|
foreach ($costItems as $costItem){
|
|
TransactionPrefee::add($transId,$costItem);
|
|
}
|
|
};
|
|
}
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'evolve721Nft',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'type' => $type,
|
|
'token_id1' => $tokenId1,
|
|
'token_id2' => $tokenId2
|
|
),
|
|
array(
|
|
'action' => Transaction::EVOLVE_721_ACTION_TYPE,
|
|
'tokenId' => $nft1['token_id'],
|
|
'tokenType' => Nft::HERO_TYPE,
|
|
'itemUniId' => $nft1['hero_uniid'],
|
|
'itemId' => $nft1['hero_id']
|
|
),
|
|
$decFeeCb
|
|
);
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$nft1 = Gun::findByTokenId($tokenId1);
|
|
$nft2 = Gun::findByTokenId($tokenId2);
|
|
if (!$nft1 || !$nft2) {
|
|
myself()->_rspErr(1, 'token paramater error');
|
|
return;
|
|
}
|
|
//CEG扣除
|
|
{
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => \services\FormulaService::Weapon_Advanced_CEG_Expend($nft1['quality']+1)
|
|
),
|
|
array(
|
|
'item_id' => V_ITEM_DIAMOND,
|
|
'item_num' => \services\FormulaService::Weapon_Advanced_CEC_Expend($nft1['quality']+1)
|
|
)
|
|
);
|
|
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$decFeeCb = function ($transId) use ($costItems){
|
|
myself()->_decItems($costItems);
|
|
foreach ($costItems as $costItem){
|
|
TransactionPrefee::add($transId,$costItem);
|
|
}
|
|
};
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'evolve721Nft',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'type' => $type,
|
|
'token_id1' => $tokenId1,
|
|
'token_id2' => $tokenId2
|
|
),
|
|
array(
|
|
'action' => Transaction::EVOLVE_721_ACTION_TYPE,
|
|
'tokenId' => $nft1['token_id'],
|
|
'tokenType' => Nft::EQUIP_TYPE,
|
|
'itemUniId' => $nft1['gun_uniid'],
|
|
'itemId' => $nft1['gun_id']
|
|
),
|
|
$decFeeCb
|
|
);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
myself()->_rspErr(1, 'type param error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function evolveChip()
|
|
{
|
|
$tokenId1 = getReqVal('token_id1', '');
|
|
$tokenIds = explode('|', getReqVal('token_ids', ''));
|
|
|
|
if (in_array($tokenId1, $tokenIds) || count($tokenIds) <= 0) {
|
|
myself()->_rspErr(1, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
|
|
$nftDb = Chip::findByTokenId($tokenId1);
|
|
if (!$nftDb) {
|
|
myself()->_rspErr(1, 'token_id1 paramater error');
|
|
return;
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'evolveChip',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId1,
|
|
'token_ids' => implode('|', $tokenIds)
|
|
),
|
|
array(
|
|
'action' => Transaction::EVOLVE_CHIP_ACTION_TYPE,
|
|
'tokenId' => $tokenId1,
|
|
'tokenType' => 0,
|
|
'itemUniId' => $nftDb['chip_uniid'],
|
|
'itemId' => $nftDb['item_id']
|
|
)
|
|
);
|
|
}
|
|
|
|
public function mintShardBatchUser()
|
|
{
|
|
$itemUniId = getReqVal('item_uniid', 0);
|
|
$num = getReqVal('num', 0);
|
|
$itemDb = Bag::findByUniId($itemUniId);
|
|
if ($num <= 0) {
|
|
myself()->_rspErr(1, 'num paramater error');
|
|
return;
|
|
}
|
|
error_log(json_encode(
|
|
$_REQUEST
|
|
));
|
|
if (!$itemDb || $itemDb['item_num'] < $num) {
|
|
myself()->_rspErr(1, 'item not enough');
|
|
return;
|
|
}
|
|
$itemMeta = mt\Item::get($itemDb['item_id']);
|
|
switch ($itemMeta['type']) {
|
|
case mt\Item::FRAGMENT_BOX_TYPE:
|
|
{
|
|
$this->internalOpenFragmentBox($itemDb, $itemMeta, $num);
|
|
}
|
|
break;
|
|
case mt\Item::CHIP_BOX_TYPE:
|
|
{
|
|
$this->internalOpenChipBox($itemDb, $itemMeta, $num);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
myself()->_rspErr(1, 'item type error');
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function shardMixByUser()
|
|
{
|
|
$tokenIds = explode('|', getReqVal('token_ids', ''));
|
|
$itemId = getReqVal('item_id', '');
|
|
|
|
$tokenId = '';
|
|
$tokenType = '';
|
|
|
|
{
|
|
$heros = array();
|
|
$guns = array();
|
|
$specHeros = array();
|
|
$specGuns = array();
|
|
mt\Item::groupFragment($tokenIds, $heros, $guns, $specHeros, $specGuns);
|
|
error_log(json_encode(array(
|
|
$tokenIds,
|
|
$heros,
|
|
$guns,
|
|
$specHeros,
|
|
$specGuns,
|
|
json_encode($_REQUEST)
|
|
)));
|
|
if (count($tokenIds) != (
|
|
count($heros) + count($guns) + count($specHeros) + count($specGuns)
|
|
)) {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
if (count($specHeros) + count($specGuns) > 1) {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
if (count($heros) > 0 && count($guns) > 0) {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
if (count($heros) > 0) {
|
|
if (count($heros) != 8 || count($specGuns) > 0) {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
$tokenType = Nft::HERO_TYPE;
|
|
} else if (count($guns) > 0) {
|
|
if (count($guns) != 8 || count($specHeros) > 0) {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
$tokenType = Nft::EQUIP_TYPE;
|
|
} else {
|
|
myself()->_rspErr(101, 'token_ids paramater error');
|
|
return;
|
|
}
|
|
}
|
|
|
|
$tokenId = BuyRecord::genOrderId
|
|
(
|
|
2006,
|
|
phpcommon\BC_FUNC_CREATION,
|
|
myself()->_getNowTime(),
|
|
myself()->_getOpenId()
|
|
);
|
|
//CEG扣除
|
|
{
|
|
if ($tokenType == Nft::HERO_TYPE){
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => 100
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$decFeeCb = function ($transId) use ($costItems){
|
|
myself()->_decItems($costItems);
|
|
foreach ($costItems as $costItem){
|
|
TransactionPrefee::add($transId,$costItem);
|
|
}
|
|
};
|
|
// $this->_decItems($costItems);
|
|
}
|
|
if ($tokenType == Nft::EQUIP_TYPE){
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => 30
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$decFeeCb = function ($transId) use ($costItems){
|
|
myself()->_decItems($costItems);
|
|
foreach ($costItems as $costItem){
|
|
TransactionPrefee::add($transId,$costItem);
|
|
}
|
|
};
|
|
// $this->_decItems($costItems);
|
|
}
|
|
}
|
|
|
|
$params = array(
|
|
'c' => 'BcService',
|
|
'a' => 'shardMixByUser',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => $tokenType,
|
|
'item_id' => $itemId,
|
|
'token_ids' => implode('|', $tokenIds)
|
|
);
|
|
{
|
|
error_log(3333333);
|
|
$url = self::getWeb3ServiceUrl();
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
error_log(444444);
|
|
myself()->_rspErr(500, 'server internal error');
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$rspObj = json_decode($response, true);
|
|
if ($rspObj['errcode'] == 0) {
|
|
$transId = $rspObj['trans_id'];
|
|
Transaction::add(
|
|
$transId,
|
|
Transaction::SHARD_MIX_BY_USER_ACTION_TYPE,
|
|
$tokenId,
|
|
$tokenType,
|
|
0,
|
|
$itemId
|
|
);
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$decFeeCb($transId);
|
|
myself()->_rspData(array(
|
|
'trans_id' => $transId,
|
|
'params' => $rspObj['params'],
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
error_log(5555555555);
|
|
} else {
|
|
error_log(22222222222222);
|
|
myself()->_rspErr(500, 'server internal error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function pluginChipBatch()
|
|
{
|
|
$type = getReqVal('type', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$chipIds = explode('|', getReqVal('chip_ids', ''));
|
|
$slotIds = explode('|', getReqVal('slot_ids', ''));
|
|
|
|
error_log(json_encode($_REQUEST));
|
|
if (count($chipIds) != count($slotIds) ||
|
|
count($chipIds) < 0) {
|
|
myself()->_rspErr(101, 'chip_ids paramater error');
|
|
return;
|
|
}
|
|
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
$heroDb = Hero::findByTokenId($tokenId);
|
|
foreach ($chipIds as $chipId) {
|
|
$chipDb = Chip::findByTokenId($chipId);
|
|
if (!$chipDb) {
|
|
myself()->_rspErr(101, 'chip_ids paramater error');
|
|
return;
|
|
}
|
|
}
|
|
if (!$heroDb) {
|
|
myself()->_rspErr(101, 'token_id paramater error');
|
|
return;
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'pluginChip',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => Nft::HERO_TYPE,
|
|
'chip_ids' => implode('|', $chipIds),
|
|
'slot_ids' => implode('|', $slotIds),
|
|
),
|
|
array(
|
|
'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE,
|
|
'tokenId' => $tokenId,
|
|
'tokenType' => Nft::HERO_TYPE,
|
|
'itemUniId' => $heroDb['hero_uniid'],
|
|
'itemId' => $heroDb['hero_id']
|
|
)
|
|
);
|
|
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$gunDb = Gun::findByTokenId($tokenId);
|
|
foreach ($chipIds as $chipId) {
|
|
$chipDb = Chip::findByTokenId($chipId);
|
|
if (!$chipDb) {
|
|
myself()->_rspErr(101, 'chip_ids paramater error');
|
|
return;
|
|
}
|
|
}
|
|
if (!$gunDb) {
|
|
myself()->_rspErr(101, 'token_id paramater error');
|
|
return;
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'pluginChip',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => Nft::EQUIP_TYPE,
|
|
'chip_ids' => implode('|', $chipIds),
|
|
'slot_ids' => implode('|', $slotIds),
|
|
),
|
|
array(
|
|
'action' => Transaction::PLUGIN_CHIP_ACTION_TYPE,
|
|
'tokenId' => $tokenId,
|
|
'tokenType' => Nft::EQUIP_TYPE,
|
|
'itemUniId' => $gunDb['gun_uniid'],
|
|
'itemId' => $gunDb['gun_id']
|
|
)
|
|
);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function unplugChip()
|
|
{
|
|
$type = getReqVal('type', '');
|
|
$tokenId = getReqVal('token_id', '');
|
|
$chipIds = explode('|', getReqVal('chip_ids', ''));
|
|
$slotIds = explode('|', getReqVal('slot_ids', ''));
|
|
|
|
if (count($chipIds) != count($slotIds) ||
|
|
count($chipIds) < 0) {
|
|
myself()->_rspErr(101, 'chip_ids paramater error');
|
|
return;
|
|
}
|
|
|
|
//CEG扣除
|
|
{
|
|
$costSum = 0;
|
|
foreach ($chipIds as $chipId){
|
|
$chipDb = Chip::getChipByTokenId($chipId);
|
|
if ($chipDb){
|
|
$tiliDiff = $chipDb['strength_max'] - $chipDb['strength'];
|
|
$costSum += \services\FormulaService::Chip_Demount_Mint($tiliDiff);
|
|
}
|
|
}
|
|
$decFeeCb = null;
|
|
if ($costSum > 0){
|
|
$costItems = array(
|
|
array(
|
|
'item_id' => V_ITEM_GOLD,
|
|
'item_num' => $costSum
|
|
),
|
|
);
|
|
$lackItem = null;
|
|
if (!$this->_hasEnoughItems($costItems, $lackItem)) {
|
|
$this->_rspErr(3, $this->_getLackItemErrMsg($lackItem));
|
|
return;
|
|
}
|
|
$decFeeCb = function ($transId) use ($costItems, $chipIds){
|
|
myself()->_decItems($costItems);
|
|
error_log(json_encode($costItems));
|
|
foreach ($costItems as $costItem){
|
|
TransactionPrefee::add($transId,$costItem);
|
|
}
|
|
|
|
foreach ($chipIds as $chipId){
|
|
$chipDb = Chip::getChipByTokenId($chipId);
|
|
$items = array(
|
|
'token_id' => $chipDb['token_id'],
|
|
'token_type' => $chipDb['chip_type'],
|
|
'item_id' => self::TEST_ITEM_ID,
|
|
'item_num' => $chipDb['strength_max'] - $chipDb['strength']
|
|
);
|
|
Chip::update($chipId,array(
|
|
'strength'=>$chipDb['strength_max']
|
|
));
|
|
TransactionPrefee::add($transId,$items);
|
|
}
|
|
};
|
|
}
|
|
}
|
|
|
|
switch ($type) {
|
|
case 1:
|
|
{
|
|
$heroDb = Hero::findByTokenId($tokenId);
|
|
if (!$heroDb) {
|
|
myself()->_rspErr(101, 'token_id paramater error');
|
|
return;
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'unplugChip',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => Nft::HERO_TYPE,
|
|
'chip_ids' => implode('|', $chipIds),
|
|
'slot_ids' => implode('|', $slotIds),
|
|
),
|
|
array(
|
|
'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE,
|
|
'tokenId' => $tokenId,
|
|
'tokenType' => Nft::HERO_TYPE,
|
|
'itemUniId' => $heroDb['hero_uniid'],
|
|
'itemId' => $heroDb['hero_id']
|
|
),
|
|
$decFeeCb
|
|
);
|
|
|
|
}
|
|
break;
|
|
case 2:
|
|
{
|
|
$gunDb = Gun::findByTokenId($tokenId);
|
|
if (!$gunDb) {
|
|
myself()->_rspErr(101, 'token_id paramater error');
|
|
return;
|
|
}
|
|
|
|
$this->internalBcCall(
|
|
array(
|
|
'c' => 'BcService',
|
|
'a' => 'unplugChip',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => Nft::EQUIP_TYPE,
|
|
'chip_ids' => implode('|', $chipIds),
|
|
'slot_ids' => implode('|', $slotIds),
|
|
),
|
|
array(
|
|
'action' => Transaction::UNPLUG_CHIP_ACTION_TYPE,
|
|
'tokenId' => $tokenId,
|
|
'tokenType' => Nft::EQUIP_TYPE,
|
|
'itemUniId' => $gunDb['gun_uniid'],
|
|
'itemId' => $gunDb['gun_id']
|
|
),
|
|
$decFeeCb
|
|
);
|
|
}
|
|
break;
|
|
default:
|
|
{
|
|
myself()->_rspErr(101, 'type paramater error');
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function getJumpInfo(){
|
|
$transId = getReqVal('trans_id', '');
|
|
if (!$transId){
|
|
myself()->_rspErr(101, 'trans_id paramater error');
|
|
return;
|
|
}
|
|
$tranDb= Transaction::find($transId);
|
|
if (!$tranDb){
|
|
myself()->_rspErr(101, 'trans_id paramater error');
|
|
return;
|
|
}
|
|
$data = Transaction::getJumpInfo($tranDb);
|
|
myself()->_rspData($data);
|
|
}
|
|
|
|
public function getTransactionInfo(){
|
|
$transId = getReqVal('trans_id', '');
|
|
if (!$transId){
|
|
myself()->_rspErr(101, 'trans_id paramater error');
|
|
return;
|
|
}
|
|
$tranDb= Transaction::find($transId);
|
|
myself()->_rspData(array(
|
|
'data' => array(
|
|
'trans_id' => $tranDb['trans_id'],
|
|
'item_id' => $tranDb['item_id'],
|
|
'action' => Transaction::getActionDesc($tranDb),
|
|
'status' => Transaction::getStatusDesc($tranDb),
|
|
'time' => $tranDb['createtime'],
|
|
)
|
|
));
|
|
}
|
|
|
|
private function internalActivate721Nft($tokenId, $tokenType, $itemUniId, $itemId)
|
|
{
|
|
$params = array(
|
|
'c' => 'BcService',
|
|
'a' => 'activate721Nft',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'token_type' => $tokenType,
|
|
'item_uniid' => $itemUniId,
|
|
'item_id' => $itemId
|
|
);
|
|
{
|
|
$url = self::getWeb3ServiceUrl();
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$rspObj = json_decode($response, true);
|
|
if ($rspObj['errcode'] == 0) {
|
|
$transId = $rspObj['trans_id'];
|
|
Transaction::add(
|
|
$transId,
|
|
Transaction::MINT_721_ACTION_TYPE,
|
|
$tokenId,
|
|
$tokenType,
|
|
$itemUniId,
|
|
$itemId
|
|
);
|
|
myself()->_rspData(array(
|
|
'trans_id' => $transId,
|
|
'params' => $rspObj['params']
|
|
));
|
|
} else {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function internalOpenChipBox($itemDb, $itemMeta, $num) {
|
|
$tokenId = BuyRecord::genOrderId
|
|
(
|
|
2006,
|
|
phpcommon\BC_FUNC_CREATION,
|
|
myself()->_getNowTime(),
|
|
myself()->_getOpenId()
|
|
);
|
|
$params = array(
|
|
'c' => 'BcService',
|
|
'a' => 'activate1155Nft',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'item_uniid' => $itemDb['item_uniid'],
|
|
'item_id' => $itemDb['item_id'],
|
|
'num' => $num,
|
|
);
|
|
{
|
|
$url = self::getWeb3ServiceUrl();
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$tokenType = Nft::CHIP_TYPE;
|
|
$rspObj = json_decode($response, true);
|
|
if ($rspObj['errcode'] == 0) {
|
|
$transId = $rspObj['trans_id'];
|
|
Transaction::add(
|
|
$transId,
|
|
Transaction::MINT_1155_ACTION_TYPE,
|
|
$tokenId,
|
|
Nft::CHIP_TYPE,
|
|
$itemDb['item_uniid'],
|
|
$itemDb['item_id']
|
|
);
|
|
myself()->_rspData(array(
|
|
'trans_id' => $transId,
|
|
'params' => $rspObj['params']
|
|
));
|
|
} else {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function internalOpenFragmentBox($itemDb, $itemMeta, $num) {
|
|
$tokenId = $itemMeta['include_item_id'];
|
|
$itemId = $itemMeta['include_item_id'];
|
|
$params = array(
|
|
'c' => 'BcService',
|
|
'a' => 'mintShardBatchUser',
|
|
'account_id' => myself()->_getAccountId(),
|
|
'session_id' => myself()->_getSessionId(),
|
|
'account' => myself()->_getOpenId(),
|
|
'token_id' => $tokenId,
|
|
'item_uniid' => $itemDb['item_uniid'],
|
|
'item_id' => $itemId,
|
|
'num' => $num
|
|
);
|
|
{
|
|
$url = self::getWeb3ServiceUrl();
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$tokenType = Nft::FRAGMENT_TYPE;
|
|
$rspObj = json_decode($response, true);
|
|
if ($rspObj['errcode'] == 0) {
|
|
$transId = $rspObj['trans_id'];
|
|
Transaction::add(
|
|
$transId,
|
|
Transaction::MINT_SHARD_BATCH_ACTION_TYPE,
|
|
$tokenId,
|
|
$tokenType,
|
|
$itemDb['item_uniid'],
|
|
$itemId
|
|
);
|
|
myself()->_rspData(array(
|
|
'trans_id' => $transId,
|
|
'params' => $rspObj['params']
|
|
));
|
|
} else {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
private function internalBcCall($params, $transParams, $cb = null) {
|
|
$propertyChgService = new services\PropertyChgService();
|
|
$propertyChgService->addUserChg();
|
|
$url = self::getWeb3ServiceUrl();
|
|
$response = '';
|
|
if (!phpcommon\HttpClient::get
|
|
($url,
|
|
$params,
|
|
$response)) {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
error_log($response);
|
|
$rspObj = json_decode($response, true);
|
|
if ($rspObj['errcode'] == 0) {
|
|
$transId = $rspObj['trans_id'];
|
|
Transaction::add(
|
|
$transId,
|
|
$transParams['action'],
|
|
$transParams['tokenId'],
|
|
$transParams['tokenType'],
|
|
$transParams['itemUniId'],
|
|
$transParams['itemId']
|
|
);
|
|
if ($cb) {
|
|
$cb($transId);
|
|
}
|
|
myself()->_rspData(array(
|
|
'trans_id' => $transId,
|
|
'params' => $rspObj['params'],
|
|
'property_chg' => $propertyChgService->toDto(),
|
|
));
|
|
} else {
|
|
myself()->_rspErr(500, 'server internal error');
|
|
die();
|
|
return;
|
|
}
|
|
}
|
|
|
|
private static function getWeb3ServiceUrl()
|
|
{
|
|
if (SERVER_ENV == _TEST) {
|
|
return 'http://127.0.0.1:7672/webapp/index.php';
|
|
}
|
|
$web3ServiceCluster = require_once('../config/web3service.cluster.php');
|
|
return $web3ServiceCluster[rand() % count($web3ServiceCluster)];
|
|
}
|
|
|
|
}
|