144 lines
4.7 KiB
PHP
144 lines
4.7 KiB
PHP
<?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');
|
|
|
|
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()
|
|
{
|
|
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
|
|
)
|
|
);
|
|
|
|
$conn = myself()->_getMysql('');
|
|
|
|
// 1. check order status
|
|
$chk = SqlHelper::selectOne($conn, 't_market_store', array('status'), array('o_link' => $orderId));
|
|
if (!empty($chk)) {
|
|
$this->_rspErr(1, 'repeat sell order, orderId=' . $orderId);
|
|
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' => $orderId,
|
|
'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);
|
|
}
|
|
$lastId = $this->lastInsertId($conn);
|
|
$order_id = $this->genOrderId($lastId);
|
|
$test = SqlHelper::update($conn, 't_market_store', array('idx' => $lastId), array('order_id' => $order_id));
|
|
$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;
|
|
}
|
|
}
|