game2006api/webapp/services/callback/MarketSellOrderOk.php
songliang 70c47b0f98 ...
2023-07-14 21:44:14 +08:00

146 lines
4.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace services;
require_once('MarketCallbackBase.php');
require_once('models/Nft.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/Chip.php');
require_once('models/Fragment.php');
require_once ('services/callback/common/SignatureService.php');
use services\MarketCallbackBase;
use phpcommon\SqlHelper;
use models\Nft;
use models\Hero;
use models\Gun;
use models\Chip;
use models\Fragment;
class MarketSellOrderOk extends MarketCallbackBase
{
public function process()
{
SignatureService::web3ServiceCheck();
error_log('MarketSellOrderOk:' . json_encode($_REQUEST, JSON_PRETTY_PRINT));
$tokenId = getReqVal('tokenId', '');
$owner = strtolower(getReqVal('owner', ''));
$nftToken = getReqVal('nftToken', '');
$amount = getReqVal('amount', 0);
$orderId = getReqVal('orderId', '');
$currency = getReqVal('currency', '');
$price = getReqVal('price', '');
error_log(
"eventSellOrder:" . json_encode(
array(
'tokenId' => $tokenId,
'owner' => $owner,
'nftToken' => $nftToken,
'amount' => $amount,
'orderId' => $orderId,
'currency' => $currency,
'price' => $price,
),
JSON_PRETTY_PRINT
)
);
$o_link = $orderId;
$conn = myself()->_getMysql('');
// 1. check order status and repeat order
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $o_link));
if (!empty($chk)) {
$this->_rspErr(1, 'repeat sell order, o_link=' . $o_link);
return;
}
// 2. insert sell order to t_market_store
$nftDb = Nft::findNftByOwner($owner, $tokenId);
if (empty($nftDb)) {
$nftDb = Nft::getNft($tokenId);
}
$nftDetail = Nft::toDto($nftDb);
$detail = $this->getNftGameData($nftDb);
$r = SqlHelper::insert(
$conn,
't_market_store',
array(
'token_id' => $tokenId,
'o_link' => $o_link,
'nft_token' => $nftToken,
'status' => 0,
'owner_address' => $owner,
'token_type' => $nftDetail['type'],
'amount' => $amount,
'createtime' => myself()->_getNowTime(),
'modifytime' => myself()->_getNowTime(),
's_currency' => $currency,
's_price' => $price,
'c_name' => $nftDetail['info']['name'],
'c_job' => isset($nftDetail['info']['job']) ? $nftDetail['info']['job']
: (isset($detail['chip_type']) ? $detail['chip_type']
: (isset($detail['type']) ? $detail['type']
: 0)),
'c_lv' => @$detail['gun_lv'] | @$detail['hero_lv'] | @$detail['chip_grade'],
'c_quality' => isset($nftDetail['info']['quality']) ? $nftDetail['info']['quality'] : 0,
'c_durability' => isset($nftDetail['info']['durability']) ? $nftDetail['info']['durability'] : (isset($detail['hero_tili']) ? $detail['hero_tili'] : 0),
'c_type' => isset($detail['type']) ? $detail['type'] : 0,
'c_id' => $nftDetail['item_id'],
)
);
if (!$r) {
$this->_rspErr(2, 'unknown error, orderId=' . $orderId);
}
// 成功上架更新nft状态
$this->_rspOk();
}
private function getNftGameData($nftRowInfo)
{
$t = $nftRowInfo['token_type'];
$token_id = $nftRowInfo['token_id'];
switch ($t) {
case Nft::HERO_TYPE: {
return $this->appendChipsInfo(Hero::toDtoInfo(Hero::findByTokenId2($token_id)));
}
break;
case Nft::EQUIP_TYPE: {
return $this->appendChipsInfo(Gun::toDtoInfo(Gun::findByTokenId2($token_id)));
}
break;
case Nft::CHIP_TYPE: {
return Chip::toDto(Chip::getChipByTokenId($token_id));
}
break;
case Nft::FRAGMENT_TYPE: {
return Fragment::ToDto($nftRowInfo);
}
break;
default: {
}
break;
}
return array('unknown' => 'unknown game data type, cannot find data');
}
private function appendChipsInfo($detail)
{
$detail['chips_info'] = array();
if (!empty($detail['chip_ids'])) {
$chips = explode('|', $detail['chip_ids']);
foreach ($chips as $chip) {
$chip_info = "";
if (!empty($chip)) {
$chip_info = Chip::toDto(Chip::getChipByTokenId($chip));
}
array_push($detail['chips_info'], $chip_info);
}
}
return $detail;
}
}