...
This commit is contained in:
parent
6b4c8147cf
commit
d68d106699
@ -473,14 +473,12 @@ class MarketController extends BaseAuthedController
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
$account = $address;
|
||||
|
||||
$token = getReqVal('token', '');
|
||||
|
||||
$nft_token = getReqVal('nft_token', '');
|
||||
// $nft_token = getReqVal('nft_token', '');
|
||||
|
||||
$item_id = getReqVal('item_id', '');
|
||||
if (empty($item_id)) {
|
||||
$itemMeta = mt\Item::get($item_id);
|
||||
if (!$itemMeta) {
|
||||
$this->_rspErr(1, 'item_id not found');
|
||||
return;
|
||||
}
|
||||
@ -490,11 +488,20 @@ class MarketController extends BaseAuthedController
|
||||
$this->_rspErr(1, 's_price not found');
|
||||
return;
|
||||
}
|
||||
if ($s_price<=0) {
|
||||
$this->_rspErr(1, 's_price must > 0');
|
||||
return;
|
||||
}
|
||||
|
||||
$amount = getReqVal('amount', 1);
|
||||
if (empty($amount)) {
|
||||
$this->_rspErr(1, 'amount not found');
|
||||
return;
|
||||
}
|
||||
if ($amount<=0) {
|
||||
$this->_rspErr(1, 'amount must > 0');
|
||||
return;
|
||||
}
|
||||
|
||||
$conn = myself()->_getSelfMysql();
|
||||
|
||||
@ -517,7 +524,6 @@ class MarketController extends BaseAuthedController
|
||||
}
|
||||
$this->_decItems($costItems);
|
||||
|
||||
$itemMeta = mt\Item::get($item_id);
|
||||
$c_name = $itemMeta['name'];
|
||||
$c_job = 0;
|
||||
$c_lv = 0;
|
||||
@ -530,9 +536,9 @@ class MarketController extends BaseAuthedController
|
||||
$conn,
|
||||
't_market_store',
|
||||
array(
|
||||
'token_id' => $nft_token,
|
||||
'token_id' => '',
|
||||
'item_id' => $item_id,
|
||||
'owner_address' => $account,
|
||||
'owner_address' => $address,
|
||||
'token_type' => 0,
|
||||
'amount' => $amount,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
@ -584,12 +590,11 @@ class MarketController extends BaseAuthedController
|
||||
|
||||
public function sellCancel()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$idx = getReqVal('idx', '');
|
||||
|
||||
$address = $this->_getAddress();
|
||||
if ($address != $account) {
|
||||
$this->_rspErr(1, 'not your goods, idx:' . $idx);
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -599,16 +604,11 @@ class MarketController extends BaseAuthedController
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goods['owner_address'] != $account) {
|
||||
if ($goods['owner_address'] != $address) {
|
||||
$this->_rspErr(1, 'not your goods, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->addItems($address, $goods['item_id'], $goods['amount'])) {
|
||||
$this->_rspErr(1, "cancel failed, add item failed, idx:" . $idx);
|
||||
return;
|
||||
}
|
||||
|
||||
$conn = $this->_getSelfMysql();
|
||||
$r = SqlHelper::update(
|
||||
$conn,
|
||||
@ -621,18 +621,36 @@ class MarketController extends BaseAuthedController
|
||||
'modifytime' => $this->_getNowTime(),
|
||||
)
|
||||
);
|
||||
$this->_rspOk();
|
||||
if ($r) {
|
||||
$items = array(
|
||||
array(
|
||||
'item_id' => $goods['item_id'],
|
||||
'item_num' => $goods['amount'],
|
||||
)
|
||||
);
|
||||
$awardService = new services\AwardService();
|
||||
$propertyChgService = new services\PropertyChgService();
|
||||
$this->_addItems($items, $awardService, $propertyChgService);
|
||||
|
||||
$this->_rspData(
|
||||
array(
|
||||
'idx' => $idx,
|
||||
'property_chg' => $propertyChgService->toDto(),
|
||||
)
|
||||
);
|
||||
} else {
|
||||
$this->_rspErr(1, 'cancel failed');
|
||||
}
|
||||
}
|
||||
|
||||
public function sellUpdatePrice()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$idx = getReqVal('idx', '');
|
||||
$s_price = getReqVal('s_price', '');
|
||||
|
||||
$address = $this->_getAddress();
|
||||
if ($address != $account) {
|
||||
$this->_rspErr(1, 'not your goods, idx:' . $idx);
|
||||
if (!$address) {
|
||||
$this->_rspErr(1, 'address not found');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -642,7 +660,7 @@ class MarketController extends BaseAuthedController
|
||||
return;
|
||||
}
|
||||
|
||||
if ($goods['owner_address'] != $account) {
|
||||
if ($goods['owner_address'] != $address) {
|
||||
$this->_rspErr(1, 'not your goods, idx:' . $idx);
|
||||
return;
|
||||
}
|
||||
@ -659,6 +677,11 @@ class MarketController extends BaseAuthedController
|
||||
'modifytime' => $this->_getNowTime(),
|
||||
)
|
||||
);
|
||||
if (!$r) {
|
||||
$this->_rspErr(1, 'update price failed');
|
||||
return;
|
||||
}
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
@ -710,72 +733,13 @@ class MarketController extends BaseAuthedController
|
||||
'block_chain' => $response,
|
||||
));
|
||||
}
|
||||
private function Web3PriceLowFormat($price) {
|
||||
private function Web3PriceLowFormat($price)
|
||||
{
|
||||
$bn2 = phpcommon\bnInit('1000000000000000000');
|
||||
$ret_price = phpcommon\bnDiv($price, $bn2);
|
||||
return phpcommon\bnToStr($ret_price);
|
||||
}
|
||||
|
||||
private function sellMyNft()
|
||||
{
|
||||
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$token = getReqVal('token', '');
|
||||
$nft_token = getReqVal('nft_token', '');
|
||||
$s_price = getReqVal('s_price', '');
|
||||
$amount = getReqVal('amount', 1);
|
||||
$payment_token_address = getReqVal('payment_token_address', '');
|
||||
$nonce = getReqVal('nonce', '');
|
||||
$signature = getReqVal('signature', '');
|
||||
$net_id = getReqVal('net_id', '');
|
||||
|
||||
$conn = myself()->_getSelfMysql();
|
||||
|
||||
$nftDb = Nft::findNftByOwner($account, $nft_token);
|
||||
$nftDetail = Nft::toDto($nftDb);
|
||||
$detail = $this->getNftGameData($nftDb);
|
||||
$r = SqlHelper::insert(
|
||||
$conn,
|
||||
't_market_store',
|
||||
array(
|
||||
'token_id' => $nft_token,
|
||||
'owner_address' => $nftDetail['owner_address'],
|
||||
'token_type' => $nftDetail['type'],
|
||||
'amount' => $amount,
|
||||
'createtime' => myself()->_getNowTime(),
|
||||
'modifytime' => myself()->_getNowTime(),
|
||||
's_price' => $s_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'],
|
||||
)
|
||||
);
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
private function buyNft()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$token = getReqVal('token', '');
|
||||
$nft_token = getReqVal('nft_token', '');
|
||||
$payment_token_address = getReqVal('payment_token_address', '');
|
||||
$nonce = getReqVal('nonce', '');
|
||||
$signature = getReqVal('signature', '');
|
||||
$net_id = getReqVal('net_id', '');
|
||||
|
||||
$conn = myself()->_getSelfMysql();
|
||||
$conn->execScript('DELETE FROM t_market_store WHERE ' . 'token_id=\'' . $nft_token . '\'');
|
||||
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function getSupportedCurrencyTypes()
|
||||
{
|
||||
$types = array();
|
||||
@ -795,7 +759,7 @@ class MarketController extends BaseAuthedController
|
||||
));
|
||||
}
|
||||
|
||||
public function getTransactionRecord()
|
||||
private function getTransactionRecord()
|
||||
{
|
||||
$account = strtolower(getReqVal('account', ''));
|
||||
$type = getReqVal('type', 0);
|
||||
@ -937,172 +901,6 @@ class MarketController extends BaseAuthedController
|
||||
return $rows;
|
||||
}
|
||||
|
||||
private function addItems($address, $item_id, $amount)
|
||||
{
|
||||
$r = $this->addItem($address, $item_id, $amount);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function decItems($address, $item_id, $amount)
|
||||
{
|
||||
$userInfo = $this->getUserInfo($address, array('gold'));
|
||||
$count = $this->getItemCount($item_id, $userInfo);
|
||||
if ($count < $amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = $this->decItem($address, $item_id, $amount);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function addItem($address, $item_id, $amount)
|
||||
{
|
||||
switch ($item_id) {
|
||||
case V_ITEM_GOLD: {
|
||||
$r = $this->addGold($address, $amount);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function decItem($address, $item_id, $amount)
|
||||
{
|
||||
switch ($item_id) {
|
||||
case V_ITEM_GOLD: {
|
||||
$r = $this->decGold($address, $amount);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private function addGold($address, $amount)
|
||||
{
|
||||
$r = $this->updateUserInfo($address, array(
|
||||
'gold' => function () use ($amount) {
|
||||
return "gold + ${amount}";
|
||||
}
|
||||
));
|
||||
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function decGold($address, $amount)
|
||||
{
|
||||
$userInfo = $this->getUserInfo($address, array('gold'));
|
||||
$count = $this->getItemCount(V_ITEM_GOLD, $userInfo);
|
||||
if ($count < $amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$r = $this->updateUserInfo($address, array(
|
||||
'gold' => function () use ($amount) {
|
||||
return "GREATEST(0, gold - ${amount})";
|
||||
},
|
||||
'consume_gold' => function () use ($amount) {
|
||||
return "consume_gold + ${amount}";
|
||||
}
|
||||
));
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function updateUserInfo($address, $fieldKv)
|
||||
{
|
||||
$r = SqlHelper::update(
|
||||
myself()->_getSelfMysql(),
|
||||
't_user',
|
||||
array(
|
||||
'address' => $address,
|
||||
),
|
||||
$fieldKv
|
||||
);
|
||||
if (!$r) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
private function getCostItem($address, $item_id)
|
||||
{
|
||||
$userInfo = $this->getUserInfo($address, array('gold'));
|
||||
$count = $this->getItemCount($item_id, $userInfo);
|
||||
|
||||
return array(
|
||||
'item_id' => $item_id,
|
||||
'item_amount' => $count
|
||||
);
|
||||
}
|
||||
|
||||
private function getItemCount($item_id, $userInfo)
|
||||
{
|
||||
switch ($item_id) {
|
||||
case V_ITEM_GOLD: {
|
||||
return $userInfo['gold'];
|
||||
}
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
private function getUserInfo($address, $fields)
|
||||
{
|
||||
// $account_id = $this->getAccountId($address);
|
||||
// if (!$account_id) {
|
||||
// return null;
|
||||
// }
|
||||
|
||||
$conn = myself()->_getMysql($address);
|
||||
$row = SqlHelper::selectOne(
|
||||
$conn,
|
||||
't_user',
|
||||
$fields,
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
if (empty($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
private function getAccountId($address)
|
||||
{
|
||||
$row = SqlHelper::selectOne(
|
||||
myself()->_getMysql($address),
|
||||
't_user',
|
||||
array('account_id'),
|
||||
array(
|
||||
'address' => $address
|
||||
)
|
||||
);
|
||||
|
||||
return $row['account_id'];
|
||||
}
|
||||
|
||||
private function normalizeWeb3Price($price)
|
||||
{
|
||||
$bn1 = phpcommon\bnInit($price * pow(10, 8));
|
||||
@ -1152,5 +950,4 @@ class MarketController extends BaseAuthedController
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user